When a client logs in, issue them a JWT with an expiration (more on this below). On subsequent API requests, send that token in an Authorization
header as a Bearer
token. This token can be stored in localStorage
, which is the most common, so that if the user revisits the site or refreshes the page, they are still logged in. Other client-side storage options like sessionStorage
or a cookie can be used. JWTs can get big though depending on how much information is stored in the payload, which could exceed the maximum cookie size (4K).
When an API call is made with an expired token, return a 401 HTTP status code and redirect users to the login page.