Last active
April 7, 2020 14:57
-
-
Save potato4d/59ad2d2f59c296cfd4a6e375588316b9 to your computer and use it in GitHub Desktop.
【v2対応】Nuxt.jsとFirebaseを組み合わせて爆速でWebアプリケーションを構築する ref: https://qiita.com/potato4d/items/cfddeb8732fec63cb29c
This file contains hidden or 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 '~/plugins/firebase' | |
function auth () { | |
return new Promise((resolve, reject) => { | |
firebase.auth().onAuthStateChanged((user) => { | |
resolve(user || false) | |
}) | |
}) | |
} | |
export default auth |
This file contains hidden or 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
$ npm i -g create-nuxt-app |
This file contains hidden or 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 Vue from 'vue' | |
import Vuex from 'vuex' | |
import firebase from 'firebase' | |
import { firebaseMutations, firebaseAction } from 'vuexfire' | |
const db = firebase.database() | |
const postsRef = db.ref('/posts') | |
Vue.use(Vuex) | |
return new Vuex.Store({ | |
state: { | |
posts: [] | |
}, | |
mutations: { | |
...firebaseMutations | |
}, | |
actions: { | |
INIT_POSTS: firebaseAction(({ bindFirebaseRef }) => { | |
bindFirebaseRef('posts', postsRef) | |
}) | |
} | |
} |
This file contains hidden or 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
$ vue init nuxt/starter |
This file contains hidden or 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 Vue from 'vue' | |
import Vuex from 'vuex' | |
import firebase from 'firebase' | |
import { firebaseMutations, firebaseAction } from 'vuexfire' | |
const db = firebase.database() | |
const postsRef = db.ref('/posts') | |
Vue.use(Vuex) | |
return new Vuex.Store({ | |
state: { | |
posts: [] | |
}, | |
mutations: { | |
...firebaseMutations | |
}, | |
actions: { | |
INIT_POSTS: firebaseAction(({ bindFirebaseRef }) => { | |
bindFirebaseRef('posts', postsRef) | |
}) | |
} | |
} |
This file contains hidden or 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' | |
if (!firebase.apps.length) { | |
firebase.initializeApp( | |
{ | |
apiKey: process.env.APIKEY, | |
authDomain: process.env.AUTHDOMAIN, | |
databaseURL: process.env.DATABASEURL, | |
projectId: process.env.PROJECTID, | |
storageBucket: process.env.STORAGEBUCKET, | |
messagingSenderId: process.env.MESSAGINGSENDERID | |
} | |
) | |
} | |
export default firebase |
This file contains hidden or 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' | |
const provider = new firebase.auth.GoogleAuthProvider() | |
firebase.auth().signInWithRedirect(provider) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment