|
Hi! I'm trying to update the user's password using However, I'm unsure how to verify the OTP correctly afterward. I've tried this: await supabase.auth.verifyOtp({
email,
token, // the 6-digit code
type: 'email' // also tried 'recovery' and 'magiclink'
});But it always returns ❗ My questions:
Any working example or documentation link would be super helpful. Thank you! 🙏 |
Answered by
vinumzz
Apr 21, 2025
Replies: 5 comments 1 reply
|
More information about my environment: Tech-Stack of my Nuxt (Type Script) project:Minimal reproduction:<script setup lang="ts">
const supabase = useSupabaseClient();
const user = useSupabaseUser();
const form = ref({ newPassword: '', confirmPassword: '', otp: '' });
const showOtp = ref(false);
const submit = async (isReauthDone = false) => {
const { newPassword, confirmPassword } = form.value;
if (newPassword !== confirmPassword) {
alert('Passwords do not match');
return;
}
const { error } = await supabase.auth.updateUser({ password: newPassword });
if (error?.code === 'reauthentication_needed' && !isReauthDone) {
await supabase.auth.reauthenticate();
showOtp.value = true;
return;
}
if (error) {
console.error(error);
alert('Update failed');
return;
}
alert('Password updated!');
};
const verifyOtp = async () => {
const { error } = await supabase.auth.verifyOtp({
email: user.value?.email,
token: form.value.otp,
type: 'email', // tried "recovery" and others too
});
if (error) {
console.error('OTP Error:', error);
alert('OTP invalid or expired');
return;
}
// Optional: try refreshing session?
await supabase.auth.refreshSession();
await submit(true);
};
</script>
<template>
<div class="p-8 text-white">
<h1 class="text-xl font-bold">Update Password</h1>
<input v-model="form.newPassword" placeholder="New password" type="password" class="block mt-4 p-2 bg-neutral-800 w-full rounded" />
<input v-model="form.confirmPassword" placeholder="Confirm password" type="password" class="block mt-2 p-2 bg-neutral-800 w-full rounded" />
<button @click="submit()" class="mt-4 bg-primary-500 text-sm px-4 py-2 rounded">Update</button>
<div v-if="showOtp" class="mt-6 bg-white/5 p-4 rounded">
<p class="text-sm mb-2">Enter OTP sent to your email:</p>
<input v-model="form.otp" maxlength="6" class="block w-full p-2 bg-neutral-800 rounded" />
<button @click="verifyOtp" class="mt-2 bg-primary-500 text-sm px-4 py-2 rounded">Verify & Continue</button>
</div>
</div>
</template> |
0 replies
|
I am facing the same issue |
0 replies
|
mw too i am facing the same issue |
0 replies
|
After sending the OTP with supabase.auth.reauthenticate you need to update the password like this: Hope this helps :) |
1 reply
Answer selected by
nicokempe
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@nicokempe @ssunil3232 @chrhi
After sending the OTP with supabase.auth.reauthenticate you need to update the password like this:
Hope this helps :)