Magic Link email validation and error handling

I've followed the docs on how to implement magic link, however i feel there is a few things missing from the example, email validation and error handling. Can someone please guide me in the right direction with the syntax and or structure of how to implement this?
const [email, setEmail] = useState("")

<Input // shadcn component
id="email"
type="email" // this doesnt help with validation because using onClick not submission
name="email"
placeholder="Enter email"
autoFocus
required
onChange={(e) => setEmail(e.target.value)} />

<Button onClick={async () => {
await authClient.signIn.magicLink({ // how can i add error handling? do i wrap in try-catch?
email: email,
callbackURL: "/dashboard"
})
}}>Submit</Button
const [email, setEmail] = useState("")

<Input // shadcn component
id="email"
type="email" // this doesnt help with validation because using onClick not submission
name="email"
placeholder="Enter email"
autoFocus
required
onChange={(e) => setEmail(e.target.value)} />

<Button onClick={async () => {
await authClient.signIn.magicLink({ // how can i add error handling? do i wrap in try-catch?
email: email,
callbackURL: "/dashboard"
})
}}>Submit</Button
Solution:
I figured out how to pull errors: const {error} = await authClient.signIn.magicLink({ and validation can be done before calling signIn.magicLink...
Jump to solution
1 Reply
Solution
rocketkittens
rocketkittens3mo ago
I figured out how to pull errors: const {error} = await authClient.signIn.magicLink({ and validation can be done before calling signIn.magicLink

Did you find this page helpful?