Commit 0cb0e999 authored by Mai Thanh Cong's avatar Mai Thanh Cong

fix router when login

parent 305100c1
#config
REACT_APP_AWS_USER_POOL_ID = us-east-1_c1uad9xyt
REACT_APP_AWS_CLIENT_ID = 339mutkibblh97ojfjgti8gei7
REACT_APP_AQBITS_SERVER_URL = wss://ewcxwsv9hc.execute-api.us-east-1.amazonaws.com/development
REACT_APP_BASE_URL_AQBITS = https://wll3ump6p9.execute-api.us-east-1.amazonaws.com/api
\ No newline at end of file
REACT_APP_BASE_URL_AQBITS_TRACE_CODE = https://f26svz60d8.execute-api.us-east-1.amazonaws.com/api
\ No newline at end of file
import React, { useState, useEffect } from "react";
import ReactDOM from "react-dom";
import { BrowserRouter, HashRouter, Route, Switch, Redirect, useHistory } from "react-router-dom";
import "assets/vendor/nucleo/css/nucleo.css";
import "assets/vendor/font-awesome/css/font-awesome.min.css";
import "assets/scss/argon-design-system-react.scss?v1.1.0";
import AddProfile from "./components/Profile/AddProfile";
import Index from "views/Index.js";
import Landing from "views/examples/Landing.js";
import Login from "views/examples/Login.js";
import Profile from "views/examples/Profile.js";
import Register from "views/examples/Register.js";
import NotFound from "views/examples/NotFound.js"
import DetailProfile from "./components/Profile/DetailProfile.js"
import SearchProfile from "./components/Profile/SearchProfile.js";
import Tracecode from "./components/Profile/Tracecode.js"
import AddProduct from "components/Profile/AddProduct";
import Signin from "./services/Signin";
import Signup from "services/Signup";
import { authServices } from "./services/AuthServices";
import { Routes } from "reoutes";
// import { Routes } from "./reoutes";
const RouteWithLoader = ({ component: Component, ...rest }) => {
return (
<Route {...rest} render={props => authServices.isAuthenticated() === true ? <Component {...props} /> : <Redirect to={{ pathname: '/login-page' }} />} />
);
};
export default () => (
<Switch>
<Route exact path="/login-page" component={Signin} />
<RouteWithLoader exact path="/" component={SearchProfile} />
<RouteWithLoader exact path="/profile/add" component={AddProfile} />
<RouteWithLoader exact path="/profile/add-product" component={AddProduct} />
<RouteWithLoader exact path="/profile/:code" component={DetailProfile} />
<RouteWithLoader exact path="/trace-code/:trace" component={Tracecode} />
<RouteWithLoader exact path="/not-found" component={NotFound} />
{/* <Route path="/profile" exact render={props => <SearchProfile {...props} />} />
<Route
path="/profile/add"
exact
render={props => <AddProfile {...props} />}
/>
<Route
path="/profile/add-product"
exact
render={props => <AddProduct {...props} />}
/>
<Route
path="/trace-code/:trace"
exact
render={props => <Tracecode {...props} />}
/>
<Route
path="/profile/:code"
exact
render={props => <DetailProfile {...props} />}
/>
<Route
path="/not-found"
exact
render={props => <NotFound {...props} />}
/>
<Route
path="/landing-page"
exact
render={props => <Landing {...props} />}
/>
<Route
path="/signin"
exact
render={props => <Signin {...props} />} />
<Route
path="/profile-page"
exact
render={props => <Profile {...props} />}
/>
<Route
path="/signup"
exact
render={props => <Signup {...props} />}
/>
<Redirect to="/" /> */}
</Switch>
);
......@@ -38,6 +38,7 @@ import {
Col,
UncontrolledTooltip
} from "reactstrap";
import { authServices } from "../../services/AuthServices";
const DemoNavbar = () => {
// componentDidMount() {
......@@ -76,6 +77,11 @@ const DemoNavbar = () => {
}, []);
// render() {
const onHandleLogout = () => {
authServices.logout();
history.push("/login-page");
}
return (
<>
......@@ -197,12 +203,16 @@ const DemoNavbar = () => {
<DropdownItem to="/login-page" tag={Link}>
Đăng nhp
</DropdownItem>
<DropdownItem to="/register-page" tag={Link}>
{/* <DropdownItem to="/register-page" tag={Link}>
Đăng kí
</DropdownItem>
</DropdownItem> */}
<DropdownItem to="/" tag={Link}>
Tra cu thông tin
</DropdownItem>
<DropdownItem divider />
<DropdownItem onClick={onHandleLogout}>
Đăng xut
</DropdownItem>
</DropdownMenu>
</UncontrolledDropdown>
</Nav>
......
/*!
import React from 'react';
import ReactDOM from 'react-dom';
import { HashRouter } from "react-router-dom";
import { Provider } from "react-redux";
=========================================================
* Argon Design System React - v1.1.0
=========================================================
* Product Page: https://www.creative-tim.com/product/argon-design-system-react
* Copyright 2020 Creative Tim (https://www.creative-tim.com)
* Licensed under MIT (https://github.com/creativetimofficial/argon-design-system-react/blob/master/LICENSE.md)
* Coded by Creative Tim
=========================================================
* The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
*/
import React from "react";
import ReactDOM from "react-dom";
import { BrowserRouter, Route, Switch, Redirect } from "react-router-dom";
import "assets/vendor/nucleo/css/nucleo.css";
import "assets/vendor/font-awesome/css/font-awesome.min.css";
import "assets/scss/argon-design-system-react.scss?v1.1.0";
import AddProfile from "./components/Profile/AddProfile";
import Index from "views/Index.js";
import Landing from "views/examples/Landing.js";
import Login from "views/examples/Login.js";
import Profile from "views/examples/Profile.js";
import Register from "views/examples/Register.js";
import NotFound from "views/examples/NotFound.js"
import DetailProfile from "./components/Profile/DetailProfile.js"
import SearchProfile from "./components/Profile/SearchProfile.js";
import Tracecode from "./components/Profile/Tracecode.js"
import AddProduct from "components/Profile/AddProduct";
import Signin from "services/Signin";
import Signup from "services/Signup";
// import { Routes } from "./reoutes";
// import store from "./store";
import HomePage from "./HomePage";
ReactDOM.render(
<BrowserRouter>
<Switch>
<Route path="/" exact render={props => <SearchProfile {...props} />} />
<Route
path="/profile/add"
exact
render={props => <AddProfile {...props} />}
/>
<Route
path="/profile/add-product"
exact
render={props => <AddProduct {...props} />}
/>
<Route
path="/trace-code/:trace"
exact
render={props => <Tracecode {...props} />}
/>
<Route
path="/profile/:code"
exact
render={props => <DetailProfile {...props} />}
/>
<Route
path="/not-found"
exact
render={props => <NotFound {...props} />}
/>
<Route
path="/landing-page"
exact
render={props => <Landing {...props} />}
/>
<Route
path="/signin"
exact
render={props => <Signin {...props} />} />
<Route
path="/profile-page"
exact
render={props => <Profile {...props} />}
/>
<Route
path="/signup"
exact
render={props => <Signup {...props} />}
/>
<Redirect to="/" />
</Switch>
</BrowserRouter>,
<HashRouter>
<HomePage />
</HashRouter>,
document.getElementById("root")
);
......@@ -143,7 +143,11 @@ export const authServices = {
});
},
isAuthenticated: () => {
return localStorage.getItem("access_token") && localStorage.getItem("id_token");
if(localStorage.getItem("access_token") && localStorage.getItem("id_token")){
return true;
}else {
return false;
}
},
logout: () => {
localStorage.removeItem("access_token");
......
import axiosClient from "../NodeServices/index";
const END_POINT = "https://v9f109ai6i.execute-api.us-east-1.amazonaws.com/development";
export const getNodes = () => axiosClient.get(END_POINT);
import axiosClient from "../NodeServices/index";
const END_POINT = "https://np23gd0j54.execute-api.us-east-1.amazonaws.com/development";
export const getNodeHistory = (param) => axiosClient.get(END_POINT, { params: {node_id: param} });
......@@ -26,6 +26,7 @@ import {
// core components
import DemoNavbar from "components/Navbars/DemoNavbar.js";
import SimpleFooter from "components/Footers/SimpleFooter.js";
import MainBanner from "components/Generals/MainBanner";
export default () => {
......@@ -49,7 +50,7 @@ export default () => {
authServices
.login(email, password)
.then((rs) => {
history.push(Routes.Home.path);
history.push("/profile");
setCheckUser(false);
setLoading(false);
})
......@@ -69,7 +70,7 @@ export default () => {
authServices
.login(email, password)
.then((rs) => {
history.push(Routes.Home.path);
history.push("/profile");
setCheckUser(false);
setLoading(false);
})
......@@ -83,8 +84,9 @@ export default () => {
return (
<>
<DemoNavbar />
{/* <DemoNavbar /> */}
<main>
{/* <MainBanner /> */}
<section className="section section-shaped section-lg">
<div className="shape shape-style-1 bg-gradient-default">
<span />
......@@ -115,7 +117,7 @@ export default () => {
<i className="ni ni-email-83" />
</InputGroupText>
</InputGroupAddon>
<Input placeholder="Email" type="email"
<Input placeholder="Email" type="text"
value={email} onChange={(e) => setEmail(e.target.value)} {...validEmail ? "invalid" : ""} />
<FormFeedback valid>{validEmail}</FormFeedback>
</InputGroup>
......@@ -183,7 +185,7 @@ export default () => {
</Container>
</section>
</main>
<SimpleFooter />
{/* <SimpleFooter /> */}
</>
);
};
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment