github.com/cockroachdb/cockroach@v20.2.0-alpha.1+incompatible/pkg/ui/src/routes/login.tsx (about)

     1  // Copyright 2018 The Cockroach Authors.
     2  //
     3  // Use of this software is governed by the Business Source License
     4  // included in the file licenses/BSL.txt.
     5  //
     6  // As of the Change Date specified in that file, in accordance with
     7  // the Business Source License, use of this software will be governed
     8  // by the Apache License, Version 2.0, included in the file
     9  // licenses/APL.txt.
    10  
    11  import React from "react";
    12  import { Route, Redirect } from "react-router-dom";
    13  import { Store } from "redux";
    14  
    15  import { doLogout, selectLoginState } from "src/redux/login";
    16  import { AdminUIState } from "src/redux/state";
    17  import LoginPage from "src/views/login/loginPage";
    18  
    19  export const LOGIN_PAGE = "/login";
    20  export const LOGOUT_PAGE = "/logout";
    21  
    22  export function createLoginRoute() {
    23    return (
    24      <Route exact path={LOGIN_PAGE} component={ LoginPage } />
    25    );
    26  }
    27  
    28  export function createLogoutRoute(store: Store<AdminUIState>): JSX.Element {
    29    return (
    30      <Route exact path={LOGOUT_PAGE} render={() => {
    31        const loginState = selectLoginState(store.getState());
    32  
    33        if (!loginState.loggedInUser()) {
    34          return <Redirect to={LOGIN_PAGE} />;
    35        }
    36  
    37        store.dispatch(doLogout());
    38      }} />
    39    );
    40  }