nuxt-supabase-team-auth
Version:
Drop-in Nuxt 3 module for team-based authentication with Supabase
39 lines (38 loc) • 1.19 kB
JavaScript
import { defineEventHandler, readBody, getHeader, createError } from "h3";
import { $fetch } from "ofetch";
import { useRuntimeConfig } from "#imports";
export default defineEventHandler(async (event) => {
const body = await readBody(event);
const authHeader = getHeader(event, "authorization");
if (!authHeader) {
throw createError({
statusCode: 401,
statusMessage: "Missing authorization header"
});
}
const supabaseUrl = useRuntimeConfig().supabaseUrl;
const edgeFunctionUrl = `${supabaseUrl}/functions/v1/accept-invite`;
try {
const response = await $fetch(edgeFunctionUrl, {
method: "POST",
headers: {
"Authorization": authHeader,
"Content-Type": "application/json"
},
body
});
return response;
} catch (error) {
console.error("Accept invite proxy error:", error);
console.error("Error details:", {
status: error.status,
statusCode: error.statusCode,
data: error.data,
message: error.message
});
throw createError({
statusCode: error.status || error.statusCode || 500,
statusMessage: error.message || "Failed to accept invite"
});
}
});