The backend is configured with Node.js and the front end uses Vite.
We distributed what we were developing locally to Firebase Functions.
I thought there would be no problem because I used a Google Cloud Service account in the existing local area, but the API using Google Analytics alone causes 500 errors.
The following errors occur on the server terminal.
> Error during visitor stats fetch: Error: 7 PERMISSION_DENIED: Request had insufficient authentication scopes.
> at callErrorFromStatus (/Users/user/Documents/dev/works/project-backend/functions/node_modules/@grpc/grpc-js/build/src/call.js:31:19)
> at Object.onReceiveStatus (/Users/user/Documents/dev/works/project-backend/functions/node_modules/@grpc/grpc-js/build/src/client.js:193:76)
> at Object.onReceiveStatus (/Users/user/Documents/dev/works/project-backend/functions/node_modules/@grpc/grpc-js/build/src/client-interceptors.js:360:141)
> at Object.onReceiveStatus (/Users/user/Documents/dev/works/project-backend/functions/node_modules/@grpc/grpc-js/build/src/client-interceptors.js:323:181)
> at /Users/user/Documents/dev/works/project-backend/functions/node_modules/@grpc/grpc-js/build/src/resolving-call.js:129:78
> at process.processTicksAndRejections (node:internal/process/task_queues:77:11)
> for call at
> at ServiceClientImpl.makeUnaryRequest (/Users/user/Documents/dev/works/project-backend/functions/node_modules/@grpc/grpc-js/build/src/client.js:161:32)
> at ServiceClientImpl.<anonymous> (/Users/user/Documents/dev/works/project-backend/functions/node_modules/@grpc/grpc-js/build/src/make-client.js:105:19)
> at /Users/user/Documents/dev/works/project-backend/functions/node_modules/@google-analytics/data/build/src/v1beta/beta_analytics_data_client.js:233:29
> at /Users/user/Documents/dev/works/project-backend/functions/node_modules/google-gax/build/src/normalCalls/timeout.js:44:16
> at OngoingCallPromise.call (/Users/user/Documents/dev/works/project-backend/functions/node_modules/google-gax/build/src/call.js:67:27)
> at NormalApiCaller.call (/Users/user/Documents/dev/works/project-backend/functions/node_modules/google-gax/build/src/normalCalls/normalApiCaller.js:34:19)
> at /Users/user/Documents/dev/works/project-backend/functions/node_modules/google-gax/build/src/createApiCall.js:112:30
> at process.processTicksAndRejections (node:internal/process/task_queues:95:5) {
> code: 7,
> details: 'Request had insufficient authentication scopes.',
> metadata: Metadata {
> internalRepr: Map(4) {
> 'endpoint-load-metrics-bin' => [Array],
> 'grpc-server-stats-bin' => [Array],
> 'google.rpc.errorinfo-bin' => [Array],
> 'grpc-status-details-bin' => [Array]
> },
> options: {}
> },
> statusDetails: [
> ErrorInfo {
> metadata: [Object],
> reason: 'ACCESS_TOKEN_SCOPE_INSUFFICIENT',
> domain: 'googleapis.com'
> }
> ],
> reason: 'ACCESS_TOKEN_SCOPE_INSUFFICIENT',
> domain: 'googleapis.com',
> errorInfoMetadata: {
> method: 'google.analytics.data.v1beta.BetaAnalyticsData.RunReport',
> service: 'analyticsdata.googleapis.com'
> }
> }
When I developed it local, I didn’t have any rights issues, so I thought there would be no errors when I deployed it to Firebase Functions.
As you can see in the picture, only visor-stats (APIs using Google Analytics) are experiencing 500 errors.
I didn’t know the problem, so I added the authority.
I am using the service account and downloaded it in json format, and I entered the file path correctly in the .env file.
Is there a new permission setting that I need to do?
Of course, Google Analytics API and Google Analytics Data API are in use.
I’d appreciate it if you could help me. ㅠㅠ
I am conducting a local test with the command below.
firebase emulators:start --only functions