mirror of
https://github.com/lingble/chatwoot.git
synced 2025-11-03 12:37:56 +00:00
feat: Support dark mode in login pages (#7420)
Co-authored-by: Sivin Varghese <64252451+iamsivin@users.noreply.github.com>
This commit is contained in:
@@ -1,15 +1,12 @@
|
||||
import VueRouter from 'vue-router';
|
||||
|
||||
import { frontendURL } from '../helper/URLHelper';
|
||||
import { clearBrowserSessionCookies } from '../store/utils/api';
|
||||
import authRoute from './auth/auth.routes';
|
||||
import dashboard from './dashboard/dashboard.routes';
|
||||
import login from './login/login.routes';
|
||||
import store from '../store';
|
||||
import { validateLoggedInRoutes } from '../helper/routeHelpers';
|
||||
import AnalyticsHelper from '../helper/AnalyticsHelper';
|
||||
|
||||
const routes = [...login.routes, ...dashboard.routes, ...authRoute.routes];
|
||||
const routes = [...dashboard.routes];
|
||||
|
||||
window.roleWiseRoutes = {
|
||||
agent: [],
|
||||
@@ -36,86 +33,26 @@ generateRoleWiseRoute(routes);
|
||||
|
||||
export const router = new VueRouter({ mode: 'history', routes });
|
||||
|
||||
const unProtectedRoutes = ['login', 'auth_signup', 'auth_reset_password'];
|
||||
export const validateAuthenticateRoutePermission = (to, next, { getters }) => {
|
||||
const { isLoggedIn, getCurrentUser: user } = getters;
|
||||
|
||||
const authIgnoreRoutes = [
|
||||
'auth_confirmation',
|
||||
'pushBack',
|
||||
'auth_password_edit',
|
||||
'oauth-callback',
|
||||
];
|
||||
if (!isLoggedIn) {
|
||||
window.location = '/app/login';
|
||||
return '/app/login';
|
||||
}
|
||||
|
||||
const routeValidators = [
|
||||
{
|
||||
protected: false,
|
||||
loggedIn: true,
|
||||
handler: (_, getters) => {
|
||||
const user = getters.getCurrentUser;
|
||||
return `accounts/${user.account_id}/dashboard`;
|
||||
},
|
||||
},
|
||||
{
|
||||
protected: true,
|
||||
loggedIn: false,
|
||||
handler: () => 'login',
|
||||
},
|
||||
{
|
||||
protected: true,
|
||||
loggedIn: true,
|
||||
handler: (to, getters) =>
|
||||
validateLoggedInRoutes(to, getters.getCurrentUser, window.roleWiseRoutes),
|
||||
},
|
||||
{
|
||||
protected: false,
|
||||
loggedIn: false,
|
||||
handler: () => null,
|
||||
},
|
||||
];
|
||||
if (!to.name) {
|
||||
return next(frontendURL(`accounts/${user.account_id}/dashboard`));
|
||||
}
|
||||
|
||||
export const validateAuthenticateRoutePermission = (
|
||||
to,
|
||||
from,
|
||||
next,
|
||||
{ getters }
|
||||
) => {
|
||||
const isLoggedIn = getters.isLoggedIn;
|
||||
const isProtectedRoute = !unProtectedRoutes.includes(to.name);
|
||||
const strategy = routeValidators.find(
|
||||
validator =>
|
||||
validator.protected === isProtectedRoute &&
|
||||
validator.loggedIn === isLoggedIn
|
||||
const nextRoute = validateLoggedInRoutes(
|
||||
to,
|
||||
getters.getCurrentUser,
|
||||
window.roleWiseRoutes
|
||||
);
|
||||
const nextRoute = strategy.handler(to, getters);
|
||||
return nextRoute ? next(frontendURL(nextRoute)) : next();
|
||||
};
|
||||
|
||||
const validateSSOLoginParams = to => {
|
||||
const isLoginRoute = to.name === 'login';
|
||||
const { email, sso_auth_token: ssoAuthToken } = to.query || {};
|
||||
const hasValidSSOParams = email && ssoAuthToken;
|
||||
return isLoginRoute && hasValidSSOParams;
|
||||
};
|
||||
|
||||
export const validateRouteAccess = (to, from, next, { getters }) => {
|
||||
// Disable navigation to signup page if signups are disabled
|
||||
// Signup route has an attribute (requireSignupEnabled)
|
||||
// defined in it's route definition
|
||||
if (
|
||||
window.chatwootConfig.signupEnabled !== 'true' &&
|
||||
to.meta &&
|
||||
to.meta.requireSignupEnabled
|
||||
) {
|
||||
return next(frontendURL('login'));
|
||||
}
|
||||
|
||||
// For routes which doesn't care about authentication, skip validation
|
||||
if (authIgnoreRoutes.includes(to.name)) {
|
||||
return next();
|
||||
}
|
||||
|
||||
return validateAuthenticateRoutePermission(to, from, next, { getters });
|
||||
};
|
||||
|
||||
export const initalizeRouter = () => {
|
||||
const userAuthentication = store.dispatch('setUser');
|
||||
|
||||
@@ -125,22 +62,8 @@ export const initalizeRouter = () => {
|
||||
name: to.name,
|
||||
});
|
||||
|
||||
if (validateSSOLoginParams(to)) {
|
||||
clearBrowserSessionCookies();
|
||||
next();
|
||||
return;
|
||||
}
|
||||
|
||||
userAuthentication.then(() => {
|
||||
if (!to.name) {
|
||||
const { isLoggedIn, getCurrentUser: user } = store.getters;
|
||||
if (isLoggedIn) {
|
||||
return next(frontendURL(`accounts/${user.account_id}/dashboard`));
|
||||
}
|
||||
return next('/app/login');
|
||||
}
|
||||
|
||||
return validateRouteAccess(to, from, next, store);
|
||||
return validateAuthenticateRoutePermission(to, next, store);
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user