Skip to content

Commit 79e3604

Browse files
committed
fix: move logging utils within runtime
1 parent 500b37e commit 79e3604

File tree

8 files changed

+38
-34
lines changed

8 files changed

+38
-34
lines changed

packages/nuxt/src/logging.ts

Lines changed: 0 additions & 21 deletions
This file was deleted.

packages/nuxt/src/module.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import type {
1919
import { markRaw } from 'vue'
2020
import type { NuxtVueFireAppCheckOptions } from './runtime/app-check'
2121
import { addMissingAlias } from './firebaseAliases'
22-
import { log } from './logging'
22+
import { log } from './runtime/logging'
2323

2424
export interface VueFireNuxtModuleOptions {
2525
/**

packages/nuxt/src/runtime/admin/plugin-auth-user.server.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { getCookie } from 'h3'
55
// FirebaseError is an interface here but is a class in firebase/app
66
import type { FirebaseError } from 'firebase-admin'
77
import { AUTH_COOKIE_NAME } from '../auth/api.session'
8-
import { log } from '../../logging'
8+
import { log } from '../logging'
99
import { defineNuxtPlugin, useRequestEvent } from '#app'
1010

1111
/**

packages/nuxt/src/runtime/admin/plugin.server.ts

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import {
77
// renamed because there seems to be a global Credential type in vscode
88
Credential as FirebaseAdminCredential,
99
} from 'firebase-admin/app'
10-
import { log } from '../../logging'
10+
import { log } from '../logging'
1111
import { defineNuxtPlugin, useAppConfig } from '#app'
1212

1313
export default defineNuxtPlugin((nuxtApp) => {
@@ -43,17 +43,18 @@ export default defineNuxtPlugin((nuxtApp) => {
4343
privateKey: FIREBASE_PRIVATE_KEY.replace(/\\n/g, '\n'),
4444
})
4545
} else if (process.env.GOOGLE_APPLICATION_CREDENTIALS) {
46-
console.log(
47-
'[VueFire]: using GOOGLE_APPLICATION_CREDENTIALS env variable'
48-
)
46+
log('using GOOGLE_APPLICATION_CREDENTIALS env variable')
4947
// automatically picks up the service account file path from the env variable
5048
credential = applicationDefault()
5149
} else {
52-
// TODO: add link to docs
53-
console.warn(`\
54-
[VueFire]: You must provide an "admin.serviceAccount" path to your json so it's picked up during development. See https://firebase.google.com/docs/admin/setup#initialize-sdk for more information. Note that you can also set the GOOGLE_APPLICATION_CREDENTIALS env variable to a full resolved path or a JSON string.
50+
// TODO: add link to vuefire docs
51+
log(
52+
'warn',
53+
`\
54+
You must provide an "admin.serviceAccount" path to your json so it's picked up during development. See https://firebase.google.com/docs/admin/setup#initialize-sdk for more information. Note that you can also set the GOOGLE_APPLICATION_CREDENTIALS env variable to a full resolved path or a JSON string.
5555
You can also set the FIREBASE_CLIENT_EMAIL, FIREBASE_PRIVATE_KEY and FIREBASE_PROJECT_ID env variables in production if you are deploying to something else than Firebase Cloud Functions.
56-
`)
56+
`
57+
)
5758
throw new Error('admin-app/missing-credentials')
5859
}
5960

packages/nuxt/src/runtime/app/plugin.server.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { deleteApp, FirebaseApp, initializeApp } from 'firebase/app'
22
import { User } from 'firebase/auth'
33
import LRU from 'lru-cache'
44
import { UserSymbol } from '../admin/plugin-auth-user.server'
5-
import { log } from '../../logging'
5+
import { log } from '../logging'
66
import { defineNuxtPlugin, useAppConfig } from '#app'
77

88
// TODO: allow customizing

packages/nuxt/src/runtime/auth/api.session-verification.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import {
88
deleteCookie,
99
sendRedirect,
1010
} from 'h3'
11-
import { log } from '../../logging'
11+
import { log } from '../logging'
1212
import { AUTH_COOKIE_MAX_AGE, AUTH_COOKIE_NAME } from './api.session'
1313

1414
// This version is used at https://github.com/FirebaseExtended/firebase-framework-tools/blob/e69f5bdd44695274ad88dbb4e21aac778ba60cc8/src/firebase-aware.ts#L39 but doesn't work locally. Should it maybe be used in production only? Seems unlikely.

packages/nuxt/src/runtime/auth/plugin.server.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import type { User } from 'firebase/auth'
33
import { VueFireAuthServer } from 'vuefire/server'
44
import { UserSymbol } from '../admin/plugin-auth-user.server'
55
import { defineNuxtPlugin } from '#app'
6-
import { log } from '../../logging'
6+
import { log } from '../logging'
77

88
/**
99
* Setups the auth state based on the cookie.

packages/nuxt/src/runtime/logging.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
export type LogType = 'debug' | 'info' | 'warn' | 'error' | 'trace' | 'log'
2+
3+
// TODO: allow disabling logs with some env variables
4+
5+
export function log(type: LogType, ...args: any[]): void
6+
export function log(...args: any[]): void
7+
export function log(...args: unknown[]): void {
8+
const [typeOrLog, ...rest] = args
9+
if (isLogType(typeOrLog)) {
10+
console[typeOrLog]('[VueFire]:', ...rest)
11+
} else {
12+
console.log('[VueFire]:', ...args)
13+
}
14+
}
15+
16+
function isLogType(logType: unknown): logType is LogType {
17+
return (
18+
logType === 'debug' ||
19+
logType === 'info' ||
20+
logType === 'warn' ||
21+
logType === 'error' ||
22+
logType === 'trace'
23+
)
24+
}

0 commit comments

Comments
 (0)