@@ -8,7 +8,7 @@ import { createLogger } from '@/lib/logs/console/logger'
88const logger = createLogger ( 'useVerification' )
99
1010interface UseVerificationParams {
11- hasResendKey : boolean
11+ hasEmailService : boolean
1212 isProduction : boolean
1313}
1414
@@ -20,15 +20,15 @@ interface UseVerificationReturn {
2020 isInvalidOtp : boolean
2121 errorMessage : string
2222 isOtpComplete : boolean
23- hasResendKey : boolean
23+ hasEmailService : boolean
2424 isProduction : boolean
2525 verifyCode : ( ) => Promise < void >
2626 resendCode : ( ) => void
2727 handleOtpChange : ( value : string ) => void
2828}
2929
3030export function useVerification ( {
31- hasResendKey ,
31+ hasEmailService ,
3232 isProduction,
3333} : UseVerificationParams ) : UseVerificationReturn {
3434 const router = useRouter ( )
@@ -74,10 +74,10 @@ export function useVerification({
7474 } , [ searchParams ] )
7575
7676 useEffect ( ( ) => {
77- if ( email && ! isSendingInitialOtp && hasResendKey ) {
77+ if ( email && ! isSendingInitialOtp && hasEmailService ) {
7878 setIsSendingInitialOtp ( true )
7979 }
80- } , [ email , isSendingInitialOtp , hasResendKey ] )
80+ } , [ email , isSendingInitialOtp , hasEmailService ] )
8181
8282 const isOtpComplete = otp . length === 6
8383
@@ -157,7 +157,7 @@ export function useVerification({
157157 }
158158
159159 function resendCode ( ) {
160- if ( ! email || ! hasResendKey ) return
160+ if ( ! email || ! hasEmailService ) return
161161
162162 setIsLoading ( true )
163163 setErrorMessage ( '' )
@@ -197,17 +197,27 @@ export function useVerification({
197197
198198 useEffect ( ( ) => {
199199 if ( typeof window !== 'undefined' ) {
200- if ( ! isProduction || ! hasResendKey ) {
200+ if ( ! isProduction && ! hasEmailService ) {
201201 setIsVerified ( true )
202202
203- const timeoutId = setTimeout ( ( ) => {
204- window . location . href = '/workspace'
205- } , 1000 )
203+ const handleRedirect = async ( ) => {
204+ try {
205+ await refetchSession ( )
206+ } catch ( error ) {
207+ logger . warn ( 'Failed to refetch session during dev verification skip:' , error )
208+ }
209+
210+ if ( isInviteFlow && redirectUrl ) {
211+ window . location . href = redirectUrl
212+ } else {
213+ router . push ( '/workspace' )
214+ }
215+ }
206216
207- return ( ) => clearTimeout ( timeoutId )
217+ handleRedirect ( )
208218 }
209219 }
210- } , [ isProduction , hasResendKey , router ] )
220+ } , [ isProduction , hasEmailService , router , isInviteFlow , redirectUrl ] )
211221
212222 return {
213223 otp,
@@ -217,7 +227,7 @@ export function useVerification({
217227 isInvalidOtp,
218228 errorMessage,
219229 isOtpComplete,
220- hasResendKey ,
230+ hasEmailService ,
221231 isProduction,
222232 verifyCode,
223233 resendCode,
0 commit comments