Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
🔐JWT Authentication With Refresh Token
Details
The JWT in the boilerplate was updated to work in the following way:
access token
, which you'll use to access protected resources.The
access token
is short lived (default 30 minutes) to reduce the damage of a potential leak. Therefresh token
, on the other hand, is long lived (default 7 days), and you use it to renew youraccess token
without the need to provide username and password every time it expires.Since the
refresh token
lasts for a longer time, it's stored as a cookie in a secure way:You may change it to suit your needs. The possible options for
samesite
are:Lax
: Cookies will be sent in top-level navigations (like clicking on a link to go to another site), but not in API requests or images loaded from other sites.Strict
: Cookies will be sent in top-level navigations (like clicking on a link to go to another site), but not in API requests or images loaded from other sites.None
: Cookies will be sent with both same-site and cross-site requests.🚀Usage
What you should do with the client is:
Login
: Send credentials to/api/v1/login
. Store the returned access token in memory for subsequent requests.Accessing Protected Routes
: Include the access token in the Authorization header.Token Renewal
: On access token expiry, the front end should automatically call/api/v1/refresh
for a new token.Login Again
: If refresh token is expired, credentials should be sent to/api/v1/login
again, storing the new access token in memory.Logout
: Call /api/v1/logout to end the session securely.This authentication setup in the provides a robust, secure, and user-friendly way to handle user sessions in your API applications.