Skip to content

Commit

Permalink
Fix error handling in discord 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 771dbf4 commit 2779111
Showing 1 changed file with 16 additions and 12 deletions.
28 changes: 16 additions & 12 deletions auth/discord-callback.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,30 +17,34 @@ <h1 id="txt">

document.getElementById("txt").textContent = "Logging in...";

let params = new URLSearchParams(window.location.search);
function getSession() {
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.");
}
if(params.get("error")) {
return onError(
`${params.get("error")} (${params.get("error_code")}): ${params.get("error_description")}.`
);
}

const session = SUPABASE.auth.exchangeCodeForSession(params.get("code"));
if(!params.get("code")) {
return onError("Auth code not found in URL.");
}

// console.log(session); debugger;
const session = SUPABASE.auth.exchangeCodeForSession(params.get("code"));
console.log(session);
}

function onSuccess() {
document.getElementById("txt").textContent = "You are now logged in! Redirecting...";
window.location.href = "/auth/profile-setup.html";
}
function onError(msg) {
document.getElementById("txt").textContent = `Login failed:\n${msg}\nYou will be redirected to the main page.`;
console.error(msg); debugger;
setTimeout(() => window.location.href = "/index.html", 5000);
}

getSession();
</script>
</body>

Expand Down

0 comments on commit 2779111

Please sign in to comment.