Skip to content

Instantly share code, notes, and snippets.

@dnek dnek/fireFunc.js
Created Dec 6, 2019

Embed
What would you like to do?
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
You can’t perform that action at this time.