Skip to content
This repository has been archived by the owner on Feb 9, 2024. It is now read-only.

Commit

Permalink
Handle redirects on login page
Browse files Browse the repository at this point in the history
  • Loading branch information
alex-kovoy committed Jul 5, 2019
1 parent b123d7b commit c2147f4
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 33 deletions.
2 changes: 1 addition & 1 deletion web/src/cluster/components/Logs/Logs.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import cfg from 'app/config';
import LogViewer from 'app/components/LogViewer';
import LogProvider from './LogProvider';
import QueryEditorBasic from './QueryEditorBasic';
import { getUrlParameter } from 'app/services/browser';
import { getUrlParameter } from 'app/services/history';
import * as Alerts from 'shared/components/Alert';
import { Box, Flex, Input, ButtonSecondary } from 'shared/components';
import { Cog } from 'shared/components/Icon';
Expand Down
2 changes: 1 addition & 1 deletion web/src/components/Login/LoginFailed.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ limitations under the License.
*/

import React from 'react';
import { getUrlParameter } from 'app/services/browser';
import { getUrlParameter } from 'app/services/history';
import cfg from 'app/config';
import LogoHero from './../LogoHero';
import { LoginFailed as CardFailed} from 'shared/components/CardError';
Expand Down
23 changes: 15 additions & 8 deletions web/src/flux/user/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,12 @@ const logger = Logger.create('user/actions');

export function login(userId, password, token) {
const promise = auth.login(userId, password, token);
return _handleLoginPromise(promise);
return handleLoginPromise(promise);
}

export function loginWithU2f(userId, password) {
const promise = auth.loginWithU2f(userId, password);
return _handleLoginPromise(promise);
return handleLoginPromise(promise);
}

export function loginWithSso(providerName, redirectUrl) {
Expand All @@ -59,12 +59,7 @@ export function changePassword(oldPsw, newPsw, token){
return api.put(cfg.getSiteChangePasswordUrl(), data);
}

function getEntryRoute() {
const entryUrl = history.getRedirectParam();
return !entryUrl ? cfg.routes.app : entryUrl;
}

function _handleLoginPromise(promise) {
function handleLoginPromise(promise) {
return promise.done(() => {
const redirect = getEntryRoute();
const withPageRefresh = true;
Expand All @@ -73,4 +68,16 @@ function _handleLoginPromise(promise) {
.fail(err => {
logger.error('login', err);
});
}

function getEntryRoute() {
let entryUrl = history.getRedirectParam();
if (entryUrl) {
entryUrl = history.ensureKnownRoute(entryUrl);
} else {
entryUrl = cfg.routes.app;
}

return history.ensureBaseUrl(entryUrl);

}
17 changes: 1 addition & 16 deletions web/src/services/browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,4 @@ function detectPlatform() {
}
}

export function getUrlParameter(name, path) {
path = path || window.location.search;
const query = path.substring(1);
const vars = query.split('&');
for (var i = 0; i < vars.length; i++) {
var pair = vars[i].split('=');
if (decodeURIComponent(pair[0]) == name) {
return decodeURIComponent(pair[1]);
}
}

return '';
}

export const platform = detectPlatform();

export const platform = detectPlatform();
23 changes: 16 additions & 7 deletions web/src/services/history.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,7 @@ const history = {
},

getRedirectParam() {
let loc = this.original().location;
if (loc.query && loc.query.redirect_uri) {
return loc.query.redirect_uri;
}

return '';
return getUrlParameter('redirect_uri', this.original().location.search);
},

ensureKnownRoute(url) {
Expand Down Expand Up @@ -117,4 +112,18 @@ const match = url => route => {
})
}

export default history;
export default history;

export function getUrlParameter(name, path) {
path = path || window.location.search;
const query = path.substring(1);
const vars = query.split('&');
for (var i = 0; i < vars.length; i++) {
var pair = vars[i].split('=');
if (decodeURIComponent(pair[0]) == name) {
return decodeURIComponent(pair[1]);
}
}

return '';
}

0 comments on commit c2147f4

Please sign in to comment.