@@ -11,7 +11,13 @@ import { isSsoEnabled } from '@/lib/core/config/env-flags'
1111import { validateCallbackUrl } from '@/lib/core/security/input-validation'
1212import { quickValidateEmail } from '@/lib/messaging/email/validation'
1313import { captureClientEvent , captureEvent } from '@/lib/posthog/client'
14- import { buildAuthCrossLink , POST_AUTH_REDIRECT_STORAGE_KEY } from '@/app/(auth)/auth-redirect'
14+ import {
15+ buildAuthCrossLink ,
16+ DEFAULT_POST_AUTH_ROUTE ,
17+ POST_AUTH_REDIRECT_STORAGE_KEY ,
18+ resolvePostSignupDestination ,
19+ VERIFY_FROM_SIGNUP_ROUTE ,
20+ } from '@/app/(auth)/auth-redirect'
1521import {
1622 AuthDivider ,
1723 AuthField ,
@@ -86,6 +92,8 @@ interface SignupFormProps {
8692 microsoftAvailable : boolean
8793 isProduction : boolean
8894 emailSignupEnabled : boolean
95+ /** Server-derived: verification is enabled AND a mail provider is configured. */
96+ emailVerificationEnabled : boolean
8997}
9098
9199function SignupFormContent ( {
@@ -94,6 +102,7 @@ function SignupFormContent({
94102 microsoftAvailable,
95103 isProduction,
96104 emailSignupEnabled,
105+ emailVerificationEnabled,
97106} : SignupFormProps ) {
98107 const router = useRouter ( )
99108 const searchParams = useSearchParams ( )
@@ -343,18 +352,29 @@ function SignupFormContent({
343352 logger . error ( 'Failed to refresh session after signup:' , sessionError )
344353 }
345354
355+ const destination = resolvePostSignupDestination ( { emailVerificationEnabled, redirectUrl } )
356+
346357 if ( typeof window !== 'undefined' ) {
347- sessionStorage . setItem ( 'verificationEmail' , emailValue )
348- if ( redirectUrl ) {
349- sessionStorage . setItem ( POST_AUTH_REDIRECT_STORAGE_KEY , redirectUrl )
350- } else {
351- // Clear any leftover from an earlier signup in this tab — otherwise a
352- // signup with no callbackUrl inherits the previous CLI/invite destination.
353- sessionStorage . removeItem ( POST_AUTH_REDIRECT_STORAGE_KEY )
358+ // Clear any leftover from an earlier signup in this tab — otherwise a
359+ // signup with no callbackUrl inherits the previous CLI/invite destination.
360+ sessionStorage . removeItem ( 'verificationEmail' )
361+ sessionStorage . removeItem ( POST_AUTH_REDIRECT_STORAGE_KEY )
362+
363+ if ( destination . kind === 'verify' ) {
364+ sessionStorage . setItem ( 'verificationEmail' , emailValue )
365+ if ( redirectUrl ) sessionStorage . setItem ( POST_AUTH_REDIRECT_STORAGE_KEY , redirectUrl )
354366 }
355367 }
356368
357- router . push ( '/verify?fromSignup=true' )
369+ if ( destination . kind === 'verify' ) {
370+ router . push ( VERIFY_FROM_SIGNUP_ROUTE )
371+ } else if ( destination . kind === 'redirect' ) {
372+ // Full navigation, matching the verify hop: the destination (invite, CLI
373+ // handoff) is server-rendered and must see the fresh session cookie.
374+ window . location . href = destination . url
375+ } else {
376+ router . push ( DEFAULT_POST_AUTH_ROUTE )
377+ }
358378 } catch ( error ) {
359379 logger . error ( 'Signup error:' , error )
360380 setIsLoading ( false )
@@ -488,6 +508,7 @@ export default function SignupPage({
488508 microsoftAvailable,
489509 isProduction,
490510 emailSignupEnabled,
511+ emailVerificationEnabled,
491512} : SignupFormProps ) {
492513 return (
493514 < Suspense
@@ -499,6 +520,7 @@ export default function SignupPage({
499520 microsoftAvailable = { microsoftAvailable }
500521 isProduction = { isProduction }
501522 emailSignupEnabled = { emailSignupEnabled }
523+ emailVerificationEnabled = { emailVerificationEnabled }
502524 />
503525 </ Suspense >
504526 )
0 commit comments