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

feat(api): Implement refresh token strategy #235

Open
wants to merge 2 commits into
base: dev
Choose a base branch
from
Open

Conversation

alepefe
Copy link
Collaborator

@alepefe alepefe commented Jan 16, 2025

Remember to add the following code in shared/config/.env and .env.test

REFRESH_TOKEN_SECRET=refresh_token_secret
REFRESH_TOKEN_EXPIRES_IN=30d

This pull request introduces several significant changes to the authentication module, including the addition of refresh token functionality, scheduled token cleanup, and various dependency updates.

Authentication Enhancements:

  • Refresh Token Implementation:

    • Added refreshToken method to AuthenticationController to handle refresh token requests.
    • Introduced refreshAuthTokens method in AuthenticationService to refresh authentication tokens.
    • Implemented refreshAuthTokens and createAuthTokenPair methods in JwtManager for token management. [1] [2]
  • Token Cleanup Service:

    • Added TokenCleanupService to periodically clean up expired refresh tokens using a cron job.
    • Registered TokenCleanupService in AuthenticationModule.

Dependency and Configuration Updates:

  • Dependencies:

    • Added @nestjs/schedule and uuid to api/package.json. [1] [2]
  • Configuration:

    • Updated ApiConfigService to include IssuedRefreshToken entity in the database configuration.
    • Added JWT configuration for refresh tokens in JwtConfigHandler.

Utility and Testing:

  • Utility Functions:

    • Added TimeUtils for parsing duration strings to seconds.
  • Testing:

    • Added integration tests for refresh token functionality in auth/refresh-token.spec.ts.

Copy link

vercel bot commented Jan 16, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
tnc-blue-carbon-cost-tool-ghps ❌ Failed (Inspect) Jan 17, 2025 0:07am

@alepefe
Copy link
Collaborator Author

alepefe commented Jan 16, 2025

Waiting to validate this so the frontend guys can later adapt their code.

@alepefe alepefe requested a review from alexeh January 16, 2025 12:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant