Last active
May 2, 2020 15:53
-
-
Save michalbujalski/821f201e965c0819f43efed7593b03d6 to your computer and use it in GitHub Desktop.
Firebase auth setup for in vue plugin
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 store from './store' | |
import Firebase from 'firebase' | |
const config = { | |
apiKey: <YOUR_API_KEY> | |
authDomain: <YOUR_DOMAIN>, | |
databaseURL: <DB_URL>, | |
projectId: <PROJECT_ID>, | |
storageBucket: <STORAGE_BUCKET>, | |
messagingSenderId: <MESSAGING_SENDER_ID> | |
} | |
export default { | |
install: (Vue, options) => { | |
const firebase = Firebase.initializeApp(config) | |
const auth = firebase.auth() | |
Vue.prototype.$auth = { | |
login: async (username, pass) => { | |
return await auth.signInWithEmailAndPassword(username, pass) | |
}, | |
logout: async () => { | |
await auth.signOut() | |
} | |
} | |
auth.onAuthStateChanged(user => { | |
store.commit('updateUser',{ user }) | |
}) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Sometimes when onAuthStateChanged is called user is null. Any ideas?