Skip to content
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

Cookie not being sent to frontend #85

Open
apaul45 opened this issue Jun 5, 2022 · 0 comments
Open

Cookie not being sent to frontend #85

apaul45 opened this issue Jun 5, 2022 · 0 comments

Comments

@apaul45
Copy link

apaul45 commented Jun 5, 2022

When testing my register and login functions from my front end application, I found that the CSRF cookie was not appearing. I was able to confirm that my backend api never sent it once trying one of my jwt_required functions.

When I test this with the Swagger UI though, I'm finding that it does send a cookie containing the JWT, but that this resides in the http://127.0.0.1:8000/ url.

I'm not sure why the cookie isn't being sent to the front end, as I passed in a response object to set_access_cookies.

@router.post("/login")
async def login_user(user:LoggedInUser, response: Response, auth: AuthJWT = Depends()):
    existing_user = await users_coll.find_one({"username": user.username})
    print(existing_user)
    if not existing_user:
        raise HTTPException(status_code=400, detail="Incorrect username")
    elif not pwd_context.verify(user.password, existing_user["passwordHash"]):
        raise HTTPException(status_code=400, detail="Incorrect password")
    else:
        #Create, store, and return a JWT in a cookie
        token = auth.create_access_token(subject=user.username)
        auth.set_access_cookies(token, response=response)
        return {"msg": "User successfully logged in"}

Screen Shot 2022-06-05 at 4 03 22 PM

Screen Shot 2022-06-05 at 4 04 18 PM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant