How to Re-Authenticate Users with the Magic Client SDK

How to Re-Authenticate Users with the Magic Client SDK

A user's Magic SDK session persists up to 7 days by default, so re-authentication is usually friction-less.

Note: the session length is customizable by the developer through the Magic dashboard.

0. Prerequisite: Install Magic Client SDK​

1. Re-authenticate the user:

import { Magic } from 'magic-sdk'; const m = new Magic('API_KEY'); const email = 'example@magic.link'; if (await m.user.isLoggedIn()) { const didToken = await m.user.getIdToken(); // Do something with the DID token. // For instance, this could be a `fetch` call // to a protected backend endpoint. document.getElementById('your-access-token').innerHTML = didToken; } else { // Log in the user const user = await m.auth.loginWithMagicLink({ email }); }
How to Re-Authenticate Users with the Magic Client SDK