Session 10: Internal auth refactor, prefetch cascade keys, Sentry, welcome email (1286 tests)
This commit is contained in:
@@ -2,16 +2,34 @@
|
||||
|
||||
import { useRouter } from 'next/navigation';
|
||||
import { useAuth } from '@/contexts/AuthContext';
|
||||
import { useEffect } from 'react';
|
||||
import { useEffect, useRef } from 'react';
|
||||
|
||||
export default function WelcomePage() {
|
||||
const router = useRouter();
|
||||
const { user, loading } = useAuth();
|
||||
const { user, session, loading } = useAuth();
|
||||
const welcomeFiredRef = useRef(false);
|
||||
|
||||
useEffect(() => {
|
||||
if (!loading && !user) router.replace('/signup');
|
||||
}, [loading, user, router]);
|
||||
|
||||
// Session 10 — trigger the welcome email exactly once per mount.
|
||||
// The server-side handler is idempotent via user_metadata
|
||||
// (welcome_email_sent flag), so re-triggers from a refresh are
|
||||
// safe; the ref is just a UX optimization to avoid duplicate
|
||||
// network requests on this page.
|
||||
useEffect(() => {
|
||||
if (welcomeFiredRef.current) return;
|
||||
if (loading || !user || !session) return;
|
||||
welcomeFiredRef.current = true;
|
||||
fetch('/api/welcome-email', {
|
||||
method: 'POST',
|
||||
headers: { Authorization: `Bearer ${session.access_token}` },
|
||||
}).catch(() => {
|
||||
// Fail silent — onboarding must not block on email outages.
|
||||
});
|
||||
}, [loading, user, session]);
|
||||
|
||||
return (
|
||||
<section
|
||||
className="tex-scan"
|
||||
|
||||
Reference in New Issue
Block a user