Skip to content

Commit

Permalink
Add error handling on auth callback
Browse files Browse the repository at this point in the history
  • Loading branch information
Not-A-Normal-Robot committed May 18, 2024
1 parent 5f07dc3 commit 771dbf4
Showing 1 changed file with 23 additions and 6 deletions.
29 changes: 23 additions & 6 deletions auth/discord-callback.html
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
<!DOCTYPE html>
<html lang="en">

<head>
<meta charset="UTF-8">
<meta name="darkreader-lock">
<title>Techmino Hub - logging in...</title>
</head>

<body style="background:#000;color:#FFF">
<h1 id="txt">
<noscript>You cannot login with JavaScript disabled.</noscript>
Expand All @@ -15,16 +17,31 @@ <h1 id="txt">

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);
}
</script>
</body>

</html>

0 comments on commit 771dbf4

Please sign in to comment.