nuxt-modules / supabase

Supabase module for Nuxt.
https://supabase.nuxtjs.org
MIT License
706 stars 129 forks source link

auth client signOut() does nothing? #215

Closed stlbucket closed 1 year ago

stlbucket commented 1 year ago

https://supabase.nuxtjs.org/usage/composables/use-supabase-auth-client#signout

Everything else is working with my supabase auth client, but signOut does nothing. There is no call to supabase auth at all. No error is thrown.

<script setup>
const client = useSupabaseAuthClient()
</script>

<template>
  <UButton @click="client.auth.signOut()">Logout</UButton>
</template>

that is my code - almost exactly as in the link.

any idea why this is not working?

This was working for me previously. A new version of supabase-js seems to have released yesterday. Is it possible this has caused a problem?

I am using pnpm + turborepo

stlbucket commented 1 year ago

I was able to see this error. It occurs when I first login and return to the site thru OTP magic link. I am developing locally.

image
stlbucket commented 1 year ago

I have an Auth component on my page:

<template>
  <UCard class="card">
    <div v-if="!supUser" class="login">
      <UInput placeholder="Your Email address" v-model="email"></UInput>
      <UButton @click="handleLogin">Send Magic Link</UButton>
    </div>
    <div v-else class="card">
      <div class="menu-bar">
        <div class="text-sm"><NuxtLink to="/my-profile">{{ supUser.user_metadata.display_name }}</NuxtLink></div>
        <div>
          <UButton @click="handleLogout">Logout</UButton>
        </div>
        <div class="text-sm">{{ supUser.user_metadata.app_tenant_name }}</div>
      </div>
    </div>
  </UCard>
</template>

<script lang="ts" setup>
  const supUser = useSupabaseUser()
  const supabase = useSupabaseAuthClient()
  const email = ref('')

  const handleLogin = async () => {
    const { error } = await supabase.auth.signInWithOtp({
      email: email.value,
      options: {
        emailRedirectTo: 'http://localhost:3025/my-profile'
      }
    })
    if (error) {
      alert(error.message)
    }
    alert('Check your email inbox for the magic link!')
  }
  const handleLogout = async () => {
    navigateTo('/logout')
  }
</script>
stlbucket commented 1 year ago

logout.vue:

<script setup>
const client = useSupabaseAuthClient()
</script>

<template>
  <UButton @click="client.auth.signOut()">Logout</UButton>
</template>

i currently have this setup as i was trying to isolate the issue. I have also tried this with signOut being called in the Auth component handleLogout method.

CptJJ commented 1 year ago

I also am seeing this issue when using the latest version of gotrue-js: https://github.com/supabase/supabase-js/releases/tag/v2.31.0

Ive been having tons of issue with my production app over the last week, I think all realated to go true,

every so often after a user is logged in but leaves the tab open and comes back they will be signed out, and when they go to sign in, the js will just hang on the await client.auth.signIn() function, I was hoping that updating would fix this but seems to have introduced the issue your seeing

stlbucket commented 1 year ago

Wow. I removed all my docker containers and restarted supabase to see if that might help. Now, after local dev OTP signin, my entire site is unavailable!

It works - and can query my database as anon - before i sign in. But after... the site simply isn't there. The address looks like this:

http://localhost/auth/v1/verify?token=76a4301c295f115c43ff19711803557a77320b2cb81ace99892390a9&type=magiclink&redirect_to=http://localhost:3025/my-profile

but browser is unable to connect

j4w8n commented 1 year ago

Quite a few changes in those three minor releases

https://github.com/supabase/gotrue-js/compare/v2.43.1...v2.46.1

ra-jeev commented 1 year ago

Not only SignOut, even SignIn doesn't work many a times (I used signInWithPassword). It keeps on loading as the user call is not made after the token grant and session calls. But if you refresh the page, you get signed in.

If SignIn is successful, and you refresh the page, then SignOut doesn't work (that had a 100% occurrence rate 2-3 days back). Hopefully all this uncertainly of SignIn / SignOut will be resolved soon.

fdarkaou commented 1 year ago

For me SignIn works, it generates a OTP for users to log in. But after that, nothing else works - any custom API call to a table or SignOut.

Did you happen to figure out why?

stlbucket commented 1 year ago

https://github.com/supabase/supabase/issues/16100

I think it's related to this, which appears to be a bug.

I experienced this issue on a repository where I was experimenting with some toml settings and while converting a little app to a monorepo, so I think it's possible that I corrupted something. Other projects are working fine for me as of now.

It seems more people are experiencing this though.

https://github.com/nuxt-modules/supabase/issues/216

@fdarkaou - did you happen to be using nuxt?

silentworks commented 1 year ago

I've just tested this with the latest Nuxt Supabase and can't replicate the issue noted here. Can you upgrade to the latest and let me know if the issue still persists?

stlbucket commented 1 year ago

I've upgraded and tested everything. I think it is good.