From 771dbf4579ad823c96f6fca55ba1083e56c3c267 Mon Sep 17 00:00:00 2001 From: Not-A-Normal-Robot Date: Sat, 18 May 2024 18:44:33 +0700 Subject: [PATCH] Add error handling on auth callback --- auth/discord-callback.html | 29 +++++++++++++++++++++++------ 1 file changed, 23 insertions(+), 6 deletions(-) diff --git a/auth/discord-callback.html b/auth/discord-callback.html index ded6b10..1867ef5 100644 --- a/auth/discord-callback.html +++ b/auth/discord-callback.html @@ -1,10 +1,12 @@ + Techmino Hub - logging in... +

@@ -15,16 +17,31 @@

document.getElementById("txt").textContent = "Logging in..."; - const session = await SUPABASE.auth.getSession(); - console.log(session); debugger; + let params = new URLSearchParams(window.location.search); + + if(params.get("error")) { + return onError( + `${params.get("error")} (${params.get("error_code")}): ${params.get("error_description")}.` + ); + } + + if(!params.get("code")) { + return onError("Auth code not found in URL."); + } + + const session = SUPABASE.auth.exchangeCodeForSession(params.get("code")); + + // console.log(session); debugger; - if(session) { + function onSuccess() { document.getElementById("txt").textContent = "You are now logged in! Redirecting..."; window.location.href = "/auth/profile-setup.html"; - } else { - document.getElementById("txt").textContent = "Login failed. Redirecting..."; - window.location.href = "/index.html"; + } + function onError(msg) { + document.getElementById("txt").textContent = `Login failed:\n${msg}\nYou will be redirected to the main page.`; + setTimeout(() => window.location.href = "/index.html", 5000); } + \ No newline at end of file