Created
December 6, 2019 11:21
-
-
Save dnek/df6ea9d5c791052b7d0bf5f70187acb9 to your computer and use it in GitHub Desktop.
Nuxt x Firebase Cloud Functions
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export default { | |
// 色々略 | |
plugins: [ | |
'~/plugins/fireFunc.js' | |
] | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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