# Staying Signed In

Staying Signed In: Tokens: Signing In with a JWT, Sessions and Cookies, and When They Fit Better.

Updated: November 19, 2026

1. [Tokens: Signing In with a JWT](https://www.ask-codey.com/lessons/fastapi-auth-tokens-jwt) (Journeyman): After a sign-in, an API hands out a JWT, a signed token in three parts that PyJWT makes with jwt.encode and an exp claim and checks with jwt.decode, at POST /auth/token with the OAuth2 password form so the docs page's Authorize button works, and the caller sends it back in an Authorization header with every request.
2. [Sessions and Cookies, and When They Fit Better](https://www.ask-codey.com/lessons/fastapi-auth-sessions-and-cookies) (Journeyman): A session signs a user in with a random id from secrets.token_urlsafe, kept in a sessions table and sent in an HttpOnly, Secure, SameSite cookie, so signing out deletes a row and takes effect at once, which suits one website on one server better than a token that stays valid until it expires.

Source: https://www.ask-codey.com/courses/python-web-apis/topics/fastapi-staying-signed-in
