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..9378086 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.");
}
};
@@ -24,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"
+ />
+
)}
@@ -46,11 +70,14 @@ const HomePage = () => {
-
-
- {!user && (
+ {user ? (
+
+ ) : (
)}
+
+ {loginError && (
+
+ {loginError}
+
+ )}
diff --git a/src/components/Menu.tsx b/src/components/Menu.tsx
index 9d25a9b..32ae8ac 100644
--- a/src/components/Menu.tsx
+++ b/src/components/Menu.tsx
@@ -3,6 +3,7 @@ import MenuIcon from "@mui/icons-material/Menu";
import CloseIcon from "@mui/icons-material/Close";
import BookmarkBorderOutlinedIcon from "@mui/icons-material/BookmarkBorderOutlined";
import LoginOutlinedIcon from "@mui/icons-material/LoginOutlined";
+import LogoutOutlinedIcon from "@mui/icons-material/LogoutOutlined";
import MyLocationOutlinedIcon from "@mui/icons-material/MyLocationOutlined";
import PhotoLibraryOutlinedIcon from "@mui/icons-material/PhotoLibraryOutlined";
import DarkModeOutlinedIcon from "@mui/icons-material/DarkModeOutlined";
@@ -32,9 +33,27 @@ const Menu = ({
themeMode,
onToggleTheme,
}: MenuProps) => {
- const { user } = useAuth();
+ const { user, signOut } = useAuth();
const navigate = useNavigate();
const [open, setOpen] = useState(false);
+ const [signingOut, setSigningOut] = useState(false);
+ const [signOutError, setSignOutError] = useState("");
+
+ const handleSignOut = async () => {
+ setSigningOut(true);
+ setSignOutError("");
+
+ try {
+ await signOut();
+ setOpen(false);
+ navigate("/");
+ } catch (error) {
+ console.error("Sign out failed:", error);
+ setSignOutError("Unable to sign out. Please try again.");
+ } finally {
+ setSigningOut(false);
+ }
+ };
const fullName = user?.user_metadata.full_name || "Guest";
const firstName = fullName.split(" ")[0];
@@ -157,6 +176,28 @@ const Menu = ({
{themeOption}
+
+
+
+ {signOutError && (
+
+ {signOutError}
+
+ )}
)}
diff --git a/src/context/AuthContext.tsx b/src/context/AuthContext.tsx
index 24dd244..9016085 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,18 +42,26 @@ 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 () => {
- 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/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..b54f68a 100644
--- a/src/styles/HomePage.css
+++ b/src/styles/HomePage.css
@@ -119,8 +119,19 @@
margin-top: 34px;
}
+.nav-google-login {
+ display: flex;
+ align-items: center;
+ justify-content: flex-end;
+}
+
+.login-error {
+ margin: 14px 0 0;
+ color: #ffb4b4;
+ font-size: 14px;
+}
+
.explore-button,
-.continue-guest,
.guest-link {
font-family: var(--calistoga);
cursor: pointer;
@@ -145,26 +156,18 @@
box-shadow: 0 18px 34px rgba(76, 202, 237, 0.26);
}
-.continue-guest,
.guest-link {
border: 1px solid rgba(246, 251, 255, 0.2);
background: rgba(255, 255, 255, 0.08);
color: #f6fbff;
}
-.continue-guest {
- padding: 11px 18px;
- border-radius: 8px;
- font-size: 14px;
-}
-
.guest-link {
padding: 14px 20px;
border-radius: 8px;
font-size: 16px;
}
-.continue-guest:hover,
.guest-link:hover {
background: rgba(255, 255, 255, 0.16);
transform: translateY(-2px);
@@ -191,11 +194,6 @@
font-size: 18px;
}
- .continue-guest {
- padding: 10px 12px;
- font-size: 13px;
- }
-
.landing-shell {
width: min(100% - 28px, 900px);
min-height: calc(100vh - 82px);
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;