forked from Goutam/lynkeduppro-crm
Merge pull request 'fix(onboarding): gate direct access behind OAuth handoff' (#14) from tanweer919/lynkeduppro-crm:feat/login-methods into goutamnextflow
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
"use client";
|
"use client";
|
||||||
|
|
||||||
import { useEffect } from "react";
|
import { useEffect, useState } from "react";
|
||||||
import { useRouter } from "next/navigation";
|
import { useRouter } from "next/navigation";
|
||||||
import { useAuth, useAppShell } from "@abe-kap/appshell-sdk/react";
|
import { useAuth, useAppShell } from "@abe-kap/appshell-sdk/react";
|
||||||
import { PortalAside, PanelBrand } from "@/components/portal/parts";
|
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
|
* Post-OAuth onboarding — a first-time Google user completes their CRM profile
|
||||||
* (everything except email, which Google already verified). Only reachable while
|
* (everything except email, which Google already verified).
|
||||||
* authenticated; unauthenticated visitors are sent back to sign in.
|
*
|
||||||
|
* 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() {
|
export default function OnboardingPage() {
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
const { status } = useAuth();
|
const { status } = useAuth();
|
||||||
const { ready } = useAppShell();
|
const { ready } = useAppShell();
|
||||||
|
const [allowed, setAllowed] = useState(false);
|
||||||
|
|
||||||
useEffect(() => {
|
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]);
|
}, [ready, status, router]);
|
||||||
|
|
||||||
|
if (!allowed) return <main className="portal-main"><span className="portal-grid" /></main>;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<main className="portal-main">
|
<main className="portal-main">
|
||||||
<span className="portal-grid" />
|
<span className="portal-grid" />
|
||||||
|
|||||||
@@ -120,6 +120,8 @@ export function RegisterFlow({ mode = "register" }: { mode?: "register" | "onboa
|
|||||||
// register mode: non-fatal — the auth account exists; the profile can be filled in later.
|
// register mode: non-fatal — the auth account exists; the profile can be filled in later.
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// Consume the OAuth→onboarding handoff so a stale hint can't re-open onboarding.
|
||||||
|
try { sessionStorage.removeItem("onboard_email"); } catch { /* ignore */ }
|
||||||
router.push("/dashboard");
|
router.push("/dashboard");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user