Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(ui/ux): auth pages #1161

Merged
merged 5 commits into from
May 13, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fix(ux): login: redirect if already authenticated
  • Loading branch information
ssiyad committed May 13, 2023
commit 09ee05414aced70dd3598d6b76e632d2b3dd7ae9
18 changes: 14 additions & 4 deletions desk/src/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,14 @@ export const VERIFY = "Verify Account";
export const AGENT_PORTAL_LANDING = "DeskTickets";
export const CUSTOMER_PORTAL_LANDING = "PortalTickets";
export const CUSTOMER_PORTAL_NEW_TICKET = "DefaultNewTicket";
export const AUTH_BYPASS_ROUTES = [LOGIN, SIGNUP, VERIFY];
export const AUTH_ROUTES = [LOGIN, SIGNUP, VERIFY];
export const KNOWLEDGE_BASE_PUBLIC = "Knowledge Base";
export const WEBSITE_ROOT = "Website Root";

const routes = [
{
path: "",
name: WEBSITE_ROOT,
component: () => import("@/pages/WebsiteRoot.vue"),
},
{
Expand Down Expand Up @@ -380,9 +382,17 @@ router.beforeEach(async (to) => {
});

router.beforeEach(async (to) => {
if (AUTH_BYPASS_ROUTES.includes(to.name)) return;

const isAuthRoute = AUTH_ROUTES.includes(to.name);
const authStore = useAuthStore();

await authStore.init().catch(() => router.replace({ name: LOGIN }));
try {
await authStore.init();
if (isAuthRoute) {
router.replace({ name: WEBSITE_ROOT });
}
} catch {
if (!isAuthRoute) {
router.replace({ name: LOGIN });
}
}
});