Skip to content
Snippets Groups Projects
Commit c5c2a25c authored by fibasile's avatar fibasile
Browse files

Added sign-in from session token

parent ec45b5a0
No related branches found
No related tags found
No related merge requests found
......@@ -6,7 +6,7 @@ module.exports = function(ctx) {
return {
// app boot file (/src/boot)
// --> boot files are part of "main.js"
boot: ["axios", "firebase"],
boot: ["axios", "firebase", "auth"],
css: ["app.styl"],
......
// import something here
import firebase from "firebase/app";
import "firebase/auth";
// "async" is optional
export default async ({ router, store /* app, router, Vue, ... */ }) => {
// something to do
firebase.auth().onAuthStateChanged(user => {
store.dispatch("auth/signInFromSession", user);
});
router.beforeEach((to, from, next) => {
return next();
});
};
......@@ -79,8 +79,27 @@ export function signInWithGoogle({ commit }) {
});
}
export function signInFromSession({ commit, dispatch }, user) {
if (!user) {
return dispatch("signOut");
}
commit("setStatus", "loading");
return new Promise((resolve, reject) => {
commit("setUser", {
name: user.displayName,
email: user.email,
photoURL: user.photoURL,
uid: user.uid
});
commit("setStatus", "success");
commit("setError", null);
resolve(user);
});
}
export function signOut({ commit }) {
firebase
return firebase
.auth()
.signOut()
.then(function() {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment