diff --git a/verification_server/src/server.py b/verification_server/src/server.py index 66551f6..9ed9b70 100644 --- a/verification_server/src/server.py +++ b/verification_server/src/server.py @@ -49,7 +49,7 @@ async def index(): @app.get("/callback") -async def callback(request: Request, code: str, state: str): +async def callback(request: Request, state: str, code: str | None = None): # Claim the pending verification. Deleting it up front makes the state single use verification = await app.state.pool.fetchrow( """ @@ -69,6 +69,18 @@ async def callback(request: Request, code: str, state: str): status_code=400, ) + # Galtinn redirects back with an error instead of a code if the user declines or something goes wrong. + # The verification is already claimed, so the user can start over right away + if not code: + return templates.TemplateResponse( + "error.html", + { + "request": request, + "message": "Innloggingen i Galtinn ble avbrutt. Prøv igjen fra start!", + }, + status_code=400, + ) + # The challenge column holds the PKCE code verifier discord_id, code_verifier = list(verification.values())