chore: Pass sso_account_id to select the account during SSO Login (#4103)

This commit is contained in:
Pranav Raj S 2022-03-03 20:49:51 +05:30 committed by GitHub
parent 11adfd2384
commit 9583a2dbad
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 61 additions and 9 deletions

View file

@ -5,6 +5,7 @@ import login from './login/login.routes';
import dashboard from './dashboard/dashboard.routes';
import authRoute from './auth/auth.routes';
import { frontendURL } from '../helper/URLHelper';
import { clearBrowserSessionCookies } from '../store/utils/api';
const routes = [
...login.routes,
@ -101,6 +102,13 @@ export const validateAuthenticateRoutePermission = (to, from, next) => {
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;
};
const validateRouteAccess = (to, from, next) => {
if (
window.chatwootConfig.signupEnabled !== 'true' &&
@ -111,6 +119,11 @@ const validateRouteAccess = (to, from, next) => {
next(frontendURL(`accounts/${user.account_id}/dashboard`));
}
if (validateSSOLoginParams(to)) {
clearBrowserSessionCookies();
return next();
}
if (authIgnoreRoutes.includes(to.name)) {
return next();
}