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 the saveUserData 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}
Edit page in GitHub