supabase: 1.0.1 version breaks app and redirects to /login automatically when not specified in nuxt.config

@nuxtjs/supabase: 1.0.1 nuxt: 3.6.5

I am asking this because I know there will be people who didn’t read the release notes and wonder why their app redirects to /login.

redirect option is enable by default, follow this guide to update your app

If not explicitly set in nuxt.config.ts, nuxt supabase overrides the whole middleware and nuxt, and redirects to /login when not logged it. For example if not set like this, redirect is /login by default.

  supabase: {
    redirectOptions: {
      login: "/signIn",
    },
  },

Nuxt already has a middleware for this.

export default defineNuxtRouteMiddleware((to, _from) => {
  const user = useSupabaseUser();

  if (!user.value) {
    return navigateTo("/signIn");
  }
});

This would be inconvenient for the people who are not using nuxt auth as well. What is the reason to add a redirect that just overrides everything? Why is it enabled by default? @larbish

About this issue

  • Original URL
  • State: closed
  • Created a year ago
  • Reactions: 1
  • Comments: 21 (8 by maintainers)

Most upvoted comments

@1bye The redirect you are experiencing is performed by Supabase, it’s the authentication callback. Supabase does require fully qualified addresses, since it doesn’t know your app and routes. Change you code to use the full redirect URL in the function call, and the same full URL in the Supabase settings:

// Current code of auth
const signInGithub = async () => {
  const { error } = await client.auth.signInWithOAuth({
    provider: 'github',
    options: {
      redirectTo: 'https://localhost:3000/confirm',
    },
  })
  ...
} 

I successfully solved my issue by making the following changes: I replaced redirectTo: '/confirm', with the fullpath URL and performed a nuxi cleanup. Thanks @Aietes @larbish

I just tested the module playground on Firefox, and reloading the page does not redirect when logged in. In a clean setup I can’t reproduce this bug.

In your project where this occurs, are you still using your own middleware? Do you use the module with redirect: true? If the module middleware is used, the only reason to get forwarded to the login page is when the session didn’t get initialized properly. This could point to an issue with the /confirm page, where the session is created.

To determine the cause of the issue, can you provide a minimal minimal reproduction using one of the starter templates?

👉 https://stackblitz.com/github/nuxt/starter/tree/v3-stackblitz 👉 https://codesandbox.io/s/github/nuxt/starter/v3-codesandbox

@larbish Thanks for the reply. I can’t say I like it especially because not everyone is using supa auth. I don’t think any plug&play needed. We can do much more with nuxt middleware. After all, this is not a supaAuth library, it is a supabase library. Well we will see what happens though. Thanks for maintaining the lib!

Btw, have you tested this on Firefox?

With the below configs, on Chrome it works as expected but on Firefox, it redirects to /signIn even after signing in.

  supabase: {
    redirectOptions: {
      // If not specified, the default is login, so it will break the nuxt middleware auth flow
      login: "/signIn",
      callback: "/confirm",
      exclude: ["/unprotected", "/public/*"],
    },
  },

Also just for clarification, does this exclude all? So as to disable the default configs? Just in case for anyone who don’t use supa auth exclude: ["/*"],

I’m currently using middleware for validation, which is why I disabled the redirect feature. However, I still require the callback field for OAuth. Do you have any idea?