Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The module doesn't recognize supabase.clientOptions.auth.flowType key #449

Open
aideremir opened this issue Jan 14, 2025 · 6 comments
Open
Labels
bug Something isn't working

Comments

@aideremir
Copy link

Version

@nuxtjs/supabase: 1.4.2
nuxt: 3.14.159

Steps to reproduce

nuxt.config.ts

 supabase: {
    url: process.env.SUPABASE_URL,
    key: process.env.SUPABASE_ANON_KEY,
    cookieName: 'mycookiename',
    redirect: false,
    clientOptions: {
      auth: {
        flowType: 'implicit',
      },
    },
  },

What is Expected?

The application should use the supabase auth implicit flowType

What is actually happening?

The application uses the supabase auth PKCE flowType

can be checked by outputting
useNuxtApp().$supabase

@aideremir aideremir added the bug Something isn't working label Jan 14, 2025
@th1m0
Copy link
Contributor

th1m0 commented Jan 14, 2025

It seems like the @supabase/ssr module always overwrites to use pkce see: createBrowserClient(client side) and createServerClient(SSR)

@aideremir
Copy link
Author

It seems like the @supabase/ssr module always overwrites to use pkce see: createBrowserClient(client side) and createServerClient(SSR)

@th1m0 thanks for pointing out. Are there any ideas about the purpose of overwriting?

@jlemonz
Copy link

jlemonz commented Jan 20, 2025

I also had problems with this. I think the docs of supabase nuxt should be updated. And give examples that work. I now use the other flow but lot of trial and error.

@Shooteger
Copy link

I also had problems with this. I think the docs of supabase nuxt should be updated. And give examples that work. I now use the other flow but lot of trial and error.

Hello, could you maybe share some resources/docs or code, how you got it running with the implicit flow? Thanks in advance. I am currently stuck with the issue for some time now.

@jlemonz
Copy link

jlemonz commented Jan 22, 2025

I also had problems with this. I think the docs of supabase nuxt should be updated. And give examples that work. I now use the other flow but lot of trial and error.

Hello, could you maybe share some resources/docs or code, how you got it running with the implicit flow? Thanks in advance. I am currently stuck with the issue for some time now.

You cant use implicit flow. What i do i generate a magiclink and use your own domain. Do not use supabase url because this will be flagged by outlook as spam. Is another issue posted somewhere about this. So generate the link and from the body get the tokenhash. Then generate your own email with service like mailersend. And set the to url with the tokenhash with a middleware that will verify the otp. Hope this helps. Here is also a blog with more info. Feel free to ask more help. https://catjam.fi/articles/supabase-generatelink-fix

@Shooteger
Copy link

Okay, if anyone encounters the same issue. I solved it currently by creating a second supabase instance with the "supabase-js" package and initialize a new client in a plugin. Be careful, it's very important you set a specific storageKey!

Here an example:

const costumeSupabase = createClient(config.public.SUPABASE_URL, config.public.SUPABASE_KEY, {
        auth: {
            flowType: 'implicit',
            storageKey: 'change_password_via_link', // Custom storage key
        },
});

With this I was able to create a supabase instance which uses the implicit flow. I used this instance then in my password reset component:

const { $costumeSupabase } = useNuxtApp();

Now I could finally verify my OTP code from the supabase link in different browsers / sessions:

const { error: verifyError } = await $costumeSupabase.auth.verifyOtp({
      email,
      token,
      type: 'recovery'
});

Then update the user password:

const { error: updateError } = await $costumeSupabase.auth.updateUser({
      password: state.newPassword
});

To keep it clean, after a successful password reset, I removed the local storage with the "change_password_via_link" key.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants