/plushcap/analysis/workos/workos-the-developers-guide-to-auth-sessions

The Developer’s Guide to Auth Sessions

What's this blog post about?

This post discusses the concept of sessions in web development, which help persist user data across HTTP requests in a browser. It explains that sessions are necessary because HTTP is stateless, and without them, users would need to authenticate on every single request to the backend. The core of building out a sessions system involves creating a table in the database to keep track of active sessions, setting a browser cookie containing the session's ID and user's ID, and checking against the sessions table for each subsequent request. The post also covers how to handle session expiration, which can vary depending on the domain. It suggests two ways of handling it: hard deleting the session from the sessions table or keeping every historical session in there with added expiration logic. Furthermore, it explains that authentication status is not the only reason for keeping track of a session; other uses include storing user roles and permissions, localization settings, etc. The post then delves into how to implement sessions using third-party auth providers like WorkOS or AuthKit. It highlights that these providers handle session management via access tokens, which are issued when a user authenticates and have configurable expiration windows. The post also touches upon the importance of security in implementing sessions, discussing common vulnerabilities such as session hijacking and how to prevent them using secure attributes on cookies and tying session information to user information. Lastly, it mentions that WorkOS provides detailed guides for implementing sessions with backend and frontend apps, offering a convenient solution for developers looking to ensure their users have a great experience while staying safe.

Company
WorkOS

Date published
Sept. 27, 2024

Author(s)

Word count
1443

Hacker News points
None found.

Language
English


By Matt Makai. 2021-2024.