Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- handleClick() {
- fetch('/backend/login', {
- method: 'POST',
- headers: {
- 'Accept': 'application/json',
- 'Content-Type': 'application/json',
- },
- body: JSON.stringify({
- username: this.state.username,
- password: this.state.password
- })
- })
- .then(response =>{
- if (response.ok) {
- response.json().then(data => {
- sessionStorage.setItem('loggedIn', data.success);
- console.log('login success: ' + sessionStorage.getItem('loggedIn'));
- });
- }
- else {
- console.log('failed');
- }
- })
- }
- render () {
- <LinkContainer to='/Dashboard'>
- <Button onClick={this.handleClick} type="submit"> Submit />
- </Button>
- </LinkContainer>
- }
- function requireAuth(nextState, replace) {
- if (!(sessionStorage.getItem('loggedIn') === true)) {
- console.log(sessionStorage.getItem('loggedIn'));
- replace({
- pathname: '/',
- state: { nextPathname: nextState.location.pathname }
- });
- }
- }
- ReactDOM.render(
- <Router history={browserHistory}>
- <Route path="/" component={Container}>
- <IndexRoute component={Homepage}/>
- <Route path="dashboard" component={Dashboard} onEnter=
- {requireAuth}/>
- </Route>
- </Router>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement