MCPcopy Index your code
hub / github.com/simstudioai/sim / verifyCode

Function verifyCode

apps/sim/app/(auth)/verify/use-verification.ts:103–167  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

101 const isOtpComplete = otp.length === 6
102
103 async function verifyCode() {
104 if (!isOtpComplete || !email) return
105
106 setStatus('verifying')
107 setErrorMessage('')
108
109 try {
110 const normalizedEmail = normalizeEmail(email)
111 const response = await client.emailOtp.verifyEmail({
112 email: normalizedEmail,
113 otp,
114 })
115
116 if (response && !response.error) {
117 setStatus('verified')
118
119 try {
120 await refetchSession()
121 } catch (e) {
122 logger.warn('Failed to refetch session after verification', e)
123 }
124
125 if (typeof window !== 'undefined') {
126 sessionStorage.removeItem('verificationEmail')
127
128 if (isInviteFlow) {
129 sessionStorage.removeItem('inviteRedirectUrl')
130 sessionStorage.removeItem('isInviteFlow')
131 }
132 }
133
134 setTimeout(() => {
135 if (isInviteFlow && redirectUrl) {
136 window.location.href = redirectUrl
137 } else {
138 window.location.href = '/workspace'
139 }
140 }, 1000)
141 } else {
142 logger.info('Setting invalid OTP state - API error response')
143 const message = 'Invalid verification code. Please check and try again.'
144 setStatus('error')
145 setErrorMessage(message)
146 logger.info('Error state after API error:', { errorMessage: message })
147 setOtp('')
148 }
149 } catch (error: any) {
150 let message = 'Verification failed. Please check your code and try again.'
151
152 if (error.message?.includes('expired')) {
153 message = 'The verification code has expired. Please request a new one.'
154 } else if (error.message?.includes('invalid')) {
155 logger.info('Setting invalid OTP state - caught error')
156 message = 'Invalid verification code. Please check and try again.'
157 } else if (error.message?.includes('attempts')) {
158 message = 'Too many failed attempts. Please request a new code.'
159 }
160

Callers 1

useVerificationFunction · 0.70

Calls 4

normalizeEmailFunction · 0.90
removeItemMethod · 0.80
infoMethod · 0.80
warnMethod · 0.65

Tested by

no test coverage detected