Skip to main content

Verify email address

During the passkey registration process, Passlock can also verify mailbox ownership by sending a verification link or 6 digit code. For this tutorial we'll email the user a code:

register.ts
const result = passlock.registerPasskey({ 
...
verifyEmail: { method: 'code' }
})

You'll now need to prompt the user to check their emails and enter the code, which you verify:

verify.ts
const code = ... // grab code from a form etc
const result = await passlock.verifyEmailCode({ code })

if (PasslockError.isError(result)) {
// handle error
} else {
// should be an updated Principal
console.log(result)
}

Assuming the verifyEmailCode call was successful you'll receive an updated Principal:

output
{
"token": "2arafoq-8coasjl-qx4jz3x",
"user": {
...
"emailVerified": true
}
}
tip

Email code verification takes place in your frontend. You will receive an updated Principal with a new token. You can send this token to your backend for verification. The reason for doing it this way is because we may need to re-authenticate the user during the verification process. Please see the verify email ownership howto for more information.