Skip to content

Commit

Permalink
feat(warn): doc to docs
Browse files Browse the repository at this point in the history
  • Loading branch information
posva committed Jul 13, 2023
1 parent 078c3ac commit 3eec751
Show file tree
Hide file tree
Showing 9 changed files with 28 additions and 99 deletions.
14 changes: 14 additions & 0 deletions packages/nuxt/playground/preset/nitro.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,17 @@ export default {
// }
// }
// }

interface FirebaseUserAppConfig {
firebase?: {
functions?: {
runtimeOptions?: RuntimeOptions
httpsOptions?: HttpsOptions
}
}
}

declare module '@nuxt/schema' {
// interface AppConfig extends FirebaseUserAppConfig {}
interface RuntimeConfig extends FirebaseUserAppConfig {}
}
31 changes: 0 additions & 31 deletions packages/nuxt/src/firebaseAliases.ts

This file was deleted.

8 changes: 3 additions & 5 deletions packages/nuxt/src/module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import type {
} from 'firebase-admin/app'
import { markRaw } from 'vue'
import type { NuxtVueFireAppCheckOptions } from './runtime/app-check'
import { addMissingAlias } from './firebaseAliases'
import { log } from './runtime/logging'

export interface VueFireNuxtModuleOptions {
Expand Down Expand Up @@ -89,7 +88,7 @@ export default defineNuxtModule<VueFireNuxtModuleOptions>({
const runtimeDir = fileURLToPath(new URL('./runtime', import.meta.url))
const templatesDir = fileURLToPath(new URL('../templates', import.meta.url))

// to handle TimeStamp objects
// to handle TimeStamp and GeoPoints objects
addPlugin(resolve(runtimeDir, 'payload-plugin'))

// TODO: I don't think the appConfig is the right place to store these as it makes things reactive
Expand Down Expand Up @@ -129,7 +128,7 @@ export default defineNuxtModule<VueFireNuxtModuleOptions>({
if (nuxt.options.ssr && !hasServiceAccount) {
log(
'warn',
'You activated both SSR and auth but you are not providing an admin config. If you render or prerender any page using auth, you will get an error. In that case, provide an admin config to the nuxt-vuefire module.'
'You activated both SSR and auth but you are not providing a service account for the admin SDK. See https://vuefire.vuejs.org/nuxt/getting-started.html#configuring-the-admin-sdk.'
)
}

Expand All @@ -141,8 +140,7 @@ export default defineNuxtModule<VueFireNuxtModuleOptions>({
} else if (nuxt.options.ssr) {
log(
'warn',
'You activated both SSR and app-check but you are not providing an admin config. If you render or prerender any page using app-check, you will get an error. In that case, provide an admin config to the nuxt-vuefire module.'
// TODO: link about how to provide admin credentials
'You activated both SSR and app-check but you are not providing a service account for the admin SDK. See https://vuefire.vuejs.org/nuxt/getting-started.html#configuring-the-admin-sdk.'
)
}
}
Expand Down
19 changes: 7 additions & 12 deletions packages/nuxt/src/runtime/app/plugin.server.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import { deleteApp, type FirebaseApp, initializeApp } from 'firebase/app'
import { getAuth, signInWithCustomToken, type User } from 'firebase/auth'
import { type App as AdminApp } from 'firebase-admin/app'
import { DecodedIdToken, getAuth as getAdminAuth } from 'firebase-admin/auth'
import { type User } from 'firebase/auth'
import { DecodedIdToken } from 'firebase-admin/auth'
import { LRUCache } from 'lru-cache'
import { log } from '../logging'
import { DECODED_ID_TOKEN_SYMBOL, UserSymbol } from '../constants'
import { defineNuxtPlugin, useAppConfig, useRequestEvent } from '#app'
import { DECODED_ID_TOKEN_SYMBOL } from '../constants'
import { defineNuxtPlugin, useAppConfig } from '#app'

// TODO: allow customizing
// TODO: find sensible defaults. Should they change depending on the platform?
Expand All @@ -25,7 +24,7 @@ const appCache = new LRUCache<string, FirebaseApp>({
/**
* Initializes the app and provides it to others.
*/
export default defineNuxtPlugin(async (nuxtApp) => {
export default defineNuxtPlugin((nuxtApp) => {
const appConfig = useAppConfig()

const decodedToken = nuxtApp[
Expand All @@ -35,11 +34,6 @@ export default defineNuxtPlugin(async (nuxtApp) => {

const uid = decodedToken?.uid

// // expose the user to code
// event.context.user = user
// // for SSR
// nuxtApp.payload.vuefireUser = user?.toJSON()

let firebaseApp: FirebaseApp | undefined

// log('debug', 'initializing app with', appConfig.firebaseConfig)
Expand All @@ -56,9 +50,10 @@ export default defineNuxtPlugin(async (nuxtApp) => {
firebaseApp = appCache.get(uid)!
// console.time('token')
} else {
log('debug', '👤 reusing authenticated app', uid)
log('debug', '👤 reusing authenticated app', firebaseApp.name)
}
} else {
// TODO: is this safe? should we create a new one everytime
if (!appCache.has('')) {
appCache.set('', initializeApp(appConfig.firebaseConfig))
}
Expand Down
6 changes: 2 additions & 4 deletions packages/nuxt/src/runtime/auth/api.session-verification.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ import {
} from 'h3'
import { log } from '../logging'

// 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.

/**
* Setups an API endpoint to be used by the client to mint a cookie based auth session.
*/
Expand All @@ -36,7 +34,7 @@ export default defineEventHandler(async (event) => {
log('error', 'Error minting the cookie -', e.message)
})
if (cookie) {
log('debug', `minted a session cookie for user ${verifiedIdToken.uid}`)
// log('debug', `minted a session cookie for user ${verifiedIdToken.uid}`)
setCookie(event, AUTH_COOKIE_NAME, cookie, {
maxAge: AUTH_COOKIE_MAX_AGE,
secure: true,
Expand All @@ -53,7 +51,7 @@ export default defineEventHandler(async (event) => {
}
}
} else {
log('debug', 'deleting the session cookie')
// log('debug', 'deleting the session cookie')
deleteCookie(event, AUTH_COOKIE_NAME)
event.node.res.statusCode = 204
}
Expand Down
41 changes: 0 additions & 41 deletions packages/nuxt/src/runtime/auth/api.session.ts

This file was deleted.

4 changes: 0 additions & 4 deletions packages/nuxt/src/runtime/auth/plugin-user-token.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,13 @@ import { getCookie } from 'h3'
import { DECODED_ID_TOKEN_SYMBOL } from '../constants'
import { defineNuxtPlugin, useRequestEvent } from '#app'

// TODO: move this to auth and adapt the module to load it in the right order

/**
* Decodes the user token if any. Should only be added on the server and before the firebase/app
*/
export default defineNuxtPlugin(async (nuxtApp) => {
const event = useRequestEvent()
const adminApp = nuxtApp.$firebaseAdminApp as AdminApp

// log('debug', '🔥 Plugin auth user server')

const decodedToken = await decodeUserToken(
getCookie(event, AUTH_COOKIE_NAME),
adminApp
Expand Down
2 changes: 1 addition & 1 deletion packages/nuxt/src/runtime/auth/plugin.server.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { getAuth, signInWithCustomToken, type User } from 'firebase/auth'
import { getAuth, signInWithCustomToken } from 'firebase/auth'
import { DecodedIdToken, getAuth as getAdminAuth } from 'firebase-admin/auth'
import type { FirebaseApp } from 'firebase/app'
import type { App as AdminApp } from 'firebase-admin/app'
Expand Down
2 changes: 1 addition & 1 deletion src/auth/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { FirebaseApp } from 'firebase/app'
import { getAuth, type User } from 'firebase/auth'
import { getAuth, initializeAuth, type User } from 'firebase/auth'
import { App, ref } from 'vue-demi'
import { useFirebaseApp } from '../app'
import { getGlobalScope } from '../globals'
Expand Down

0 comments on commit 3eec751

Please sign in to comment.