Is there a way to send OTP after email change?
Ok well I got it setup in hooks to something like...
if (ctx.path === '/verify-email') {
const payload = ctx?.query?.token
? (decodeJwt(ctx.query.token) as
| {
email: string;
updateTo: string;
iat: number;
exp: number;
}
| undefined)
: undefined;
if (payload) {
// Check if token has expired
if (payload.exp < Date.now() / 1000) {
// TODO: Add more elegant error handling
throw new Error('Token has expired');
} else {
await auth.api.sendVerificationOTP({
body: {
email: payload.updateTo,
type: 'email-verification'
}
});
}
}
} if (ctx.path === '/verify-email') {
const payload = ctx?.query?.token
? (decodeJwt(ctx.query.token) as
| {
email: string;
updateTo: string;
iat: number;
exp: number;
}
| undefined)
: undefined;
if (payload) {
// Check if token has expired
if (payload.exp < Date.now() / 1000) {
// TODO: Add more elegant error handling
throw new Error('Token has expired');
} else {
await auth.api.sendVerificationOTP({
body: {
email: payload.updateTo,
type: 'email-verification'
}
});
}
}
}