nuxt-modules / supabase

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

Refresh token on server #356

Open franzwarning opened 6 months ago

franzwarning commented 6 months ago

Quick question -- I'm making api calls on the server which require the supabase access token. My question is: is the token automatically refreshed on the server? Or just the client? I had to add this in my middleware/auth to get it to work (note, just using useSupabaseSession()) wasn't actually refreshing the token.

export default defineNuxtRouteMiddleware(async (to, _from) => {
    const client = useSupabaseClient()

    const session = await client.auth.getSession()

    if (!session.data.session) {
        return navigateTo(
            Urls.SignIn({ redirectAfter: encodeURIComponent(to.fullPath) })
        )
    }
})
franzwarning commented 6 months ago

Could we potentially add an argument to useSupabaseSession which awaits on refresh token (if necessary)