question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Auth not set on server side with link (magic link) login

See original GitHub issue

Version

@nuxtjs/supabase: v0.1.9 nuxt: v3.0.0-rc.1

Steps to reproduce

Set up a login form using the just the email to receive a magic link

const { session, error } = await client.auth.signIn({ email: email.value })

Use a middleware like this

export default defineNuxtRouteMiddleware((to) => {
  const user = useSupabaseUser()
  if (!(user.value))
    return navigateTo({ name: 'login', query: { redirect: to.path } })
})

What is Expected?

The user should be set on the server side.

What is actually happening?

The token on the server side plugin is null:

export default defineNuxtPlugin(async () => {
  const user = useSupabaseUser();
  const client = useSupabaseClient();
  const token = useSupabaseToken();
  if (!token.value) {
    return;
  }
  const { user: supabaseUser, error } = await client.auth.api.getUser(token.value);
  user.value = error ? null : supabaseUser;
});

Therefore the middleware redirects the user to the login and the user only becomes available after the middleware has run, leaving the user on the login page. A fix would involve watching the user, but thats still leads to the login page shortly showing up before the user is redirected again.

This issue is linked to #28 but singles out the ssr issue when using magic links

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:6

github_iconTop GitHub Comments

2reactions
larbishcommented, May 9, 2022

Hey @nosizejosh, that’s a way I found to avoid the display of the login form highlited by @mwohlan. That was just a proposition.

0reactions
nosizejoshcommented, May 17, 2022

Thank you @larbish

Read more comments on GitHub >

github_iconTop Results From Across the Web

Auth not set on server side with link (magic link) login · Issue #32
middleware has run, leaving the user on the login page. A fix would involve watching the user, but thats still leads to the...
Read more >
Frequently Asked Questions - Documentation - Magic.link
#General. #Can the magic link redirect to a specific URL? Yes! When calling the loginWithMagicLink sdk method you can pass in an optional...
Read more >
Is passwordless magic link only intended for client-side ...
Hello everybody,. I currently have a React app that uses Auth0's magic link authentication method using 'auth0-js'.
Read more >
How to implement Magic Link Authentication with Next.js and ...
This article will cover magic-link authentication basics using Next.js and Altogic, a backend-as-a-service platform using its client library ...
Read more >
How to implement Magic Link Authentication with Next.js and ...
For that authentication method, the primary condition is that the link needs to be safe and can not be able to manipulated from...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found