Код: Выделить всё
@router.post("/login")
async def login(response: Response, credentials: UserLoginSchema = Form()):
if credentials.email == ADMIN_EMAIL and credentials.password == "123":
token = auth.create_access_token(uid=credentials.email)
response.set_cookie(config.JWT_ACCESS_COOKIE_NAME, token, path="/", samesite="lax", secure=True, httponly=True)
return RedirectResponse(url="/", status_code=status.HTTP_302_FOUND)
raise HTTPException(401, detail={"message": "Invalid credentials"})
Код: Выделить всё
@app.get("/", response_class=HTMLResponse, dependencies=[Depends(auth.access_token_required)])
async def get_index(request: Request):
return templates.TemplateResponse(name="index.html", request=request)
Если я сделаю это без перенаправления, просто вручную перейду к «/» после пения во, получается. Но как только я возвращаю RedirectResponse(url="/", status_code=status.HTTP_302_FOUND), он просто забывает, что я хочу установить cookie, и переходит к "/" без них.
Что не так?
Я использую FastAPI и AuthX.>
Подробнее здесь: https://stackoverflow.com/questions/793 ... ir-cookies