From 43fe443c52e38ac50aae969fdb560993a84764c3 Mon Sep 17 00:00:00 2001 From: chark1es Date: Mon, 10 Feb 2025 14:03:19 -0800 Subject: [PATCH] changed "Online Store" to "Dashboard" --- src/components/auth/RedirectHandler.ts | 145 ++++++++++---------- src/components/core/Navbar.astro | 2 +- src/components/store/DefaultStoreView.astro | 23 ---- src/components/store/StoreItem.astro | 37 ----- src/data/pages.json | 48 +++---- src/pages/oauth2-redirect.astro | 23 ++-- 6 files changed, 111 insertions(+), 167 deletions(-) delete mode 100644 src/components/store/DefaultStoreView.astro delete mode 100644 src/components/store/StoreItem.astro 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...

`; - - try { - // Update last login before redirecting - await this.pb.collection("users").update(authData.record.id, { - last_login: new Date().toISOString() - }); - - // Clean up and redirect - localStorage.removeItem("provider"); - window.location.href = "/online-store"; - } catch (err) { - console.error("Failed to update last login:", err); - // Still redirect even if last_login update fails - localStorage.removeItem("provider"); - window.location.href = "/online-store"; - } - } catch (err: any) { - console.error("Auth error:", err); - this.showError(`Failed to complete authentication: ${err.message}`); - } + + try { + // Update last login before redirecting + await this.pb.collection("users").update(authData.record.id, { + last_login: new Date().toISOString(), + }); + + // Clean up and redirect + localStorage.removeItem("provider"); + window.location.href = "/dashboard"; + } catch (err) { + console.error("Failed to update last login:", err); + // Still redirect even if last_login update fails + localStorage.removeItem("provider"); + window.location.href = "/dashboard"; + } + } catch (err: any) { + console.error("Auth error:", err); + this.showError(`Failed to complete authentication: ${err.message}`); } -} \ No newline at end of file + } +} diff --git a/src/components/core/Navbar.astro b/src/components/core/Navbar.astro index b60eb09..3420da4 100644 --- a/src/components/core/Navbar.astro +++ b/src/components/core/Navbar.astro @@ -29,7 +29,7 @@ import pages from "../../data/pages.json"; href={page.path} class={`uppercase rounded-full duration-300 px-[1.5vw] py-[0.2vw] text-[1.2vw] text-nowrap ${ - page.name === "Online Store" + page.name === "Dashboard" ? "bg-ieee-yellow text-black hover:opacity-70" : "text-white border-white hover:opacity-50 border-[0.1vw] font-light" }`} diff --git a/src/components/store/DefaultStoreView.astro b/src/components/store/DefaultStoreView.astro deleted file mode 100644 index 5dd8287..0000000 --- a/src/components/store/DefaultStoreView.astro +++ /dev/null @@ -1,23 +0,0 @@ -
-
-
-
-

- Store Coming Soon! -

-
-

- 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. -

-
-
-
-
-
diff --git a/src/components/store/StoreItem.astro b/src/components/store/StoreItem.astro deleted file mode 100644 index 6cf9941..0000000 --- a/src/components/store/StoreItem.astro +++ /dev/null @@ -1,37 +0,0 @@ ---- -interface Props { - name: string; - description: string; - price: number; - imageUrl: string; -} - -const { - name, - description, - price, - imageUrl = "https://placehold.co/400x300", -} = Astro.props; ---- - -
-
-
-
- {name} -
-
-
-

{name}

-

{description}

-
- ${price.toFixed(2)} - -
-
-
diff --git a/src/data/pages.json b/src/data/pages.json index 20ac665..664514e 100644 --- a/src/data/pages.json +++ b/src/data/pages.json @@ -1,26 +1,26 @@ [ - { - "name": "Join", - "path": "/join" - }, - { - "name": "Events", - "path": "/events" - }, - { - "name": "Projects", - "path": "/projects" - }, - { - "name": "Board", - "path": "/board" - }, - { - "name": "Find Us", - "path": "/find" - }, - { - "name": "Online Store", - "path": "/online-store" - } + { + "name": "Join", + "path": "/join" + }, + { + "name": "Events", + "path": "/events" + }, + { + "name": "Projects", + "path": "/projects" + }, + { + "name": "Board", + "path": "/board" + }, + { + "name": "Find Us", + "path": "/find" + }, + { + "name": "Dashboard", + "path": "/dashboard" + } ] diff --git a/src/pages/oauth2-redirect.astro b/src/pages/oauth2-redirect.astro index ef7bf0c..20552bb 100644 --- a/src/pages/oauth2-redirect.astro +++ b/src/pages/oauth2-redirect.astro @@ -3,18 +3,15 @@ import Layout from "../layouts/Layout.astro"; const title = "Authenticating..."; --- - -
-
-

Redirecting to store...

-
-
-
-
-
-
- +
+
+

Redirecting to dashboard...

+
+
+
+
+