1- import { SourcebotLogo } from "@/app/components/sourcebotLogo" ;
1+ "use client"
2+
3+ import { InputOTPSeparator } from "@/components/ui/input-otp"
4+ import { InputOTPGroup } from "@/components/ui/input-otp"
5+ import { InputOTPSlot } from "@/components/ui/input-otp"
6+ import { InputOTP } from "@/components/ui/input-otp"
7+ import { Card , CardHeader , CardDescription , CardTitle , CardContent , CardFooter } from "@/components/ui/card"
8+ import { Button } from "@/components/ui/button"
9+ import { ArrowLeft } from "lucide-react"
10+ import { useRouter , useSearchParams } from "next/navigation"
11+ import { useCallback , useState } from "react"
12+ import VerificationFailed from "./verificationFailed"
13+ import { SourcebotLogo } from "@/app/components/sourcebotLogo"
14+ import useCaptureEvent from "@/hooks/useCaptureEvent"
215
316export default function VerifyPage ( ) {
17+ const [ value , setValue ] = useState ( "" )
18+ const searchParams = useSearchParams ( )
19+ const email = searchParams . get ( "email" )
20+ const router = useRouter ( )
21+ const captureEvent = useCaptureEvent ( ) ;
22+
23+ if ( ! email ) {
24+ captureEvent ( "wa_login_verify_page_no_email" , { } )
25+ return < VerificationFailed />
26+ }
27+
28+ const handleSubmit = useCallback ( async ( ) => {
29+ const url = new URL ( "/api/auth/callback/nodemailer" , window . location . origin )
30+ url . searchParams . set ( "token" , value )
31+ url . searchParams . set ( "email" , email )
32+ router . push ( url . toString ( ) )
33+ } , [ value ] )
34+
35+ const handleKeyDown = ( e : React . KeyboardEvent < HTMLInputElement > ) => {
36+ if ( e . key === 'Enter' && value . length === 6 ) {
37+ handleSubmit ( )
38+ }
39+ }
440
541 return (
6- < div className = "flex flex-col items-center p-12 h-screen" >
7- < SourcebotLogo
8- className = "mb-2 h-16"
9- size = "small"
10- />
11- < h1 className = "text-2xl font-bold mb-2" > Verify your email</ h1 >
12- < p className = "text-sm text-muted-foreground" >
13- { `We've sent a magic link to your email. Please check your inbox.` }
14- </ p >
42+ < div className = "min-h-screen flex flex-col items-center justify-center p-4 bg-gradient-to-b from-background to-muted/30" >
43+ < div className = "w-full max-w-md" >
44+ < div className = "flex justify-center mb-6" >
45+ < SourcebotLogo className = "h-16" size = "large" />
46+ </ div >
47+ < Card className = "w-full shadow-lg border-muted/40" >
48+ < CardHeader className = "space-y-1" >
49+ < CardTitle className = "text-2xl font-bold text-center" > Verify your email</ CardTitle >
50+ < CardDescription className = "text-center" >
51+ Enter the 6-digit code we sent to < span className = "font-semibold text-primary" > { email } </ span >
52+ </ CardDescription >
53+ </ CardHeader >
54+
55+ < CardContent >
56+ < form onSubmit = { ( e ) => {
57+ e . preventDefault ( )
58+ if ( value . length === 6 ) {
59+ handleSubmit ( )
60+ }
61+ } } className = "space-y-6" >
62+ < div className = "flex justify-center py-4" >
63+ < InputOTP maxLength = { 6 } value = { value } onChange = { setValue } onKeyDown = { handleKeyDown } className = "gap-2" >
64+ < InputOTPGroup >
65+ < InputOTPSlot index = { 0 } className = "rounded-md border-input" />
66+ < InputOTPSlot index = { 1 } className = "rounded-md border-input" />
67+ < InputOTPSlot index = { 2 } className = "rounded-md border-input" />
68+ </ InputOTPGroup >
69+ < InputOTPSeparator />
70+ < InputOTPGroup >
71+ < InputOTPSlot index = { 3 } className = "rounded-md border-input" />
72+ < InputOTPSlot index = { 4 } className = "rounded-md border-input" />
73+ < InputOTPSlot index = { 5 } className = "rounded-md border-input" />
74+ </ InputOTPGroup >
75+ </ InputOTP >
76+ </ div >
77+ </ form >
78+ </ CardContent >
79+
80+ < CardFooter className = "flex flex-col space-y-4 pt-0" >
81+ < Button variant = "ghost" className = "w-full text-sm" size = "sm" onClick = { ( ) => window . history . back ( ) } >
82+ < ArrowLeft className = "mr-2 h-4 w-4" />
83+ Back to login
84+ </ Button >
85+ </ CardFooter >
86+ </ Card >
87+ < div className = "mt-8 text-center text-sm text-muted-foreground" >
88+ < p >
89+ Having trouble?{ " " }
90+ < a href = "mailto:team@sourcebot.dev" className = "text-primary hover:underline" >
91+ Contact support
92+ </ a >
93+ </ p >
94+ </ div >
95+ </ div >
1596 </ div >
1697 )
17- }
98+ }
99+
0 commit comments