Redirecting to store...
-diff --git a/src/components/auth/RedirectHandler.ts b/src/components/auth/RedirectHandler.ts index 4482f4e..4c7e51a 100644 --- a/src/components/auth/RedirectHandler.ts +++ b/src/components/auth/RedirectHandler.ts @@ -1,85 +1,92 @@ import PocketBase from "pocketbase"; export class RedirectHandler { - private pb: PocketBase; - private contentEl: HTMLElement; - private params: URLSearchParams; - private provider: any; + private pb: PocketBase; + private contentEl: HTMLElement; + private params: URLSearchParams; + private provider: any; - constructor() { - this.pb = new PocketBase("https://pocketbase.ieeeucsd.org"); - this.contentEl = this.getContentElement(); - this.params = new URLSearchParams(window.location.search); - this.provider = this.getStoredProvider(); - this.handleRedirect(); + constructor() { + this.pb = new PocketBase("https://pocketbase.ieeeucsd.org"); + this.contentEl = this.getContentElement(); + this.params = new URLSearchParams(window.location.search); + this.provider = this.getStoredProvider(); + this.handleRedirect(); + } + + private getContentElement(): HTMLElement { + const contentEl = document.getElementById("content"); + if (!contentEl) { + throw new Error("Content element not found"); + } + return contentEl; + } + + private getStoredProvider() { + return JSON.parse(localStorage.getItem("provider") || "{}"); + } + + private showError(message: string) { + this.contentEl.innerHTML = ` +
${message}
+ + Return to Home + + `; + } + + private async handleRedirect() { + const code = this.params.get("code"); + const state = this.params.get("state"); + + if (!code) { + this.showError("No authorization code found in URL."); + return; } - private getContentElement(): HTMLElement { - const contentEl = document.getElementById("content"); - if (!contentEl) { - throw new Error("Content element not found"); - } - return contentEl; + if (state !== this.provider.state) { + this.showError("Invalid state parameter."); + return; } - private getStoredProvider() { - return JSON.parse(localStorage.getItem("provider") || "{}"); - } + try { + const authData = await this.pb + .collection("users") + .authWithOAuth2Code( + "oidc", + code, + this.provider.codeVerifier, + window.location.origin + "/oauth2-redirect", + { emailVisibility: false }, + ); - private showError(message: string) { - this.contentEl.innerHTML = `${message}
`; - } - - private async handleRedirect() { - const code = this.params.get("code"); - const state = this.params.get("state"); - - if (!code) { - this.showError("No authorization code found in URL."); - return; - } - - if (state !== this.provider.state) { - this.showError("Invalid state parameter."); - return; - } - - try { - const authData = await this.pb.collection("users").authWithOAuth2Code( - "oidc", - code, - this.provider.codeVerifier, - window.location.origin + "/oauth2-redirect", - { emailVisibility: false } - ); - - console.log("Auth successful:", authData); - this.contentEl.innerHTML = ` + console.log("Auth successful:", authData); + this.contentEl.innerHTML = `Authentication Successful!
Redirecting to store...
- Our store is currently under development. Check back - later for IEEE UCSD merchandise! In the meantime, please - make sure your profile is up to date with your IEEE - Member ID and resume. -
-{description}
-Redirecting to store...
-Redirecting to dashboard...
+