Create type-safe Supabase clients with Supabase Third-Party Auth. So far the configuration mainly supports the Firebase Auth integration.
- TypeScript support with full type inference
- Configurable auth methods (Firebase Auth, JWT, Access Token)
- Database schema type safety
# bun
bun add @zac/supabase-authparty-js
# pnpm
pnpm add @zac/supabase-authparty-js
# npm
npm install @zac/supabase-authparty-js
- Generate your Supabase types:
supabase gen types typescript --local > types.d.ts
- Create and use the client:
You MUST pass your
Database
type tocreateFirebaseAuthSupabaseClient
import { createFirebaseAuthSupabaseClient } from '@zac/supabase-authparty-js';
import { Database } from './types'; // your generated types
import { getAuth } from 'firebase/auth';
// Firebase Auth client
const createClient = createFirebaseAuthSupabaseClient<Database>({
auth: getAuth()
}, {
supabaseUrl: process.env.SUPABASE_URL!,
supabaseAnonKey: process.env.SUPABASE_ANON_KEY!
});
// Or with JWT token
const createClient = createFirebaseAuthSupabaseClient<Database>({
jwtToken: await getAuth().currentUser?.getIdToken()
}, {
supabaseUrl: process.env.SUPABASE_URL!,
supabaseAnonKey: process.env.SUPABASE_ANON_KEY!
});
// Use client with full type inference
const supabase = createClient('public'); // or your schema name
const { data } = await supabase
.from('your_table')
.select('*');
// data will be fully typed based on your schema
- User signs in with Firebase Auth
- Firebase generates JWT token
- Token passed to Supabase for authentication
- Supabase validates token against Firebase public keys
- Access granted to authorized resources
Enable Firebase Auth in Supabase:
- Go to Authentication > Providers
- Enable Firebase Authentication
- Add Firebase project public keys
- Configure JWT claim mappings
type CreateFirebaseAuthClient = <DB extends Database = Database>(
props: (
| { auth: FirebaseAuth; accessToken?: AccessToken<DB>; jwtToken?: string }
| { auth?: FirebaseAuth; accessToken: AccessToken<DB>; jwtToken?: string }
| { auth?: FirebaseAuth; accessToken?: AccessToken<DB>; jwtToken: string }
),
env: { supabaseUrl: string; supabaseAnonKey: string }
) => <D extends DB = DB, S extends string & keyof DB = "public">(schemaName?: S) => SupabaseClient<D, S, D[S] extends GenericSchema ? D[S] : any>;
MIT
PRs welcome!