MCPcopy Create free account
hub / github.com/akdeb/ElatoAI / authenticateUser

Function authenticateUser

server/deno/utils.ts:114–132  ·  view source on GitHub ↗
(
    supabaseClient: SupabaseClient,
    authToken: string,
)

Source from the content-addressed store, hash-verified

112export const isDev = Deno.env.get("DEV_MODE") === "True";
113
114export const authenticateUser = async (
115 supabaseClient: SupabaseClient,
116 authToken: string,
117): Promise<IUser> => {
118 try {
119 const jwtSecret = Deno.env.get("JWT_SECRET_KEY");
120
121 if (!jwtSecret) throw new Error("JWT_SECRET_KEY not configured");
122
123 const secretBytes = new TextEncoder().encode(jwtSecret);
124 const payload = await jose.jwtVerify(authToken, secretBytes);
125
126 const { payload: { email } } = payload;
127 const user = await getUserByEmail(supabaseClient, email as string);
128 return user;
129 } catch (error: any) {
130 throw new Error(error.message || "Failed to authenticate user");
131 }
132};
133
134/**
135 * Decrypts an encrypted secret with the same master encryption key.

Callers 1

main.tsFile · 0.90

Calls 2

getUserByEmailFunction · 0.90
encodeMethod · 0.45

Tested by

no test coverage detected