nuxt-supabase-team-auth
Version:
Drop-in Nuxt 3 module for team-based authentication with Supabase
22 lines (21 loc) • 769 B
JavaScript
import { useNuxtApp, useState } from "#app";
export const useSupabaseClient = () => {
const nuxtApp = useNuxtApp();
if (!nuxtApp.$supabase) {
throw new Error(
"Supabase not found in Nuxt app. Make sure @nuxtjs/supabase is properly configured in your nuxt.config.ts modules array and that NUXT_PUBLIC_SUPABASE_URL and NUXT_PUBLIC_SUPABASE_ANON_KEY are set."
);
}
if (!nuxtApp.$supabase.client) {
throw new Error(
"Supabase client not found. The @nuxtjs/supabase module may not be properly initialized."
);
}
return nuxtApp.$supabase.client;
};
export const useSupabaseSession = () => {
return useState("supabase_session", () => null);
};
export const useSupabaseUser = () => {
return useState("supabase_user", () => null);
};