Skip to content

Commit 3cd8bda

Browse files
committed
Redirect to dashboard home page when user is logged in and accessing auth pages
1 parent b74c343 commit 3cd8bda

File tree

2 files changed

+11
-5
lines changed

2 files changed

+11
-5
lines changed

resources/js/router/index.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,12 @@ router.beforeEach(async (to, from, next) => {
1818
if (!authStore.user) {
1919
authStore.clearBrowserData();
2020
}
21+
22+
if(to?.meta?.isPublicAuthPage && authStore.user) {
23+
next({name: 'dashboard'})
24+
return;
25+
}
26+
2127
const requiresAbility = to.meta.requiresAbility;
2228
const requiresAuth = to.meta.requiresAuth;
2329
const belongsToOwnerOnly = to.meta.isOwner;

resources/js/router/routes.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ const routes = [
1717
{
1818
name: "home",
1919
path: "/",
20-
meta: {requiresAuth: false},
20+
meta: {requiresAuth: false, isPublicAuthPage: true},
2121
component: PageLogin,
2222
},
2323
{
@@ -64,25 +64,25 @@ const routes = [
6464
{
6565
path: "/login",
6666
name: "login",
67-
meta: {requiresAuth: false},
67+
meta: {requiresAuth: false, isPublicAuthPage: true},
6868
component: PageLogin,
6969
},
7070
{
7171
path: "/register",
7272
name: "register",
73-
meta: {requiresAuth: false},
73+
meta: {requiresAuth: false, isPublicAuthPage: true},
7474
component: PageRegister,
7575
},
7676
{
7777
path: "/reset-password",
7878
name: "resetPassword",
79-
meta: {requiresAuth: false},
79+
meta: {requiresAuth: false, isPublicAuthPage: true},
8080
component: PageResetPassword,
8181
},
8282
{
8383
path: "/forgot-password",
8484
name: "forgotPassword",
85-
meta: {requiresAuth: false},
85+
meta: {requiresAuth: false, isPublicAuthPage: true},
8686
component: PageForgotPassword,
8787
},
8888
{

0 commit comments

Comments
 (0)