From 5b4f5f457e629f169c25de5bd9f76d1a8d7e8a63 Mon Sep 17 00:00:00 2001
From: Jason Chen
Date: Sun, 4 Oct 2026 17:46:05 -0400
Subject: [PATCH 1/3] Updated Google OAuth login functionality and update
related components
---
package-lock.json | 11 ++++++++
package.json | 1 +
src/components/HomePage.tsx | 50 +++++++++++++++++++++++++++++++------
src/context/AuthContext.tsx | 20 ++++++++-------
src/main.tsx | 23 +++++++++++------
src/styles/HomePage.css | 6 +++++
6 files changed, 88 insertions(+), 23 deletions(-)
diff --git a/package-lock.json b/package-lock.json
index 5970185..d81340b 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -14,6 +14,7 @@
"@mui/material": "^7.3.7",
"@mui/x-date-pickers": "^8.26.0",
"@react-google-maps/api": "^2.20.8",
+ "@react-oauth/google": "^0.13.5",
"@supabase/supabase-js": "^2.90.1",
"axios": "^1.13.2",
"dayjs": "^1.11.19",
@@ -1637,6 +1638,16 @@
"integrity": "sha512-tieX9Va5w1yP88vMgfH1pHTacDQ9TgDTjox3tLlisKDXRQWdjw+QeVVghhf5XqqIxXHgPdcGwBvKY6UP+SIvLw==",
"license": "MIT"
},
+ "node_modules/@react-oauth/google": {
+ "version": "0.13.5",
+ "resolved": "https://registry.npmjs.org/@react-oauth/google/-/google-0.13.5.tgz",
+ "integrity": "sha512-xQWri2s/3nNekZJ4uuov2aAfQYu83bN3864KcFqw2pK1nNbFurQIjPFDXhWaKH3IjYJ2r/9yyIIpsn5lMqrheQ==",
+ "license": "MIT",
+ "peerDependencies": {
+ "react": ">=16.8.0",
+ "react-dom": ">=16.8.0"
+ }
+ },
"node_modules/@rolldown/pluginutils": {
"version": "1.0.0-beta.47",
"resolved": "https://registry.npmjs.org/@rolldown/pluginutils/-/pluginutils-1.0.0-beta.47.tgz",
diff --git a/package.json b/package.json
index 842e3ad..3bc9bd0 100644
--- a/package.json
+++ b/package.json
@@ -16,6 +16,7 @@
"@mui/material": "^7.3.7",
"@mui/x-date-pickers": "^8.26.0",
"@react-google-maps/api": "^2.20.8",
+ "@react-oauth/google": "^0.13.5",
"@supabase/supabase-js": "^2.90.1",
"axios": "^1.13.2",
"dayjs": "^1.11.19",
diff --git a/src/components/HomePage.tsx b/src/components/HomePage.tsx
index eb607f7..60bba4c 100644
--- a/src/components/HomePage.tsx
+++ b/src/components/HomePage.tsx
@@ -2,16 +2,30 @@ import { useNavigate } from "react-router-dom";
import "../styles/HomePage.css";
import { useAuth } from "../context/AuthContext";
import logo from "../assets/logo2.jpg";
+import { useState } from "react";
+import {
+ GoogleLogin,
+ type CredentialResponse,
+} from "@react-oauth/google";
const HomePage = () => {
const { user, signInWithGoogle } = useAuth();
const navigate = useNavigate();
+ const [loginError, setLoginError] = useState("");
- const handleExploreClick = () => {
- if (user) {
+ const handleGoogleSuccess = async (response: CredentialResponse) => {
+ if (!response.credential) {
+ setLoginError("Google did not return a login credential.");
+ return;
+ }
+
+ try {
+ setLoginError("");
+ await signInWithGoogle(response.credential);
navigate("/map");
- } else {
- signInWithGoogle();
+ } catch (error) {
+ console.error("Google sign-in failed:", error);
+ setLoginError("Unable to sign in with Google. Please try again.");
}
};
@@ -46,9 +60,25 @@ const HomePage = () => {
-
+ {user ? (
+
+ ) : (
+
+ setLoginError("Google sign-in was cancelled or failed.")
+ }
+ shape="pill"
+ size="large"
+ text="signin_with"
+ theme="outline"
+ />
+ )}
{!user && (
)}
+
+ {loginError && (
+
+ {loginError}
+
+ )}
diff --git a/src/context/AuthContext.tsx b/src/context/AuthContext.tsx
index 24dd244..8d92401 100644
--- a/src/context/AuthContext.tsx
+++ b/src/context/AuthContext.tsx
@@ -6,7 +6,7 @@ import type { User, Session } from "@supabase/supabase-js";
type AuthContextType = {
user: User | null; // Current user object or null if not logged in
session: Session | null; // Current session with tokens
- signInWithGoogle: () => Promise; // Function to trigger Google login
+ signInWithGoogle: (idToken: string) => Promise; // Function to log in with Google OAuth
signOut: () => Promise; // Function to log out
loading: boolean; // Whether auth state is still being checked
};
@@ -42,14 +42,16 @@ export function AuthProvider({ children }: { children: React.ReactNode }) {
}, []);
// Trigger Google OAuth sign-in popup
- const signInWithGoogle = async () => {
- await supabase.auth.signInWithOAuth({
- provider: "google",
- options: {
- redirectTo: window.location.origin + "/map", // Where to redirect after login
- },
- });
- };
+ const signInWithGoogle = async (idToken: string) => {
+ const { error } = await supabase.auth.signInWithIdToken({
+ provider: "google",
+ token: idToken,
+ });
+
+ if (error) {
+ throw error;
+ }
+};
// End user session and clear auth state
const signOut = async () => {
diff --git a/src/main.tsx b/src/main.tsx
index bef5202..f1f3f48 100644
--- a/src/main.tsx
+++ b/src/main.tsx
@@ -1,10 +1,19 @@
-import { StrictMode } from 'react'
-import { createRoot } from 'react-dom/client'
-import './index.css'
-import App from './App.tsx'
+import { StrictMode } from "react";
+import { createRoot } from "react-dom/client";
+import { GoogleOAuthProvider } from "@react-oauth/google";
+import "./index.css";
+import App from "./App.tsx";
-createRoot(document.getElementById('root')!).render(
+const googleClientId = import.meta.env.VITE_GOOGLE_CLIENT_ID;
+
+if (!googleClientId) {
+ throw new Error("VITE_GOOGLE_CLIENT_ID is not configured");
+}
+
+createRoot(document.getElementById("root")!).render(
-
+
+
+
,
-)
+);
\ No newline at end of file
diff --git a/src/styles/HomePage.css b/src/styles/HomePage.css
index 0951c99..3e384da 100644
--- a/src/styles/HomePage.css
+++ b/src/styles/HomePage.css
@@ -119,6 +119,12 @@
margin-top: 34px;
}
+.login-error {
+ margin: 14px 0 0;
+ color: #ffb4b4;
+ font-size: 14px;
+}
+
.explore-button,
.continue-guest,
.guest-link {
From fa2006db838b05c294916f01db14e2e8043cbd3e Mon Sep 17 00:00:00 2001
From: Jason Chen
Date: Sun, 4 Oct 2026 17:53:43 -0400
Subject: [PATCH 2/3] Button reorganized
---
src/components/HomePage.tsx | 29 +++++++++++++----------------
src/styles/HomePage.css | 20 ++++++--------------
2 files changed, 19 insertions(+), 30 deletions(-)
diff --git a/src/components/HomePage.tsx b/src/components/HomePage.tsx
index 60bba4c..9378086 100644
--- a/src/components/HomePage.tsx
+++ b/src/components/HomePage.tsx
@@ -38,9 +38,19 @@ const HomePage = () => {
{!user && (
-
+
+
+ setLoginError("Google sign-in was cancelled or failed.")
+ }
+ shape="pill"
+ size="large"
+ text="signin_with"
+ theme="outline"
+ width="210"
+ />
+
)}
@@ -68,19 +78,6 @@ const HomePage = () => {
Open Map
) : (
-
- setLoginError("Google sign-in was cancelled or failed.")
- }
- shape="pill"
- size="large"
- text="signin_with"
- theme="outline"
- />
- )}
-
- {!user && (
{themeOption}
+
+
+
+ {signOutError && (
+
+ {signOutError}
+
+ )}
)}
diff --git a/src/context/AuthContext.tsx b/src/context/AuthContext.tsx
index 8d92401..9016085 100644
--- a/src/context/AuthContext.tsx
+++ b/src/context/AuthContext.tsx
@@ -55,7 +55,13 @@ export function AuthProvider({ children }: { children: React.ReactNode }) {
// End user session and clear auth state
const signOut = async () => {
- await supabase.auth.signOut();
+ const { error } = await supabase.auth.signOut({
+ scope: "local",
+ });
+
+ if (error) {
+ throw error;
+ }
};
// Provide auth data to all child components
diff --git a/src/styles/Menu.css b/src/styles/Menu.css
index a17900a..780f9ed 100644
--- a/src/styles/Menu.css
+++ b/src/styles/Menu.css
@@ -201,6 +201,33 @@
background: #eef1f1;
}
+.menu-option-signout {
+ margin-top: 4px;
+ border-top: 1px solid #e7ebec;
+ border-radius: 0 0 10px 10px;
+ color: #a33f3f;
+}
+
+.menu-option-signout .menu-option-icon {
+ color: #a33f3f;
+}
+
+.menu-option-signout .menu-option-copy strong {
+ color: #8f3434;
+}
+
+.menu-option:disabled {
+ cursor: wait;
+ opacity: 0.65;
+}
+
+.menu-error {
+ margin: 3px 10px 7px;
+ color: #a33f3f;
+ font-size: 11px;
+ line-height: 1.4;
+}
+
.map-page[data-theme="dark"] .menu-container,
.map-page[data-theme="dark"] .menu-popover {
border-color: rgba(255, 255, 255, 0.12);
@@ -264,6 +291,16 @@
color: #c8e0d7;
}
+.map-page[data-theme="dark"] .menu-option-signout {
+ border-top-color: #34454c;
+}
+
+.map-page[data-theme="dark"] .menu-option-signout .menu-option-icon,
+.map-page[data-theme="dark"] .menu-option-signout .menu-option-copy strong,
+.map-page[data-theme="dark"] .menu-error {
+ color: #ffabab;
+}
+
@keyframes menuPopoverIn {
from {
opacity: 0;