diff --git a/src/components/CoursesPage.vue b/src/components/CoursesPage.vue index 38049c2..5287380 100644 --- a/src/components/CoursesPage.vue +++ b/src/components/CoursesPage.vue @@ -149,7 +149,7 @@ diff --git a/src/components/ForgetPassword.vue b/src/components/ForgetPassword.vue index b17db1d..cc455d3 100644 --- a/src/components/ForgetPassword.vue +++ b/src/components/ForgetPassword.vue @@ -10,7 +10,8 @@
-
+ +
Вспомнили пароль? @@ -173,6 +174,8 @@ import firebase from "firebase"; import modal from "./Modal"; +import { getUserInfo, checkRouter } from "../utils/getUserInfo"; + export default { components: { modal @@ -213,6 +216,13 @@ export default { self.showModal(); }); } + }, + beforeCreate: function() { + getUserInfo(); + firebase.auth().onAuthStateChanged(user => { + this.$store.dispatch("fetchUser", user); + checkRouter(); + }); } }; diff --git a/src/components/InDevelopment.vue b/src/components/InDevelopment.vue index bba9cd7..e2dd837 100644 --- a/src/components/InDevelopment.vue +++ b/src/components/InDevelopment.vue @@ -27,5 +27,17 @@ p { diff --git a/src/components/Login.vue b/src/components/Login.vue index bf51b22..a0bae6c 100644 --- a/src/components/Login.vue +++ b/src/components/Login.vue @@ -177,6 +177,8 @@ import firebase from "firebase"; import modal from "./Modal"; +import {getUserInfo, checkRouter } from "../utils/getUserInfo"; + export default { components: { modal @@ -194,7 +196,6 @@ export default { methods: { submit() { let self = this; - console.log(123); // eslint-disable-line no-console firebase .auth() .signInWithEmailAndPassword(this.form.email, this.form.password) @@ -217,12 +218,10 @@ export default { } }, beforeCreate: function() { + getUserInfo() firebase.auth().onAuthStateChanged(user => { this.$store.dispatch("fetchUser", user); - if (this.$store.state.user.loggedIn) { - this.$router.push({ path: "/user/courses" }); - return; - } + checkRouter(); }); } }; diff --git a/src/components/Register.vue b/src/components/Register.vue index e32c5bb..633cfa0 100644 --- a/src/components/Register.vue +++ b/src/components/Register.vue @@ -191,6 +191,8 @@ import firebase from "firebase"; import modal from "./Modal"; +import {getUserInfo, checkRouter } from "../utils/getUserInfo"; + export default { components: { modal @@ -254,6 +256,13 @@ export default { closeModal() { this.isModalVisible = false; } + }, + beforeCreate: function() { + getUserInfo() + firebase.auth().onAuthStateChanged(user => { + this.$store.dispatch("fetchUser", user); + checkRouter(); + }); } }; diff --git a/src/components/ReviewsPage.vue b/src/components/ReviewsPage.vue index 8b2ff75..391dfe9 100644 --- a/src/components/ReviewsPage.vue +++ b/src/components/ReviewsPage.vue @@ -198,5 +198,17 @@ diff --git a/src/components/UserCourses.vue b/src/components/UserCourses.vue index 00452a5..6a60ac2 100644 --- a/src/components/UserCourses.vue +++ b/src/components/UserCourses.vue @@ -43,17 +43,24 @@ a { diff --git a/src/components/UserSettings.vue b/src/components/UserSettings.vue index 676a5aa..891e6c2 100644 --- a/src/components/UserSettings.vue +++ b/src/components/UserSettings.vue @@ -34,6 +34,8 @@ import UserInfo from "./UserInfo"; import UserTabs from "./UserTabs"; import UserInputs from "./UserInputs"; +import { getUserInfo, checkRouter } from "../utils/getUserInfo"; + export default { components: { UserInfo, @@ -41,12 +43,10 @@ export default { UserInputs }, beforeCreate: function() { + getUserInfo(); firebase.auth().onAuthStateChanged(user => { this.$store.dispatch("fetchUser", user); - if (!this.$store.state.user.loggedIn) { - this.$router.push({ path: "/login" }); - return; - } + checkRouter(); }); } }; diff --git a/src/utils/getUserInfo.js b/src/utils/getUserInfo.js index a0675a8..c1b43b0 100644 --- a/src/utils/getUserInfo.js +++ b/src/utils/getUserInfo.js @@ -2,25 +2,24 @@ import firebase from "firebase"; import store from "../store"; import router from "../routes"; -function checkRouter() { - let authRoutes = ["Login", "Register", "ForgetPassword"]; - let independentRoutes = ["Main", "CoursesPage", "ReviewsPage", "FeedbackPage", "InDevelopment", "DescriptionCourse"]; +export function checkRouter() { + let authRoutes = ["Login", "Register", "ForgetPassword"]; let lmsRoutes = ["UserCourses", "UserSettings", "Enroll", "Task"]; - if (independentRoutes.includes(router.currentRoute.name)){ - return; - } - else if (authRoutes.includes(router.currentRoute.name) && store.user.loggedIn) { - this.$router.push({ name: "CoursesPage" }); - } - else if (lmsRoutes.includes(router.currentRoute.name) && !store.user.loggedIn) { - this.$router.push({ name: "Login" }); + if ( + authRoutes.includes(router.currentRoute.name) && + store.state.user.loggedIn + ) { + router.push({ name: "CoursesPage" }); + } else if ( + lmsRoutes.includes(router.currentRoute.name) && + !store.state.user.loggedIn + ) { + router.push({ name: "Login" }); } } -export default function getUserInfo() { - console.log(router.currentRoute); // eslint-disable-line no-console +export function getUserInfo() { if (store.state.user.getDataFromFirebase) { - checkRouter(); return; } firebase.auth().onAuthStateChanged(user => { @@ -34,6 +33,5 @@ export default function getUserInfo() { store.commit("saveUserInfo", doc.data()); }); } - checkRouter(); }); }