mirror of
https://github.com/stack-auth/stack.git
synced 2026-06-13 21:01:21 +08:00
Rebased onto dev after PR 1475 (cl/hexclave-pr1) was squash-merged. Squashes the original 46-commit branch (including PR1-duplicate commits that arrived via cherry-picks/merges) into a single commit containing only PR2's net delta over dev. Original PR 1481 head: 94872de407873a1cabd4085deb21b69afe8d7699 (kept locally at backup/cl-romantic-mendel-5a2c25-pre-rebase)
26 lines
571 B
TypeScript
26 lines
571 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 Hexclave 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;
|
|
}; |