Skip to content

Instantly share code, notes, and snippets.

@dnek
Created December 6, 2019 11:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dnek/df6ea9d5c791052b7d0bf5f70187acb9 to your computer and use it in GitHub Desktop.
Save dnek/df6ea9d5c791052b7d0bf5f70187acb9 to your computer and use it in GitHub Desktop.
Nuxt x Firebase Cloud Functions
import firebase from 'firebase/app'
export default async (ctx, inject) => {
const options = {
'functionsLocation': 'asia-northeast1',
'config': {
'apiKey': 'xxxx',
'authDomain': 'xxxx',
'databaseURL': 'xxxx',
'projectId': 'xxxx',
'storageBucket': '',
'messagingSenderId': 'xxxx',
'appId': 'xxxx',
'measurementId': 'xxxx'
}
}
if (!firebase.apps.length) {
firebase.initializeApp(options.config)
}
await import('firebase/functions')
const fireFunc = firebase.app().functions(options.functionsLocation)
const fireFuncObj = firebase.functions
inject('fireFunc', fireFunc)
inject('fireFuncObj', fireFuncObj)
}
/*
** 参考
** https://github.com/lupas/nuxt-fire
** MIT - 2018-present Pascal Luther
*/
export default {
// 色々略
plugins: [
'~/plugins/fireFunc.js'
]
}
export default {
async asyncData ({ query, app }) {
if (process.client) {
const res = await app.$fireFunc.httpsCallable('mySearchFunc')(query)
return res.data
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment