Skip to content

Breaking changes: OAuth session token deleted from Cookies on page refresh after updating to 2.47.6 #1334

Closed
@tzhf

Description

@tzhf

Bug report

  • I confirm this is a bug with Supabase, not with my own application.
  • I confirm I have searched the Docs, GitHub Discussions, and Discord.

Describe the bug

When using @supabase/supabase-js with Twitch as an OAuth provider, the auth-token is saved to localStorage upon redirection, but is immediately removed after a page refresh. This issue occurs after upgrading @supabase/supabase-js from 2.47.5 to 2.47.6 : #1334 (comment).
So i guess the culprit is here : https://github.com/supabase/auth-js/releases/tag/v2.67.0

After twitch login redirection, we get a session, which is stored in localStorage. At this point it's the expected behaviour.
But after a single page refresh, or a route redirection, the token is deleted from localStorage, the user is not authenticated, and the session does not persist. This behavior breaks the login flow, which worked correctly in previous versions.

To Reproduce

Steps to reproduce the behavior, please provide code snippets or a repository:

This works with 2.47.5 but not with 2.47.6:

useSupabase.ts composable :

import { createClient } from '@supabase/supabase-js'

export const useSupabase = () => {
  const config = useRuntimeConfig()
  return createClient(config.public.SUPABASE_URL, config.public.SUPABASE_KEY)
}

/pages/auth/redirect.vue :

const client = useSupabase()

onMounted(async () => {
  const { data: session, error } = await client.auth.getSession()
  if (session) {
    // Here we have a session, and the auth-token is stored in localStorage, it redirects successfully
    console.log('Session:', session) 
    return navigateTo(`/a_vue_page.vue`)
  } else {
    console.error('Session error:', error)
  }
}

/pages/a_vue_page.vue :

const client = useSupabase()
const getSession = await client.auth.getSession()
// The session is null, and the auth-token in localStorage has been deleted
console.log(getSession )

const handleTwitchLogin = () => {
  client.auth.signInWithOAuth({
    provider: 'twitch',
    options: { redirectTo: `${config.public.BASE_URL}/auth/redirect` },
  })
}

Expected behavior

After redirection, the session token should remain in localStorage and the user should stay authenticated.

System information

  • Nuxt: 3.13.2
  • Supabase-js: 2.47.5 & 2.47.6
  • Node.js: 18.20.4

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions