1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
5 import { Redirect, RouteProps } from "react-router";
6 import * as React from "react";
7 import { connect, DispatchProp } from "react-redux";
8 import authActions from "../../store/auth/auth-action";
9 import { authService, projectService } from "../../services/services";
11 interface ApiTokenProps {
14 class ApiToken extends React.Component<ApiTokenProps & RouteProps & DispatchProp<any>, {}> {
15 static getUrlParameter(search: string, name: string) {
16 const safeName = name.replace(/[\[]/, '\\[').replace(/[\]]/, '\\]');
17 const regex = new RegExp('[\\?&]' + safeName + '=([^&#]*)');
18 const results = regex.exec(search);
19 return results === null ? '' : decodeURIComponent(results[1].replace(/\+/g, ' '));
23 const search = this.props.location ? this.props.location.search : "";
24 const apiToken = ApiToken.getUrlParameter(search, 'api_token');
25 this.props.dispatch(authActions.SAVE_API_TOKEN(apiToken));
26 this.props.dispatch(authService.getUserDetails());
27 this.props.dispatch(projectService.getProjectList());
30 return <Redirect to="/"/>
34 export default connect()(ApiToken);