chore: Add support for conversation_id in SSO params (#5228)
This commit is contained in:
parent
4b1bb65c92
commit
27a9806817
5 changed files with 54 additions and 14 deletions
|
@ -5,16 +5,31 @@ export const frontendURL = (path, params) => {
|
|||
return `/app/${path}${stringifiedParams}`;
|
||||
};
|
||||
|
||||
export const getLoginRedirectURL = (ssoAccountId, user) => {
|
||||
const getSSOAccountPath = ({ ssoAccountId, user }) => {
|
||||
const { accounts = [] } = user || {};
|
||||
const ssoAccount = accounts.find(
|
||||
account => account.id === Number(ssoAccountId)
|
||||
);
|
||||
let accountPath = '';
|
||||
if (ssoAccount) {
|
||||
return frontendURL(`accounts/${ssoAccountId}/dashboard`);
|
||||
accountPath = `accounts/${ssoAccountId}`;
|
||||
} else if (accounts.length) {
|
||||
accountPath = `accounts/${accounts[0].id}`;
|
||||
}
|
||||
if (accounts.length) {
|
||||
return frontendURL(`accounts/${accounts[0].id}/dashboard`);
|
||||
return accountPath;
|
||||
};
|
||||
|
||||
export const getLoginRedirectURL = ({
|
||||
ssoAccountId,
|
||||
ssoConversationId,
|
||||
user,
|
||||
}) => {
|
||||
const accountPath = getSSOAccountPath({ ssoAccountId, user });
|
||||
if (accountPath) {
|
||||
if (ssoConversationId) {
|
||||
return frontendURL(`${accountPath}/conversations/${ssoConversationId}`);
|
||||
}
|
||||
return frontendURL(`${accountPath}/dashboard`);
|
||||
}
|
||||
return DEFAULT_REDIRECT_URL;
|
||||
};
|
||||
|
|
|
@ -74,17 +74,37 @@ describe('#URL Helpers', () => {
|
|||
describe('getLoginRedirectURL', () => {
|
||||
it('should return correct Account URL if account id is present', () => {
|
||||
expect(
|
||||
getLoginRedirectURL('7500', {
|
||||
getLoginRedirectURL({
|
||||
ssoAccountId: '7500',
|
||||
user: {
|
||||
accounts: [{ id: 7500, name: 'Test Account 7500' }],
|
||||
},
|
||||
})
|
||||
).toBe('/app/accounts/7500/dashboard');
|
||||
});
|
||||
|
||||
it('should return default URL if account id is not present', () => {
|
||||
expect(getLoginRedirectURL('7500', {})).toBe('/app/');
|
||||
it('should return correct conversation URL if account id and conversationId is present', () => {
|
||||
expect(
|
||||
getLoginRedirectURL('7500', {
|
||||
getLoginRedirectURL({
|
||||
ssoAccountId: '7500',
|
||||
ssoConversationId: '752',
|
||||
user: {
|
||||
accounts: [{ id: 7500, name: 'Test Account 7500' }],
|
||||
},
|
||||
})
|
||||
).toBe('/app/accounts/7500/conversations/752');
|
||||
});
|
||||
|
||||
it('should return default URL if account id is not present', () => {
|
||||
expect(getLoginRedirectURL({ ssoAccountId: '7500', user: {} })).toBe(
|
||||
'/app/'
|
||||
);
|
||||
expect(
|
||||
getLoginRedirectURL({
|
||||
ssoAccountId: '7500',
|
||||
user: {
|
||||
accounts: [{ id: '7501', name: 'Test Account 7501' }],
|
||||
},
|
||||
})
|
||||
).toBe('/app/accounts/7501/dashboard');
|
||||
expect(getLoginRedirectURL('7500', null)).toBe('/app/');
|
||||
|
|
|
@ -80,7 +80,7 @@ export default {
|
|||
props: {
|
||||
ssoAuthToken: { type: String, default: '' },
|
||||
ssoAccountId: { type: String, default: '' },
|
||||
redirectUrl: { type: String, default: '' },
|
||||
ssoConversationId: { type: String, default: '' },
|
||||
config: { type: String, default: '' },
|
||||
email: { type: String, default: '' },
|
||||
},
|
||||
|
@ -139,6 +139,7 @@ export default {
|
|||
password: this.credentials.password,
|
||||
sso_auth_token: this.ssoAuthToken,
|
||||
ssoAccountId: this.ssoAccountId,
|
||||
ssoConversationId: this.ssoConversationId,
|
||||
};
|
||||
this.$store
|
||||
.dispatch('login', credentials)
|
||||
|
|
|
@ -11,8 +11,8 @@ export default {
|
|||
config: route.query.config,
|
||||
email: route.query.email,
|
||||
ssoAuthToken: route.query.sso_auth_token,
|
||||
redirectUrl: route.query.route_url,
|
||||
ssoAccountId: route.query.sso_account_id,
|
||||
ssoConversationId: route.query.sso_conversation_id,
|
||||
}),
|
||||
},
|
||||
],
|
||||
|
|
|
@ -84,12 +84,16 @@ export const getters = {
|
|||
|
||||
// actions
|
||||
export const actions = {
|
||||
login(_, { ssoAccountId, ...credentials }) {
|
||||
login(_, { ssoAccountId, ssoConversationId, ...credentials }) {
|
||||
return new Promise((resolve, reject) => {
|
||||
authAPI
|
||||
.login(credentials)
|
||||
.then(response => {
|
||||
window.location = getLoginRedirectURL(ssoAccountId, response.data);
|
||||
window.location = getLoginRedirectURL({
|
||||
ssoAccountId,
|
||||
ssoConversationId,
|
||||
user: response.data,
|
||||
});
|
||||
resolve();
|
||||
})
|
||||
.catch(error => {
|
||||
|
|
Loading…
Reference in a new issue