From 4ed93274def83df5d7afbeaba7a1e635f488a0a7 Mon Sep 17 00:00:00 2001 From: fwaszkiewicz Date: Tue, 25 Nov 2025 13:32:05 +0100 Subject: [PATCH 1/2] Provide google api credentials as path to json file in .env --- server/api/google-wallet.ts | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/server/api/google-wallet.ts b/server/api/google-wallet.ts index e086294..8d71b2a 100644 --- a/server/api/google-wallet.ts +++ b/server/api/google-wallet.ts @@ -1,3 +1,5 @@ +import { readFileSync } from 'fs'; + import { GoogleAuth } from 'google-auth-library'; import { defineEventHandler, readBody } from 'h3'; import jwt from 'jsonwebtoken'; @@ -8,7 +10,13 @@ const classId = `${issuerId}.codelab_class`; const init = () => { const config = useRuntimeConfig(); - const credentials = config.googleApplicationCredentialsJson; + const credentialsPath = config.googleApplicationCredentialsJson; + + if (typeof credentialsPath !== 'string' || !credentialsPath) + throw new Error('Missing Google Application Credentials path'); + + const credentialsFile = readFileSync(credentialsPath, 'utf-8'); + const credentials = JSON.parse(credentialsFile); if (typeof credentials !== 'object') throw new Error('Invalid Google Application Credentials'); -- GitLab From c6030d54b30ea3889f12915eaed6393fd803fe47 Mon Sep 17 00:00:00 2001 From: fwaszkiewicz Date: Tue, 25 Nov 2025 13:57:06 +0100 Subject: [PATCH 2/2] Use $fetch istead of fetch making a direct call to the Nuxt server --- src/components/wallet/AddToGoogleWallet.vue | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/src/components/wallet/AddToGoogleWallet.vue b/src/components/wallet/AddToGoogleWallet.vue index 44355b5..efcd80c 100644 --- a/src/components/wallet/AddToGoogleWallet.vue +++ b/src/components/wallet/AddToGoogleWallet.vue @@ -16,22 +16,19 @@ const addToGoogleWallet = async () => { try { const { operationalKey, name } = await tokensStore.getCurrentUserMetadata(); const baseUrl = window.location.origin; - const res = await fetch('/api/google-wallet', { + const data = await $fetch<{ url?: string; error?: string; message?: string }>('/api/google-wallet', { method: 'POST', - - headers: { 'Content-Type': 'application/json' }, - body: JSON.stringify({ + body: { operationalPublicKey: operationalKey, displayName: name || 'User', baseUrl - }) + } }); - const data = await res.text(); - const parsed = JSON.parse(data); - if (parsed.url && !parsed.error) - window.open(parsed.url, '_blank'); + + if (data.url && !data.error) + window.open(data.url, '_blank'); else - toastError('Failed to generate Google Wallet pass', new Error(parsed.message || data, { cause: parsed })); + toastError('Failed to generate Google Wallet pass', new Error(data.message || JSON.stringify(data), { cause: data })); } catch (error) { toastError('Error generating Google Wallet pass', error); } finally { -- GitLab