Skip to content

Parse token maxAge from JWT Token #1038

@AndreasMietk

Description

@AndreasMietk

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

  • Would you be willing to help implement this feature?

Provider

  • AuthJS
  • Local
  • Refresh
  • New Provider

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementAn improvement that needs to be addedpendingAn issue waiting for triage

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions