Download API_routes/auth.py from Muxperts/Veda: direct link, hf CLI and curl.
- Browser
- Download file 500 Bytes
-
https://huggingface.co/spaces/Muxperts/Veda/resolve/main/API_routes/auth.py
- Command line
-
hf download hf://spaces/Muxperts/Veda/API_routes/auth.py
-
curl -L -o auth.py https://huggingface.co/spaces/Muxperts/Veda/resolve/main/API_routes/auth.py
500 Bytes
| from fastapi import Request | |
| from fastapi.responses import RedirectResponse | |
| def require_login(request: Request): | |
| """ | |
| Checks if a user is logged in. | |
| If NOT logged in: Returns a RedirectResponse to the login page. | |
| If Logged in: Returns the user dictionary. | |
| """ | |
| if "user" not in request.session: | |
| # Instead of raising an error, we return a RedirectResponse | |
| return RedirectResponse(url="/login", status_code=303) | |
| return request.session["user"] |