Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
57 changes: 45 additions & 12 deletions src/components/HomePage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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.");
}
};

Expand All @@ -24,9 +38,19 @@ const HomePage = () => {
</div>

{!user && (
<button className="continue-guest" onClick={() => navigate("/map")}>
Explore as Guest
</button>
<div className="nav-google-login">
<GoogleLogin
onSuccess={handleGoogleSuccess}
onError={() =>
setLoginError("Google sign-in was cancelled or failed.")
}
shape="pill"
size="large"
text="signin_with"
theme="outline"
width="210"
/>
</div>
)}
</nav>

Expand All @@ -46,11 +70,14 @@ const HomePage = () => {
</p>

<div className="landing-actions">
<button className="explore-button" onClick={handleExploreClick}>
{user ? "Open Map" : "Sign in with Google"}
</button>

{!user && (
{user ? (
<button
className="explore-button"
onClick={() => navigate("/map")}
>
Open Map
</button>
) : (
<button
className="guest-link"
onClick={() => navigate("/map")}
Expand All @@ -60,6 +87,12 @@ const HomePage = () => {
</button>
)}
</div>

{loginError && (
<p className="login-error" role="alert">
{loginError}
</p>
)}
</div>

</section>
Expand Down
43 changes: 42 additions & 1 deletion src/components/Menu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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];
Expand Down Expand Up @@ -157,6 +176,28 @@ const Menu = ({
</button>

{themeOption}

<button
type="button"
className="menu-option menu-option-signout"
onClick={handleSignOut}
disabled={signingOut}
role="menuitem"
>
<span className="menu-option-icon">
<LogoutOutlinedIcon fontSize="small" />
</span>
<span className="menu-option-copy">
<strong>{signingOut ? "Signing out…" : "Sign out"}</strong>
<small>End this session on this device</small>
</span>
</button>

{signOutError && (
<p className="menu-error" role="alert">
{signOutError}
</p>
)}
</div>
</div>
)}
Expand Down
28 changes: 18 additions & 10 deletions src/context/AuthContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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<void>; // Function to trigger Google login
signInWithGoogle: (idToken: string) => Promise<void>; // Function to log in with Google OAuth
signOut: () => Promise<void>; // Function to log out
loading: boolean; // Whether auth state is still being checked
};
Expand Down Expand Up @@ -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
Expand Down
23 changes: 16 additions & 7 deletions src/main.tsx
Original file line number Diff line number Diff line change
@@ -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(
<StrictMode>
<App />
<GoogleOAuthProvider clientId={googleClientId}>
<App />
</GoogleOAuthProvider>
</StrictMode>,
)
);
26 changes: 12 additions & 14 deletions src/styles/HomePage.css
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
Expand All @@ -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);
Expand Down
37 changes: 37 additions & 0 deletions src/styles/Menu.css
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand Down
Loading