|
|
|
@@ -1,6 +1,6 @@
|
|
|
|
|
"use client";
|
|
|
|
|
|
|
|
|
|
import { useEffect } from "react";
|
|
|
|
|
import { useEffect, useState } from "react";
|
|
|
|
|
import { useRouter } from "next/navigation";
|
|
|
|
|
import { useAuth, useAppShell } from "@abe-kap/appshell-sdk/react";
|
|
|
|
|
import { PortalAside, PanelBrand } from "@/components/portal/parts";
|
|
|
|
@@ -10,18 +10,34 @@ import { isShellConfigured } from "@/lib/appshell";
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Post-OAuth onboarding — a first-time Google user completes their CRM profile
|
|
|
|
|
* (everything except email, which Google already verified). Only reachable while
|
|
|
|
|
* authenticated; unauthenticated visitors are sent back to sign in.
|
|
|
|
|
* (everything except email, which Google already verified).
|
|
|
|
|
*
|
|
|
|
|
* This screen is ONLY a step in the OAuth → onboarding handoff: the login page
|
|
|
|
|
* stashes the verified email in `sessionStorage` right before routing here. Any
|
|
|
|
|
* other way in — a typed URL, a fresh tab, a lost session — has no handoff hint
|
|
|
|
|
* (and possibly no session), so we bounce back to sign in rather than showing an
|
|
|
|
|
* empty form.
|
|
|
|
|
*/
|
|
|
|
|
export default function OnboardingPage() {
|
|
|
|
|
const router = useRouter();
|
|
|
|
|
const { status } = useAuth();
|
|
|
|
|
const { ready } = useAppShell();
|
|
|
|
|
const [allowed, setAllowed] = useState(false);
|
|
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
|
if (isShellConfigured() && ready && status === "unauthenticated") router.replace("/portal/login");
|
|
|
|
|
if (!isShellConfigured()) { setAllowed(true); return; } // local dev without the Shell
|
|
|
|
|
if (!ready) return; // wait for session restore
|
|
|
|
|
let hasHandoff = false;
|
|
|
|
|
try { hasHandoff = !!sessionStorage.getItem("onboard_email"); } catch { /* ignore */ }
|
|
|
|
|
if (status === "unauthenticated" || !hasHandoff) {
|
|
|
|
|
router.replace("/portal/login");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
setAllowed(true);
|
|
|
|
|
}, [ready, status, router]);
|
|
|
|
|
|
|
|
|
|
if (!allowed) return <main className="portal-main"><span className="portal-grid" /></main>;
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<main className="portal-main">
|
|
|
|
|
<span className="portal-grid" />
|
|
|
|
|