(
supabaseClient: SupabaseClient,
authToken: string,
)
| 112 | export const isDev = Deno.env.get("DEV_MODE") === "True"; |
| 113 | |
| 114 | export 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. |
no test coverage detected