File tree Expand file tree Collapse file tree 4 files changed +14
-10
lines changed
Expand file tree Collapse file tree 4 files changed +14
-10
lines changed Original file line number Diff line number Diff line change @@ -17,6 +17,12 @@ export default class CustomNavbar extends Component {
1717 isOpen : ! this . state . isOpen
1818 } )
1919 }
20+
21+ signOut = ( ) => {
22+ this . props . signOut ( )
23+ localStorage . setItem ( 'LoginState' , 'false' )
24+ }
25+
2026 render ( ) {
2127 return (
2228 < Navbar color = "faded" light toggleable >
@@ -29,7 +35,7 @@ export default class CustomNavbar extends Component {
2935 < NavLink to = "/elapse" tag = { Link } > Elapse</ NavLink >
3036 < NavLink to = "/route/8080" tag = { Link } > Route</ NavLink >
3137 < NavLink to = "/pageNotFound" tag = { Link } > 404</ NavLink >
32- < NavLink href = "javascript:;" onClick = { this . props . signOut } > Sign out</ NavLink >
38+ < NavLink href = "javascript:;" onClick = { this . signOut } > Sign out</ NavLink >
3339 < NavLink href = "https://github.com/YutHelloWorld/vortex-react" > Github</ NavLink >
3440 </ Nav >
3541 </ Collapse >
Original file line number Diff line number Diff line change @@ -7,23 +7,20 @@ export default class Login extends Component {
77 static propTypes = {
88 authenticateWithCb : PropTypes . func . isRequired ,
99 location : PropTypes . object . isRequired ,
10- }
11-
12- state = {
13- redirectToReferrer : false
10+ isAuthenticated : PropTypes . bool . isRequired ,
1411 }
1512
1613 login = ( ) => {
1714 this . props . authenticateWithCb ( ( ) => {
18- this . setState ( { redirectToReferrer : true } )
15+ localStorage . setItem ( 'LoginState' , ' true' )
1916 } )
2017 }
2118
2219 render ( ) {
2320 const { from } = this . props . location . state || { from : { pathname : '/' } }
24- const { redirectToReferrer } = this . state
21+ const { isAuthenticated } = this . props
2522
26- if ( redirectToReferrer ) {
23+ if ( isAuthenticated ) {
2724 return (
2825 < Redirect to = { from } />
2926 )
Original file line number Diff line number Diff line change @@ -3,7 +3,7 @@ import Login from '../components/Login'
33import { authenticateWithCb } from 'store/fakeAuth'
44
55const mapStateToProps = ( state ) => ( {
6-
6+ isAuthenticated : state . isAuthenticated
77} )
88
99const mapDispatchToProps = {
Original file line number Diff line number Diff line change @@ -25,7 +25,8 @@ const ACTION_HANDLERS = {
2525 [ SIGN_OUT ] : state => false ,
2626}
2727
28- const initialState = false
28+ const initialState = ! ( localStorage . getItem ( 'LoginState' ) == null ||
29+ localStorage . getItem ( 'LoginState' ) === 'false' )
2930
3031export default function ( state = initialState , action ) {
3132 const handler = ACTION_HANDLERS [ action . type ]
You can’t perform that action at this time.
0 commit comments