Server error issue when deployed to Firebase App Hosting Backend #12585
-
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
I finally fixed the issue after more than 18 hours of debugging, I used Google Cloud Logging to check the logs in the console and I discovered the issues which is just I didn't set First I enabled Google Cloud Logging in the console and then I ran the following command locally, (Mac) while signed in to gcloud locally, to get a list of all the logs of my project, I ran it in the same directory as my project but I am not sure if it is going to work if ran outside of the directory: gcloud logging logs list and then I got a list of all the log names of my project including the stderr which is the one that holds the nextauth error, the output was like: projects/project-id/logs/cloudaudit.googleapis.com%2Factivity
projects/project-id/logs/cloudaudit.googleapis.com%2Fdata_access
projects/project-id/logs/cloudaudit.googleapis.com%2Fsystem_event
projects/project-id/logs/cloudbuild
projects/project-id/logs/run.googleapis.com%2Frequests
projects/project-id/logs/run.googleapis.com%2Fstderr # <---------- this is the one holding the nextjs server errors
projects/project-id/logs/run.googleapis.com%2Fstdout
projects/project-id/logs/run.googleapis.com%2Fvarlog%2Fsystem and then I ran the following command to read the stderr logs, and that is where I noticed the error gcloud logging read 'logName=projects/project-id/logs/run.googleapis.com%2Fstderr' --limit 10 --format json and then as part of the log outputed in json, I saw the error: ...
{
"insertId": "random-id",
"labels": {
"goog-managed-by": "firebase-app-hosting",
"instanceId": "a-very-long-random-id"
},
"logName": "projects/project-id/logs/run.googleapis.com%2Fstderr",
"receiveTimestamp": "YYYY-MM-DDT09:06:51.638426853Z",
"resource": {
"labels": {
"configuration_name": "app-hosting-project-name",
"location": "country-code-central1",
"project_id": "project-id",
"revision_name": "build-name",
"service_name": "app-hosting-project-name"
},
"type": "cloud_run_revision"
},
"textPayload": "\u001b[31m[auth][error]\u001b[0m UntrustedHost: Host must be trusted. URL was: https://customdomain.com/api/auth/session. Read more at https://errors.authjs.dev#untrustedhost",
"timestamp": "YYYY-MM-DDT09:06:51.333089Z"
},
... and going to import type { NextAuthConfig } from 'next-auth';
export const authConfig = {
pages: {
signIn: '/signin',
},
trustHost: true, // < -------------- this line
providers: [],
} satisfies NextAuthConfig; and then I pushed and it rebuilt it again and it worked out of the box |
Beta Was this translation helpful? Give feedback.
I finally fixed the issue after more than 18 hours of debugging, I used Google Cloud Logging to check the logs in the console and I discovered the issues which is just I didn't set
trustHost
option to true in the next-auth config and when I did it just worked fine, in case anyone faced the same issue this is how I did it,First I enabled Google Cloud Logging in the console and then I ran the following command locally, (Mac) while signed in to gcloud locally, to get a list of all the logs of my project, I ran it in the same directory as my project but I am not sure if it is going to work if ran outside of the directory:
and then I got a list of all the log names of…