From fa1064daacc243b8401ad2a2b62c89d406b82453 Mon Sep 17 00:00:00 2001 From: dwindown Date: Tue, 23 Dec 2025 11:04:40 +0700 Subject: [PATCH] Fix JWT signing for Google Calendar authentication MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Change from jwt.sign() to SignJWT class - Use proper jose library SignJWT API for Deno - Fix 'Cannot read properties of undefined' error 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Sonnet 4.5 --- .../create-google-meet-event/index.ts | 28 ++++++------------- 1 file changed, 8 insertions(+), 20 deletions(-) diff --git a/supabase/functions/create-google-meet-event/index.ts b/supabase/functions/create-google-meet-event/index.ts index 37dcfd0..82fd072 100644 --- a/supabase/functions/create-google-meet-event/index.ts +++ b/supabase/functions/create-google-meet-event/index.ts @@ -30,33 +30,21 @@ interface CreateMeetRequest { // Function to create JWT and get access token async function getGoogleAccessToken(serviceAccount: GoogleServiceAccount): Promise { try { - // Import JWT library - const { jwt } = await import("https://deno.land/x/jose@v4.15.1/index.ts"); - - // Create JWT header and payload - const header = { - alg: "RS256", - typ: "JWT", - kid: serviceAccount.private_key_id, - }; + // Import JWT sign function from jose + const { SignJWT } = await import("https://deno.land/x/jose@v4.15.1/index.ts"); const now = Math.floor(Date.now() / 1000); - const payload = { + + // Create and sign JWT + const token = await new SignJWT({ iss: serviceAccount.client_email, scope: "https://www.googleapis.com/auth/calendar", aud: serviceAccount.token_uri, exp: now + 3600, iat: now, - }; - - // Import key - const privateKey = serviceAccount.private_key; - - // Sign JWT - const token = await jwt.sign(payload, privateKey, { - algorithm: 'RS256', - header: header, - }); + }) + .setProtectedHeader({ alg: 'RS256', kid: serviceAccount.private_key_id }) + .sign(serviceAccount.private_key); // Exchange JWT for access token const response = await fetch(serviceAccount.token_uri, {