athul / blog

Personal Blog built with Hugo
https://blog.athulcyriac.in
14 stars 4 forks source link

FastAPI Auth + Login Page | dayDreams ++ #82

Open utterances-bot opened 3 years ago

utterances-bot commented 3 years ago

FastAPI Auth + Login Page | dayDreams ++

Using auth in Fastapi and connecting it to a Login Form

https://blog.athulcyriac.xyz/fastapi-auth/

jacrack commented 3 years ago

Hi, thanks for the tutorial :D i have a problem with redirect response in the login function:

 bson.errors.InvalidId: 'dashboard' is not a valid ObjectId, it must be a 12-byte input or a 24-character hex string

and this is my route on app.py

 @app.get("/dashboard", response_class=HTMLResponse, dependencies=[Depends(manager)], tags=["Templates"])
async def dashboard(request: Request):
    return templates.TemplateResponse("dashboard.html", {"request": request})

i don't know hat happens, I already tried in many ways :c im using MongoDB for the users

jacrack commented 3 years ago

The top part is part of the error, this comes out at the end:

AttributeError: _ObjectId__id
INFO:     127.0.0.1:63440 - "GET /dashboard HTTP/1.1" 500 Internal Server Error
jacrack commented 3 years ago

sorry, I forgot the loader XD

@manager.user_loader
def load_user(username: str):
    user = users_collection.find_one({"username": str(username)})
    if user:
        return user
FIRDOUS-BHAT commented 3 years ago

Please rename the argument tokenUrl with token_url in your LoginManager