/* global React */
function SiteNav({ route, onNavigate, user, onSignIn, onSignOut }) {
return (
);
}
function SiteFooter() {
return (
);
}
function GoogleSSOModal({ authConfig, onClose, onSignIn }) {
const [loading, setLoading] = React.useState(false);
const [errorText, setErrorText] = React.useState("");
React.useEffect(() => {
if (!authConfig?.enabled || !authConfig?.google_client_id) return;
function initialize() {
if (!window.google?.accounts?.id) {
setTimeout(initialize, 250);
return;
}
window.google.accounts.id.initialize({
client_id: authConfig.google_client_id,
callback: async (response) => {
try {
setLoading(true);
setErrorText("");
const result = await fetch("/api/auth/google", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ id_token: response.credential }),
});
const payload = await result.json();
if (!result.ok || !payload.ok) {
throw new Error(payload?.detail || payload?.error || "Google sign-in failed.");
}
const name = payload.user?.name || "Wheelsafar user";
const user = {
name,
email: payload.user?.email || "",
phone: "",
avatar: name.split(" ").map((part) => part[0]).join("").slice(0, 2).toUpperCase() || "WS",
picture: payload.user?.picture || "",
};
onSignIn(user);
} catch (error) {
setErrorText(error.message || "Google sign-in failed.");
} finally {
setLoading(false);
}
},
auto_select: false,
});
const holder = document.getElementById("google-signin-modal");
if (holder) {
const buttonWidth = Math.min(320, Math.max(220, holder.clientWidth || 0));
window.google.accounts.id.renderButton(holder, {
theme: "filled_black",
size: "large",
text: "signin_with",
shape: "pill",
width: buttonWidth,
});
}
}
initialize();
}, [authConfig, onSignIn]);
return (
e.stopPropagation()}>
Sign in to list an item
Before your listing goes to the WhatsApp group, we verify you with your Google account linked to Wheelsafar.
{!authConfig?.enabled ?
Google SSO not configured on backend.
: null}
{loading ? : "Loading Google…"}
{errorText ?
{errorText}
: null}
By continuing, you agree to Wheelsafar's community rules and confirm that listings are your own.
);
}
Object.assign(window, { SiteNav, SiteFooter, GoogleSSOModal });