Skip to content

Instantly share code, notes, and snippets.

@michalbujalski
Last active May 2, 2020 15:53
Show Gist options
  • Save michalbujalski/821f201e965c0819f43efed7593b03d6 to your computer and use it in GitHub Desktop.
Save michalbujalski/821f201e965c0819f43efed7593b03d6 to your computer and use it in GitHub Desktop.
Firebase auth setup for in vue plugin
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 })
})
}
}
@brewmanandi
Copy link

Sometimes when onAuthStateChanged is called user is null. Any ideas?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment