show an error page when galtinn redirects back without a code

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
leanderandClaude Opus 5.5 committed 2026-10-23 21:34:37 +02:00
1 parent f08cb453ec
commit f0039ee240
1 file changed
+13 -1
+13 -1
View File
@@ -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())