0

I want to change request.session in middleware. But it doesn't change.

@app.middleware("http")
async def renewal_token(request: Request, call_next):
    response = await call_next(request)
    now = datetime.now()
    expire = now + timedelta(minutes=30)
    session_id = request.session["session_id"]
    request.session["token_expiry"] = expire.timestamp()  # My problem
    response.set_cookie(key="Authorization", value=session_id, expires=expire.replace(tzinfo=timezone.utc))
    return response

I cleared request.session but it still doesn't work.

...
request.session.clear()
request.session["token_expiry"] = expire.timestamp()
...
2
  • This might also be related. Commented Jan 12 at 10:25
  • How are you actually configuring your session? What are you using for session storage? What middleware are you using to persist the session? How are you trying to read the values you've stored in the session? Commented Jan 13 at 8:22

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.