Update Login
- Note that the below code can't be used to change providers, so if a user uses Google to login they can only change to another Google email. You must verify they are changing to a Google managed email before proceeding. One option is to check the
user.providerIds
array beforehand if you utilize thesaveUserData
method of this library.
svelte
<script lang="ts">import { verifyBeforeUpdateEmail, getAuth } from 'firebase/auth';</script><button type="button" on:click={() => {const newEmail = prompt('Whats the new email?');if (newEmail) {const auth = getAuth();const user = auth.currentUser;verifyBeforeUpdateEmail(user, newEmail, { url: 'https://sveltefirets.vercel.app/demo/account' });}}}>Update Email</button>
{#if $user}
{:else}
You must first sign in to try it:
saveUserData(e.detail)} />
{/if}
- See verifyBeforeUpdateEmail docs to learn about the possible errors that you should be catching.
- See https://firebase.google.com/docs/auth/web/account-linking to learn how to link accounts (add a new sign in method instead of change the email for a particular one)