[Nuxt] Login flow with magic link
For some reason, I can't make the magic link work.
I have a nuxt 3 project with @nuxtjs/supabase module.
I run
supabase start && supabase functions serve
I have an edge function login
that does the following:
when I generate a magic link and open it on my nuxt 3 application, I don't get logged in automatically. This is what supposed to happen, right? user
from useSupabaseUser
remains null
.
Here is confirm.vue
:
I even added this to config.toml
:
40 Replies
What is this outputting?
console.log({ data, error });
and after initial signup:
if u want to take a look, I can set up a minimal reproduction repo
Also remember Nuxt did their own shell on top of Supabase if they have any special requirements for this process.
Nuxt x Supabase - Docs
Get Started - Nuxt x Supabase - Docs
@nuxtjs/supabase is a Nuxt module for first class integration with Supabase.
?
Please do, curious to take a look
Ouch, gotta go now, hopefully garry can help you out
Yes that is done by Nuxt not Supabase. Just pointing out that they Could have different process that Supabase docs, not that they do. I don't know I've never used it. I've seen though here there are differences.
well the official supabase docs use it too and link to a demo using it
which is outdated btw
GitHub
Update Nuxt 3 User Management example by Shooteger · Pull Request #...
Updating package versions, as well as .lock file. Adding .env-example file and set runtimeConfig with supabase key
I have read the CONTRIBUTING.md file.
YES
What kind of change does this PR introdu...
I checked this, but it did not help
This guy also had the same issue: https://github.com/orgs/supabase/discussions/20443
GitHub
Build a User Management App with Nuxt 3: Can't login with magic lin...
Improve documentation Link https://supabase.com/docs/guides/getting-started/tutorials/with-nuxt-3?database-method=dashboard Describe the problem // app.vue <script setup> const user = useSupa...
however his suggested fix did nothing for me sadly
man, it's been a rough start trying out supabase...
Nuxt I think uses cookies, supabase-js in Javascript plain does not. Supabase has its own cookie based server/browser setup called SSR.
But one would think their guide from the Nuxt site would work at least.
GitHub
GitHub - Revadike/nuxt3-supabase
Contribute to Revadike/nuxt3-supabase development by creating an account on GitHub.
^ try please
If this is a Nuxt specific issue you might add Nuxt to the title. As there are some Nuxt users here.
how does one login with a magic link token with supabase-js?
does it also automatically refresh session?
When you click the link it calls Supabase to confirm the user email and then redirects back to the browser. A user token and session info is provided (after a #) and that is extracted by the supabase client in a browser and then the session is valid and stored in local storage. From that point on it is refreshed before it expires.
Note the token can't be read from a server as it is after a # which is why I expect turning off SSR is required for Nuxt as it won't work server side.
makes sense
well I tried the manual method
with supabase-js
I tried both the hashed_token and otp token method (created by
supabase.auth.admin.generateLink
in the edge function), using supabase.auth.verifyOtp
in the client
for both it returns the code or email link is invalid or expired
this could be the underlying issue why
@nuxtjs/supabase
won't work for me
they probably try the same thing
but I still don't know why
here is my current nuxt config
Check the auth logs on your instanced to see if you get more than one /verify request. If it is called twice the link is no longer any good.
same thing when trying to use
setSession
on the client using the access_token and refresh_token returned by visiting the magic link:
Are you using the same instance to generate the link and verify it?
Your edge function is running on the instance that deployed it.
how can I check?
i only have 1 supabase project
Are you doing local dev?
yes
supabase start
nuxt dev
Your function might be running there and not on the real instance.
wdym
Log out your environment variables and check the function log.

If you are doing local dev then it has it's own instance running with its own jwt secret and keys.
If your function is on hosted supabase instance then your link is signed by it. If you run than then on your local instance that would generate the error you see, or visa versa.
ok, what .env values should I set to use my local instance?
change SUPABASE_KEY to use the local anon key maybe?
🎉 🎉 🎉 🎉

If you are doing functions serve then the function is running locally on your local instance. You would need your nuxt code to be using that local url and key.
Or you need to deploy the function on your hosted instance and run that.
i figured it out
API_URL as SUPABASE_URL and anon key AS SUPABASE_KEY
it makes sense, I just expected supabase would use my local instance by default or something
Your calls will use whatever URL/key you provide to createClient.
the nuxtjs library creates the client instance for me
so i had no idea
btw, session is stored in a cookie, not localStorage from what I can tell
Yes that is a Nuxt thing. It is a shell around Supabase-js and sends the local storage calls to a cookie handler I assume (like Supabase SSR does).
i read it indeed uses supabase ssr under the hood