mirror of
https://github.com/stack-auth/stack.git
synced 2026-06-13 21:01:21 +08:00
* added supabase example * removed unused files * added jwt endpoint * supabase server action * removed unused * updated dependencies * reverted package changes * fixed bugs * added supabase docs * updated docs * updated pnpm lock
26 lines
573 B
TypeScript
26 lines
573 B
TypeScript
'use server';
|
|
|
|
import { stackServerApp } from "@/stack";
|
|
import * as jose from "jose";
|
|
|
|
/*
|
|
This is a server action that returns a Supabase JWT with the Stack Auth user ID
|
|
*/
|
|
export const getSupabaseJwt = async () => {
|
|
const user = await stackServerApp.getUser();
|
|
|
|
if (!user) {
|
|
return null;
|
|
}
|
|
|
|
const token = await new jose.SignJWT({
|
|
sub: user.id,
|
|
role: "authenticated",
|
|
})
|
|
.setProtectedHeader({ alg: "HS256" })
|
|
.setIssuedAt()
|
|
.setExpirationTime('1h')
|
|
.sign(new TextEncoder().encode(process.env.SUPABASE_JWT_SECRET));
|
|
|
|
return token;
|
|
}; |