Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add refresh token #78

Merged
merged 20 commits into from
Jan 21, 2024
Merged

Add refresh token #78

merged 20 commits into from
Jan 21, 2024

Conversation

cherylli
Copy link
Collaborator

@cherylli cherylli commented Jan 16, 2024

Description

  1. Refresh token functionality is added.
  • refresh route
  • refresh token in user table
  1. Global guard to protect all the routes
  • can be bypassed by @Public decorator

Refresh token will have 7 day expiry, while access token will expire in 15mins (I think access tokens can probably have a longer expiry)

Please add 2 new environment Variables
AT_SECRET
RT_SECRET

JWT_SECRET can be removed

Issue link

Fixes # (issue)

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

How Has This Been Tested?

Tested locally

Checklist:

  • My code follows the style guidelines of this project
  • I have performed a self-review of my code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing tests pass locally with my changes
  • Any dependent changes have been merged and published in downstream modules

@cherylli cherylli self-assigned this Jan 16, 2024
@cherylli cherylli marked this pull request as draft January 16, 2024 04:09
@cherylli cherylli marked this pull request as ready for review January 18, 2024 13:43
@cherylli
Copy link
Collaborator Author

Refresh token - hashing

@cherylli
Copy link
Collaborator Author

@cherylli cherylli marked this pull request as draft January 18, 2024 22:26
@cherylli cherylli marked this pull request as ready for review January 18, 2024 23:22
Copy link
Contributor

@jenny-alexander jenny-alexander left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. I did various tests like:

  • Access token and refresh token were granted after successful login.
  • Access token was removed from cookies after 15 minutes.
  • Refresh token was successfully granted after access token expires.
  • I tampered with refresh token and when 'refresh' endpoint was invoked, it failed (as expected).
  • Access token and refresh token were removed from cookies after successful logout & refreshToken set to null in database.

src/auth/auth.service.ts Outdated Show resolved Hide resolved
@cherylli
Copy link
Collaborator Author

LGTM. I did various tests like:

  • Access token and refresh token were granted after successful login.
  • Access token was removed from cookies after 15 minutes.
  • Refresh token was successfully granted after access token expires.
  • I tampered with refresh token and when 'refresh' endpoint was invoked, it failed (as expected).
  • Access token and refresh token were removed from cookies after successful logout & refreshToken set to null in database.

https://github.com/chingu-x/chingu-dashboard-be/pull/78/files#r1460185576

@jenny-alexander jenny-alexander removed the request for review from kennytram January 20, 2024 15:47
Copy link
Collaborator

@curtwl curtwl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@cherylli cherylli merged commit b750ab8 into dev Jan 21, 2024
1 check passed
@cherylli cherylli deleted the feature/refresh-token branch January 21, 2024 02:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants