Skip to content

Commit 042973b

Browse files
committed
feat(ssr): extra logs for debugging
1 parent ecf2c3f commit 042973b

File tree

1 file changed

+41
-25
lines changed

1 file changed

+41
-25
lines changed

src/server/admin.ts

+41-25
Original file line numberDiff line numberDiff line change
@@ -33,22 +33,23 @@ export function getAdminApp(
3333
GOOGLE_APPLICATION_CREDENTIALS,
3434
} = process.env
3535

36+
log('debug', 'Detected environment variables', {
37+
FIREBASE_PROJECT_ID,
38+
FIREBASE_CLIENT_EMAIL,
39+
FIREBASE_PRIVATE_KEY: FIREBASE_PRIVATE_KEY && '****',
40+
FIREBASE_CONFIG,
41+
FUNCTION_NAME,
42+
GOOGLE_APPLICATION_CREDENTIALS,
43+
})
44+
3645
if (FIREBASE_CONFIG || FUNCTION_NAME) {
37-
log('debug', 'using FIREBASE_CONFIG env variable')
46+
// TODO: last time I tried this one fails on the server
47+
log('debug', `using FIREBASE_CONFIG env variable for ${FUNCTION_NAME}`)
3848
initializeApp()
3949
} else {
4050
let credential: FirebaseAdminCredential
41-
// This version should work in Firebase Functions and other providers while applicationDefault() only works on
42-
// Firebase deployments
43-
if (FIREBASE_PRIVATE_KEY) {
44-
log('debug', 'using FIREBASE_PRIVATE_KEY env variable')
45-
credential = cert({
46-
projectId: FIREBASE_PROJECT_ID,
47-
clientEmail: FIREBASE_CLIENT_EMAIL,
48-
// replace `\` and `n` character pairs w/ single `\n` character
49-
privateKey: FIREBASE_PRIVATE_KEY.replace(/\\n/g, '\n'),
50-
})
51-
} else if (process.env.GOOGLE_APPLICATION_CREDENTIALS) {
51+
52+
if (GOOGLE_APPLICATION_CREDENTIALS) {
5253
if (
5354
typeof GOOGLE_APPLICATION_CREDENTIALS === 'string' &&
5455
// ensure it's an object
@@ -69,22 +70,37 @@ export function getAdminApp(
6970
}
7071
credential = cert(certObject)
7172
} else {
72-
// automatically picks up the service account file path from the env variable
73-
log('debug', 'using applicationDefault()')
74-
credential = applicationDefault()
73+
log(
74+
'debug',
75+
'using GOOGLE_APPLICATION_CREDENTIALS env variable as a file path'
76+
)
77+
credential = cert(GOOGLE_APPLICATION_CREDENTIALS)
7578
}
79+
} else if (FIREBASE_PRIVATE_KEY) {
80+
// This version should work in Firebase Functions and other providers while applicationDefault() only works on
81+
// Firebase deployments
82+
log('debug', 'using FIREBASE_PRIVATE_KEY env variable')
83+
credential = cert({
84+
projectId: FIREBASE_PROJECT_ID,
85+
clientEmail: FIREBASE_CLIENT_EMAIL,
86+
// replace `\` and `n` character pairs w/ single `\n` character
87+
privateKey: FIREBASE_PRIVATE_KEY.replace(/\\n/g, '\n'),
88+
})
7689
} else {
77-
// No credentials were provided, this will fail so we throw an explicit error
78-
// TODO: add link to vuefire docs
79-
log(
80-
'warn',
81-
`\
82-
You must provide admin credentials during development. See https://firebase.google.com/docs/admin/setup#initialize-sdk for more information. It must be made available through GOOGLE_APPLICATION_CREDENTIALS env variable as a full resolved path or a JSON string.
83-
You can also set the FIREBASE_CLIENT_EMAIL, FIREBASE_PRIVATE_KEY and FIREBASE_PROJECT_ID env variables. Note this environment variable is automatically set on Firebase Cloud Functions.\
84-
`
85-
)
86-
throw new Error('admin-app/missing-credentials')
90+
// automatically picks up the service account file path from the env variable
91+
log('debug', 'using applicationDefault()')
92+
credential = applicationDefault()
8793
}
94+
// No credentials were provided, this will fail so we throw an explicit error
95+
// TODO: add link to vuefire docs
96+
// log(
97+
// 'warn',
98+
// `\
99+
// You must provide admin credentials during development. See https://firebase.google.com/docs/admin/setup#initialize-sdk for more information. It must be made available through GOOGLE_APPLICATION_CREDENTIALS env variable as a full resolved path or a JSON string.
100+
// You can also set the FIREBASE_CLIENT_EMAIL, FIREBASE_PRIVATE_KEY and FIREBASE_PROJECT_ID env variables. Note this environment variable is automatically set on Firebase Cloud Functions.\
101+
// `
102+
// )
103+
// throw new Error('admin-app/missing-credentials')
88104

89105
initializeApp({
90106
// TODO: is this really going to be used?

0 commit comments

Comments
 (0)