Update main.py
Browse files
main.py
CHANGED
@@ -182,7 +182,20 @@ async def landing(request: Request):
|
|
182 |
# Your other routes and app configuration go here
|
183 |
|
184 |
@app.get("/login", response_class=HTMLResponse)
|
185 |
-
async def login(request: Request):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
186 |
return templates.TemplateResponse("login.html", {"request": request})
|
187 |
|
188 |
|
|
|
182 |
# Your other routes and app configuration go here
|
183 |
|
184 |
@app.get("/login", response_class=HTMLResponse)
|
185 |
+
async def login(request: Request, token: Optional[str] = Depends(oauth2_scheme, use_cache=False)):
|
186 |
+
# Check if user is already authenticated
|
187 |
+
if token:
|
188 |
+
try:
|
189 |
+
# Verify the token (you should have a function similar to 'verify_token')
|
190 |
+
user_email = verify_token(token)
|
191 |
+
if user_email:
|
192 |
+
# If token is valid, redirect to /protected
|
193 |
+
return RedirectResponse(url="/protected")
|
194 |
+
except Exception as e:
|
195 |
+
# Handle token verification errors (e.g., token expired)
|
196 |
+
pass
|
197 |
+
|
198 |
+
# If not authenticated, show the login page
|
199 |
return templates.TemplateResponse("login.html", {"request": request})
|
200 |
|
201 |
|