nuxt-auth icon indicating copy to clipboard operation
nuxt-auth copied to clipboard

Parse token maxAge from JWT Token

Open AndreasMietk opened this issue 7 months ago • 1 comments

Describe the feature

Hi, im using the local provider with a FastAPI backend where i generate my JWT tokens where i also set the expiration value.

def generate_jwt_token(user: User) -> str:
    return jwt.encode({
        "exp": datetime.datetime.utcnow() + datetime.timedelta(minutes=int(JWT_EXP_MINUTES))
        JWT_USER_PROPERTY: user.email
    }, JWT_SECRET, algorithm=JWT_ALGORITHM)

I looked into the codebase and saw that the cookie for the token only accepts the module config value for maxAgeInSeconds here

It would be really nice to be able to parse it from the expiration field of the JWT!

This way i don't need to keep attention to sync this value or use an extra ENV for my backend/frontend deployment

What are your thoughts?

How would you implement this?

I don't have any implementation ideas.

I think one would need to re-set _rawTokenCookie when a new token is set and it can be identified as a JWT

Additional information

  • [x] Would you be willing to help implement this feature?

Provider

  • [ ] AuthJS
  • [x] Local
  • [ ] Refresh
  • [ ] New Provider

AndreasMietk avatar Jul 04 '25 12:07 AndreasMietk

Agreed. It's also common to receive a expires_in field along with an access token, so it would be nice to have the option to use that as well.

pdjohntony avatar Sep 26 '25 19:09 pdjohntony