fix: Allow users to login even if they have access to more than 15 accounts (#4475)
This commit is contained in:
@@ -1,4 +1,3 @@
|
||||
/* eslint no-console: 0 */
|
||||
import Auth from '../api/auth';
|
||||
|
||||
const parseErrorCode = error => Promise.reject(error);
|
||||
@@ -7,7 +6,7 @@ export default axios => {
|
||||
const { apiHost = '' } = window.chatwootConfig || {};
|
||||
const wootApi = axios.create({ baseURL: `${apiHost}/` });
|
||||
// Add Auth Headers to requests if logged in
|
||||
if (Auth.isLoggedIn()) {
|
||||
if (Auth.hasAuthCookie()) {
|
||||
const {
|
||||
'access-token': accessToken,
|
||||
'token-type': tokenType,
|
||||
|
||||
@@ -14,6 +14,9 @@ export const getLoginRedirectURL = (ssoAccountId, user) => {
|
||||
if (ssoAccount) {
|
||||
return frontendURL(`accounts/${ssoAccountId}/dashboard`);
|
||||
}
|
||||
if (accounts.length) {
|
||||
return frontendURL(`accounts/${accounts[0].id}/dashboard`);
|
||||
}
|
||||
return DEFAULT_REDIRECT_URL;
|
||||
};
|
||||
|
||||
@@ -41,15 +44,6 @@ export const conversationUrl = ({
|
||||
return url;
|
||||
};
|
||||
|
||||
export const accountIdFromPathname = pathname => {
|
||||
const isInsideAccountScopedURLs = pathname.includes('/app/accounts');
|
||||
const urlParam = pathname.split('/')[3];
|
||||
// eslint-disable-next-line no-restricted-globals
|
||||
const isScoped = isInsideAccountScopedURLs && !isNaN(urlParam);
|
||||
const accountId = isScoped ? Number(urlParam) : '';
|
||||
return accountId;
|
||||
};
|
||||
|
||||
export const isValidURL = value => {
|
||||
/* eslint-disable no-useless-escape */
|
||||
const URL_REGEX = /^https?:\/\/(?:www\.)?[-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9()@:%_\+.~#?&//=]*)$/gm;
|
||||
|
||||
@@ -142,14 +142,7 @@ class ActionCableConnector extends BaseActionCableConnector {
|
||||
}
|
||||
|
||||
export default {
|
||||
init() {
|
||||
if (AuthAPI.isLoggedIn()) {
|
||||
const actionCable = new ActionCableConnector(
|
||||
window.WOOT,
|
||||
AuthAPI.getPubSubToken()
|
||||
);
|
||||
return actionCable;
|
||||
}
|
||||
return null;
|
||||
init(pubsubToken) {
|
||||
return new ActionCableConnector(window.WOOT, pubsubToken);
|
||||
},
|
||||
};
|
||||
|
||||
@@ -44,7 +44,7 @@ export const getPushSubscriptionPayload = subscription => ({
|
||||
});
|
||||
|
||||
export const sendRegistrationToServer = subscription => {
|
||||
if (auth.isLoggedIn()) {
|
||||
if (auth.hasAuthCookie()) {
|
||||
return NotificationSubscriptions.create(
|
||||
getPushSubscriptionPayload(subscription)
|
||||
);
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
import {
|
||||
frontendURL,
|
||||
conversationUrl,
|
||||
accountIdFromPathname,
|
||||
isValidURL,
|
||||
getLoginRedirectURL,
|
||||
} from '../URLHelper';
|
||||
@@ -39,18 +38,6 @@ describe('#URL Helpers', () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe('accountIdFromPathname', () => {
|
||||
it('should return account id if accont scoped url is passed', () => {
|
||||
expect(accountIdFromPathname('/app/accounts/1/settings/general')).toBe(1);
|
||||
});
|
||||
it('should return empty string if accont scoped url not is passed', () => {
|
||||
expect(accountIdFromPathname('/app/accounts/settings/general')).toBe('');
|
||||
});
|
||||
it('should return empty string if empty string is passed', () => {
|
||||
expect(accountIdFromPathname('')).toBe('');
|
||||
});
|
||||
});
|
||||
|
||||
describe('isValidURL', () => {
|
||||
it('should return true if valid url is passed', () => {
|
||||
expect(isValidURL('https://chatwoot.com')).toBe(true);
|
||||
@@ -75,7 +62,7 @@ describe('#URL Helpers', () => {
|
||||
getLoginRedirectURL('7500', {
|
||||
accounts: [{ id: '7501', name: 'Test Account 7501' }],
|
||||
})
|
||||
).toBe('/app/');
|
||||
).toBe('/app/accounts/7501/dashboard');
|
||||
expect(getLoginRedirectURL('7500', null)).toBe('/app/');
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user