UNPKG

nuxt-supabase-team-auth

Version:

Drop-in Nuxt 3 module for team-based authentication with Supabase

40 lines (39 loc) 1.23 kB
import { defineEventHandler, readBody, createError } from "h3"; import { $fetch } from "ofetch"; import { useRuntimeConfig } from "#imports"; export default defineEventHandler(async (event) => { const body = await readBody(event); const config = useRuntimeConfig(); const supabaseUrl = config.public.supabase.url; const serviceKey = config.supabaseServiceKey; if (!serviceKey) { throw createError({ statusCode: 500, statusMessage: "Missing Supabase service key configuration" }); } const transformedBody = { email: body.email, password: body.password, team_name: body.teamName // Convert camelCase to snake_case }; const edgeFunctionUrl = `${supabaseUrl}/functions/v1/create-team-and-owner`; try { const response = await $fetch(edgeFunctionUrl, { method: "POST", headers: { "Content-Type": "application/json", "Authorization": `Bearer ${serviceKey}` }, body: transformedBody }); return response; } catch (error) { console.error("Signup with team proxy error:", error); throw createError({ statusCode: error.status || 500, statusMessage: error.message || "Failed to signup with team" }); } });