1
- import React , { findDOMNode } from 'react' ;
2
- import { Router , Route , Link , History } from 'react-router' ;
1
+ import React , { findDOMNode } from 'react'
2
+ import { Router , Route , Link , History } from 'react-router'
3
3
import { createHistory , useBasename } from 'history'
4
- import auth from './auth' ;
4
+ import auth from './auth'
5
5
6
6
const history = useBasename ( createHistory ) ( {
7
7
basename : '/auth-flow'
@@ -11,18 +11,18 @@ var App = React.createClass({
11
11
getInitialState ( ) {
12
12
return {
13
13
loggedIn : auth . loggedIn ( )
14
- } ;
14
+ }
15
15
} ,
16
16
17
17
updateAuth ( loggedIn ) {
18
18
this . setState ( {
19
19
loggedIn : loggedIn
20
- } ) ;
20
+ } )
21
21
} ,
22
22
23
23
componentWillMount ( ) {
24
- auth . onChange = this . updateAuth ;
25
- auth . login ( ) ;
24
+ auth . onChange = this . updateAuth
25
+ auth . login ( )
26
26
} ,
27
27
28
28
render ( ) {
@@ -41,51 +41,51 @@ var App = React.createClass({
41
41
</ ul >
42
42
{ this . props . children }
43
43
</ div >
44
- ) ;
44
+ )
45
45
}
46
- } ) ;
46
+ } )
47
47
48
48
var Dashboard = React . createClass ( {
49
49
render ( ) {
50
- var token = auth . getToken ( ) ;
50
+ var token = auth . getToken ( )
51
51
52
52
return (
53
53
< div >
54
54
< h1 > Dashboard</ h1 >
55
55
< p > You made it!</ p >
56
56
< p > { token } </ p >
57
57
</ div >
58
- ) ;
58
+ )
59
59
}
60
- } ) ;
60
+ } )
61
61
62
62
var Login = React . createClass ( {
63
63
mixins : [ History ] ,
64
64
65
65
getInitialState ( ) {
66
66
return {
67
67
error : false
68
- } ;
68
+ }
69
69
} ,
70
70
71
71
handleSubmit ( event ) {
72
- event . preventDefault ( ) ;
72
+ event . preventDefault ( )
73
73
74
- var email = findDOMNode ( this . refs . email ) . value ;
75
- var pass = findDOMNode ( this . refs . pass ) . value ;
74
+ var email = findDOMNode ( this . refs . email ) . value
75
+ var pass = findDOMNode ( this . refs . pass ) . value
76
76
77
77
auth . login ( email , pass , ( loggedIn ) => {
78
78
if ( ! loggedIn )
79
- return this . setState ( { error : true } ) ;
79
+ return this . setState ( { error : true } )
80
80
81
- var { location } = this . props ;
81
+ var { location } = this . props
82
82
83
83
if ( location . state && location . state . nextPathname ) {
84
- this . history . replaceState ( null , location . state . nextPathname ) ;
84
+ this . history . replaceState ( null , location . state . nextPathname )
85
85
} else {
86
- this . history . replaceState ( null , '/about' ) ;
86
+ this . history . replaceState ( null , '/about' )
87
87
}
88
- } ) ;
88
+ } )
89
89
} ,
90
90
91
91
render ( ) {
@@ -98,29 +98,29 @@ var Login = React.createClass({
98
98
< p > Bad login information</ p >
99
99
) }
100
100
</ form >
101
- ) ;
101
+ )
102
102
}
103
- } ) ;
103
+ } )
104
104
105
105
var About = React . createClass ( {
106
106
render ( ) {
107
- return < h1 > About</ h1 > ;
107
+ return < h1 > About</ h1 >
108
108
}
109
- } ) ;
109
+ } )
110
110
111
111
var Logout = React . createClass ( {
112
112
componentDidMount ( ) {
113
- auth . logout ( ) ;
113
+ auth . logout ( )
114
114
} ,
115
115
116
116
render ( ) {
117
- return < p > You are now logged out</ p > ;
117
+ return < p > You are now logged out</ p >
118
118
}
119
- } ) ;
119
+ } )
120
120
121
121
function requireAuth ( nextState , replaceState ) {
122
122
if ( ! auth . loggedIn ( ) )
123
- replaceState ( { nextPathname : nextState . location . pathname } , '/login' ) ;
123
+ replaceState ( { nextPathname : nextState . location . pathname } , '/login' )
124
124
}
125
125
126
126
React . render ( (
@@ -132,4 +132,4 @@ React.render((
132
132
< Route path = "dashboard" component = { Dashboard } onEnter = { requireAuth } />
133
133
</ Route >
134
134
</ Router >
135
- ) , document . getElementById ( 'example' ) ) ;
135
+ ) , document . getElementById ( 'example' ) )
0 commit comments