1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
5 import { Config } from './config';
7 const REDIRECT_TO_KEY = 'redirectTo';
9 export const storeRedirects = () => {
11 const { location: { href }, localStorage } = window;
13 if (href.indexOf(REDIRECT_TO_KEY) > -1) {
14 redirectUrl = href.split(`${REDIRECT_TO_KEY}=`)[1];
17 if (localStorage && redirectUrl) {
18 localStorage.setItem(REDIRECT_TO_KEY, redirectUrl);
22 export const handleRedirects = (token: string, config: Config) => {
23 const { localStorage } = window;
24 const { keepWebServiceUrl } = config;
26 if (localStorage && localStorage.getItem(REDIRECT_TO_KEY)) {
27 const redirectUrl = localStorage.getItem(REDIRECT_TO_KEY);
28 localStorage.removeItem(REDIRECT_TO_KEY);
31 const sep = redirectUrl.indexOf("?") > -1 ? "&" : "?";
32 window.location.href = `${keepWebServiceUrl}${redirectUrl}${sep}api_token=${token}`;