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

add authenticated routes and redirects after login

parent 46f1ec95
No related branches found
No related tags found
No related merge requests found
<template> <template>
<q-page <q-page padding class="flex justify-center content-center">
padding
class="flex justify-center content-center"
>
<!-- content --> <!-- content -->
<q-card class="q-pa-md page-row"> <q-card class="q-pa-md page-row">
...@@ -13,15 +10,9 @@ ...@@ -13,15 +10,9 @@
<div class="text-grey">Please sign in to your account</div> <div class="text-grey">Please sign in to your account</div>
</div> </div>
<div class="col-12 text-center q-pa-md"> <div class="col-12 text-center q-pa-md">
<q-btn <q-btn class="bg-grey-5 text-white q-pa-sm full-width" @click="handleGoogle">
class="bg-grey-5 text-white q-pa-sm full-width"
@click="handleGoogle"
>
Sign in with Sign in with
<q-icon <q-icon name="fab fa-google" class="q-ml-sm" />
name="fab fa-google"
class="q-ml-sm"
/>
</q-btn> </q-btn>
</div> </div>
<div class="col-12 text-center q-pa-md"> <div class="col-12 text-center q-pa-md">
...@@ -29,11 +20,7 @@ ...@@ -29,11 +20,7 @@
</div> </div>
</div> </div>
<div class="login-form q-pa-md"> <div class="login-form q-pa-md">
<q-form <q-form @submit="onSubmit" @reset="onReset" class="q-gutter-md">
@submit="onSubmit"
@reset="onReset"
class="q-gutter-md"
>
<q-input <q-input
filled filled
v-model="email" v-model="email"
...@@ -58,39 +45,21 @@ ...@@ -58,39 +45,21 @@
/> />
<div class="flex justify-start"> <div class="flex justify-start">
<q-btn <q-btn to="/signup" label="Sign up" dense color="grey-5" flat />
to="/signup"
label="Sign up"
dense
color="grey-5"
flat
/>
<q-space /> <q-space />
<q-btn <q-btn label="Sign in" to="/account/projects" color="grey-4" />
label="Sign in" <q-btn label="Reset" type="reset" color="grey-5" flat class="q-ml-sm" />
to="/account/projects"
color="grey-4"
/>
<q-btn
label="Reset"
type="reset"
color="grey-5"
flat
class="q-ml-sm"
/>
</div> </div>
</q-form> </q-form>
</div> </div>
</div> </div>
<div class="col-sm-12 col-md-6 q-pa-lg has-decoration"> <div class="col-sm-12 col-md-6 q-pa-lg has-decoration">
<div class="text-center"> <div class="text-center">
<q-img <q-img src="/statics/600x600fabr.png" basic style="max-width: 200px;" />
src="/statics/600x600fabr.png"
basic
style="max-width: 200px;"
/>
<div class="text-h5">Open-source Circular Fashion</div> <div class="text-h5">Open-source Circular Fashion</div>
<div class="text-display3">A growing collection of open designs, patterns, recipes and zero waste projects.</div> <div
class="text-display3"
>A growing collection of open designs, patterns, recipes and zero waste projects.</div>
<q-separator class="q-my-md" /> <q-separator class="q-my-md" />
<div class="text-overline">A project by</div> <div class="text-overline">A project by</div>
...@@ -103,26 +72,48 @@ ...@@ -103,26 +72,48 @@
</template> </template>
<script> <script>
import { mapActions } from "vuex"; import { mapActions, mapGetters } from "vuex";
export default { export default {
// name: 'PageName', // name: 'PageName',
data () { data() {
return { return {
email: "", email: "",
password: "" password: ""
}; };
}, },
computed: {
...mapGetters({
user: "auth/user"
})
},
watch: {
user: function(newVal) {
console.log("user changed");
if (newVal) {
this.$nextTick(() => {
this.showAccountPage();
});
}
}
},
methods: { methods: {
showAccountPage() {
if (this.$route.query.redirect) {
this.$router.push(this.$route.query.redirect);
} else {
this.$router.push("/account");
}
},
...mapActions({ signInWithGoogle: "auth/signInWithGoogle" }), ...mapActions({ signInWithGoogle: "auth/signInWithGoogle" }),
onSubmit () { }, onSubmit() {},
onReset () { }, onReset() {},
handleGoogle () { handleGoogle() {
const vm = this; const vm = this;
this.signInWithGoogle() this.signInWithGoogle()
.then(success => { .then(success => {
vm.$router.push("/account"); vm.showAccountPage();
}) })
.catch(error => { }); .catch(error => {});
} }
} }
}; };
......
...@@ -25,8 +25,13 @@ export default function({ store } /*, ssrContext } */) { ...@@ -25,8 +25,13 @@ export default function({ store } /*, ssrContext } */) {
Router.beforeEach((to, from, next) => { Router.beforeEach((to, from, next) => {
console.log(to); console.log(to);
console.log(store); console.log(store);
if (to.path.startsWith("/account") && !store.getters["auth/user"]) { if (to.matched.some(record => record.meta.requiresAuth)) {
return next("/login"); if (!store.getters["auth/user"]) {
return next({
path: "/login",
query: { redirect: to.fullPath }
});
}
} }
return next(); return next();
}); });
......
...@@ -25,29 +25,36 @@ const routes = [ ...@@ -25,29 +25,36 @@ const routes = [
children: [ children: [
{ {
path: "", path: "",
meta: { requiresAuth: true },
component: () => import("pages/UserDashboard") component: () => import("pages/UserDashboard")
}, },
{ {
path: "edit", path: "edit",
meta: { requiresAuth: true },
component: () => import("pages/UserSettings.vue") component: () => import("pages/UserSettings.vue")
}, },
{ {
path: "projects", path: "projects",
meta: { requiresAuth: true },
component: () => import("pages/UserProjects.vue") component: () => import("pages/UserProjects.vue")
}, },
{ {
path: "collections", path: "collections",
meta: { requiresAuth: true },
component: () => import("pages/UserCollections.vue") component: () => import("pages/UserCollections.vue")
}, },
{ {
path: "collections/new", path: "collections/new",
meta: { requiresAuth: true },
component: () => import("pages/CollectionUpload.vue") component: () => import("pages/CollectionUpload.vue")
}, },
{ {
path: "bookmarks", path: "bookmarks",
meta: { requiresAuth: true },
component: () => import("pages/UserBookmarks.vue") component: () => import("pages/UserBookmarks.vue")
}, },
{ {
meta: { requiresAuth: true },
path: "projects/new", path: "projects/new",
component: () => import("pages/ProjectUpload.vue") component: () => import("pages/ProjectUpload.vue")
} }
......
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