Bird
0
0

What will this NestJS service method return when called with a valid refresh token?

medium📝 Predict Output Q5 of 15
NestJS - Authentication
What will this NestJS service method return when called with a valid refresh token?
async refreshToken(token: string) {
  const payload = this.jwtService.verify(token, { secret: process.env.REFRESH_TOKEN_SECRET });
  return this.jwtService.sign({ userId: payload.userId });
}
AA new refresh token signed with the refresh token secret
BThe original refresh token unchanged
CAn error indicating invalid token
DA new access token signed with the default secret
Step-by-Step Solution
Solution:
  1. Step 1: Verify refresh token

    The method verifies the token using the refresh token secret.
  2. Step 2: Sign new token

    It signs a new token with payload userId but does not specify a secret, so default is used (usually access token secret).
  3. Final Answer:

    A new access token signed with the default secret -> Option D
  4. Quick Check:

    Verify refresh token, then issue new access token [OK]
Quick Trick: Refresh token verified, new access token issued [OK]
Common Mistakes:
  • Assuming it returns the original refresh token
  • Expecting a new refresh token to be returned
  • Thinking it throws error on valid token

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More NestJS Quizzes