1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
5 import { RouteProps } from "react-router";
6 import React from "react";
7 import { RootState } from "store/store";
8 import { connect, DispatchProp } from "react-redux";
9 import { saveApiToken } from "store/auth/auth-action";
10 import { getUrlParameter } from "common/url";
11 import { AuthService } from "services/auth-service/auth-service";
12 import { navigateToRootProject, navigateToLinkAccount } from "store/navigation/navigation-action";
13 import { Config } from "common/config";
14 import { getAccountLinkData } from "store/link-account-panel/link-account-panel-actions";
15 import { replace } from "react-router-redux";
16 import { User } from "models/user";
18 interface ApiTokenProps {
19 authService: AuthService;
25 export const ApiToken = connect((state: RootState) => ({
26 user: state.auth.user,
28 class extends React.Component<ApiTokenProps & RouteProps & DispatchProp<any>, {}> {
30 const search = this.props.location ? this.props.location.search : "";
31 const apiToken = getUrlParameter(search, 'api_token');
32 this.props.dispatch<any>(saveApiToken(apiToken));
35 componentDidUpdate() {
36 const redirectURL = this.props.authService.getTargetURL();
38 if (this.props.loadMainApp && this.props.user) {
40 this.props.authService.removeTargetURL();
41 this.props.dispatch(replace(redirectURL));
43 else if (this.props.dispatch(getAccountLinkData())) {
44 this.props.dispatch(navigateToLinkAccount);
47 this.props.dispatch(navigateToRootProject);