Skip to content

Commit 35e4a08

Browse files
committed
fix(login): make welcome screen able to login
1 parent 161bd78 commit 35e4a08

File tree

1 file changed

+38
-2
lines changed

1 file changed

+38
-2
lines changed

src/auth/screens/welcome.screen.js

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,31 @@
1+
/* eslint-disable no-shadow */
12
import React, { Component } from 'react';
23
import styled from 'styled-components';
4+
import { bindActionCreators } from 'redux';
35
import { connect } from 'react-redux';
46
import { ActivityIndicator } from 'react-native';
7+
import CookieManager from 'react-native-cookies';
58

9+
import { auth, getUser } from 'auth';
610
import { ViewContainer } from 'components';
711
import { colors, fonts, normalize } from 'config';
8-
import { t } from 'utils';
12+
import { t, resetNavigationTo } from 'utils';
913

1014
const mapStateToProps = state => ({
1115
locale: state.auth.locale,
1216
isLoggingIn: state.auth.isLoggingIn,
17+
isAuthenticated: state.auth.isAuthenticated,
1318
});
1419

20+
const mapDispatchToProps = dispatch =>
21+
bindActionCreators(
22+
{
23+
auth,
24+
getUser,
25+
},
26+
dispatch
27+
);
28+
1529
const Container = styled.View`
1630
flex: 1;
1731
justify-content: center;
@@ -30,8 +44,30 @@ class Welcome extends Component {
3044
props: {
3145
locale: string,
3246
isLoggingIn: boolean,
47+
isAuthenticated: boolean,
48+
auth: Function,
49+
getUser: Function,
50+
navigation: Object,
3351
};
3452

53+
componentDidMount() {
54+
const { isAuthenticated, navigation, auth, getUser } = this.props;
55+
const { code, state } = navigation.state.params;
56+
57+
if (isAuthenticated) {
58+
resetNavigationTo('Main', navigation);
59+
} else {
60+
CookieManager.clearAll().then(() => {
61+
auth(code, state).then(() => {
62+
getUser().then(() => {
63+
console.log('resetNavigationTo Main');
64+
resetNavigationTo('Main', navigation);
65+
});
66+
});
67+
});
68+
}
69+
}
70+
3571
render() {
3672
const { locale, isLoggingIn } = this.props;
3773

@@ -46,4 +82,4 @@ class Welcome extends Component {
4682
}
4783
}
4884

49-
export const WelcomeScreen = connect(mapStateToProps)(Welcome);
85+
export const WelcomeScreen = connect(mapStateToProps, mapDispatchToProps)(Welcome);

0 commit comments

Comments
 (0)