source: client_app/src/components/main/App.js@ 6f9b7b0

Last change on this file since 6f9b7b0 was 6f9b7b0, checked in by i-ina <76742075+i-ina@…>, 3 years ago

user login

  • Property mode set to 100644
File size: 1.7 KB
Line 
1import React, {Component} from 'react';
2import {BrowserRouter as Router, Route, Redirect} from 'react-router-dom';
3import Login from '../login/login';
4import Profile from "../data/profile";
5import 'semantic-ui-css/semantic.min.css';
6import HeaderComp from '../template/header';
7import './App.css';
8import UserLogin from "../../repository/login_repo";
9
10class App extends Component{
11 constructor(props) {
12 super(props);
13 this.state = {
14 logged: false,
15 error: null,
16 currentUser: {}
17 }
18 }
19
20 render(){
21 return(
22 <Router>
23 <HeaderComp acc={this.state.currentUser.email} accType={this.state.currentUser.type} name={this.state.currentUser.name}/>
24 <main>
25 <Route path={"/login"} render={() => <Login error={this.state.error} onCompleteForm={this.attemptLogin} loggedIn={this.state.logged}/>}/>
26 <Route path={"/profile"} render={() => <Profile userProfile={this.state.currentUser}/>}/>
27 <Route path={"/"} render={() => <Redirect to={"/login"}/>}/>
28 </main>
29 </Router>
30 );
31 }
32
33 attemptLogin = (email, password, type) => {
34 UserLogin.login(email, password, type).then((res) =>{
35 console.log(res.data);
36 if(res.data.email==null){
37 this.setState({
38 logged: false,
39 error: res.data.error,
40 });
41 }else{
42 this.setState({
43 logged: true,
44 currentUser: res.data,
45 error: null,
46 });
47 }
48 });
49
50 if(this.state.currentUser.email!=null){
51 return <Redirect to={"/profile"}/>;
52 }
53 }
54}
55
56export default App;
Note: See TracBrowser for help on using the repository browser.