Skip to content

Commit 8f3808c

Browse files
author
Sven
committed
Merge branch 'master' of github.com:YutHelloWorld/vortex-react
2 parents 257c0e5 + 9b3f91e commit 8f3808c

File tree

4 files changed

+14
-10
lines changed

4 files changed

+14
-10
lines changed

src/layouts/components/Navbar.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff 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>

src/routes/Login/components/Login.js

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff 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
)

src/routes/Login/containers/LoginContainer.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import Login from '../components/Login'
33
import { authenticateWithCb } from 'store/fakeAuth'
44

55
const mapStateToProps = (state) => ({
6-
6+
isAuthenticated: state.isAuthenticated
77
})
88

99
const mapDispatchToProps = {

src/store/fakeAuth.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff 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

3031
export default function (state = initialState, action) {
3132
const handler = ACTION_HANDLERS[action.type]

0 commit comments

Comments
 (0)