Authenticating with magic links
When a user of our application switches to the magic link form, enters an account email and presses Sign in with Magic Link, the server should create a secret link that is then sent via email to the user who wants to log in.
Now, I will show you how to generate such magic links, allowing us to authenticate users with it. We will start with a frontend-based solution, which will use the built-in email templates, then gradually move to a server-based solution including fully customizing those emails.
Sending magic links with signInWithOtp() on the frontend
Similar to signInWithPassword()
, in the supabase.auth
file, there is a signInWithOtp({email})
function that takes an email address and sends a magic link to it.
Note
A magic link is a link that contains a One Time Password (OTP), which can be used exactly one time to log in.
signInWithOtp
works the same way on frontend and backend – calling it will make a request to the GoTrue...