Code: Select all
@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"})
Code: Select all
@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)
Wenn ich es ohne Weiterleitung mache, gehe ich nach dem Singen einfach manuell zu „/“. rein, es klappt. Aber sobald ich RedirectResponse(url="/", status_code=status.HTTP_302_FOUND) zurückgebe, vergisst es einfach, dass ich ein Cookie setzen möchte und geht ohne sie zu „/“.
Was ist los?
Ich verwende FastAPI und AuthX.