-
Notifications
You must be signed in to change notification settings - Fork 10
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
"null" Session Id when using RedisBackend and InMemoryBackend #7
Comments
The issue seems to arise on this line: starsessions/starsessions/middleware.py Line 46 in 6bd258a
I am using Fastapi, btw. |
can you share a code example for more context? |
Please see below. app = FastAPI()
app.include_router(router) # Simple API router
app.add_middleware(SessionMiddleware, backend=RedisBackend(settings.redis_url), autoload=True) I checked the |
Sorrry not the |
Also attach an example of your view function where you call this code. The session id will be generated by the session middleware if empty. This happens when response is being sent. |
This is the only view where I write to the session. @router.post("/password/request", status_code=status.HTTP_202_ACCEPTED)
async def reset_request(
request: Request,
background_tasks: BackgroundTasks,
email: str = Body(..., embed=True),
):
otp = generate_otp()
otp_expires_at = dt.datetime.now() + dt.timedelta(seconds=settings.otp_valid_for)
request.session[SESSION_KEY_OTP] = otp
request.session[SESSION_KEY_OTP_EXPIRES_AT] = otp_expires_at.timestamp()
background_tasks.add_task(email_otp, email, otp) |
Looks like that is all fine. The session ID will be generated once the response is sent and will be available on the next request. |
When I use CookieBackend I see session key and value. However, in any of the other backends cookie is returned empty. I use Insomnia to test it. |
yes, sure. thanks for report. |
I tested locally and all works fine.
CookieBackend is different. The ID here is encrypted cookie content so it is always available. |
I will check and report back. Thank you! |
After checking on a different machine, RedisBackend works fine. Session ID is set as expected. Now, I have to investigate why it didn't work before. Sorry for bothering ) |
Session ID is shown as null when I use RedisBackend. It is also same for InMemoryBackend. However, Cookie backend works fine.
The text was updated successfully, but these errors were encountered: