0

how to generate new token before it expire? as per the fastapi doc here is the code for generate access token.

def create_access_token(data: dict, expires_delta: timedelta | None = None):
    to_encode = data.copy()
    if expires_delta:
        expire = datetime.utcnow() + expires_delta
    else:
        expire = datetime.utcnow() + timedelta(minutes=5)
    to_encode.update({"exp": expire})
    encoded_jwt = jwt.encode(to_encode, SECRET_KEY, algorithm=ALGORITHM)
    return encoded_jwt

here my token is expiring after 5 minutes and I want to generate another new token just before it expire .

boyenec
  • 1,405
  • 5
  • 29
  • 1
    You usually have a separate refresh token that can be used to regenerate the token _when the client needs a new token because the old one fails_: https://stackoverflow.com/questions/27726066/jwt-refresh-token-flow – MatsLindh Jan 19 '23 at 08:58

0 Answers0