Skip to content

Commit 817ffc5

Browse files
committed
promise chaining
1 parent f3d2ec4 commit 817ffc5

File tree

2 files changed

+36
-56
lines changed

2 files changed

+36
-56
lines changed

src/components/SignIn/index.js

Lines changed: 27 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -105,20 +105,15 @@ class SignInGoogleBase extends Component {
105105
.doSignInWithGoogle()
106106
.then(socialAuthUser => {
107107
// Create a user in your Firebase Realtime Database too
108-
this.props.firebase
109-
.user(socialAuthUser.user.uid)
110-
.set({
111-
username: socialAuthUser.user.displayName,
112-
email: socialAuthUser.user.email,
113-
roles: [],
114-
})
115-
.then(() => {
116-
this.setState({ error: null });
117-
this.props.history.push(ROUTES.HOME);
118-
})
119-
.catch(error => {
120-
this.setState({ error });
121-
});
108+
return this.props.firebase.user(socialAuthUser.user.uid).set({
109+
username: socialAuthUser.user.displayName,
110+
email: socialAuthUser.user.email,
111+
roles: [],
112+
});
113+
})
114+
.then(() => {
115+
this.setState({ error: null });
116+
this.props.history.push(ROUTES.HOME);
122117
})
123118
.catch(error => {
124119
if (error.code === ERROR_CODE_ACCOUNT_EXISTS) {
@@ -156,20 +151,15 @@ class SignInFacebookBase extends Component {
156151
.doSignInWithFacebook()
157152
.then(socialAuthUser => {
158153
// Create a user in your Firebase Realtime Database too
159-
this.props.firebase
160-
.user(socialAuthUser.user.uid)
161-
.set({
162-
username: socialAuthUser.additionalUserInfo.profile.name,
163-
email: socialAuthUser.additionalUserInfo.profile.email,
164-
roles: [],
165-
})
166-
.then(() => {
167-
this.setState({ error: null });
168-
this.props.history.push(ROUTES.HOME);
169-
})
170-
.catch(error => {
171-
this.setState({ error });
172-
});
154+
return this.props.firebase.user(socialAuthUser.user.uid).set({
155+
username: socialAuthUser.additionalUserInfo.profile.name,
156+
email: socialAuthUser.additionalUserInfo.profile.email,
157+
roles: [],
158+
});
159+
})
160+
.then(() => {
161+
this.setState({ error: null });
162+
this.props.history.push(ROUTES.HOME);
173163
})
174164
.catch(error => {
175165
if (error.code === ERROR_CODE_ACCOUNT_EXISTS) {
@@ -207,20 +197,15 @@ class SignInTwitterBase extends Component {
207197
.doSignInWithTwitter()
208198
.then(socialAuthUser => {
209199
// Create a user in your Firebase Realtime Database too
210-
this.props.firebase
211-
.user(socialAuthUser.user.uid)
212-
.set({
213-
username: socialAuthUser.additionalUserInfo.profile.name,
214-
email: socialAuthUser.additionalUserInfo.profile.email,
215-
roles: [],
216-
})
217-
.then(() => {
218-
this.setState({ error: null });
219-
this.props.history.push(ROUTES.HOME);
220-
})
221-
.catch(error => {
222-
this.setState({ error });
223-
});
200+
return this.props.firebase.user(socialAuthUser.user.uid).set({
201+
username: socialAuthUser.additionalUserInfo.profile.name,
202+
email: socialAuthUser.additionalUserInfo.profile.email,
203+
roles: [],
204+
});
205+
})
206+
.then(() => {
207+
this.setState({ error: null });
208+
this.props.history.push(ROUTES.HOME);
224209
})
225210
.catch(error => {
226211
if (error.code === ERROR_CODE_ACCOUNT_EXISTS) {

src/components/SignUp/index.js

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -50,20 +50,15 @@ class SignUpFormBase extends Component {
5050
.doCreateUserWithEmailAndPassword(email, passwordOne)
5151
.then(authUser => {
5252
// Create a user in your Firebase realtime database
53-
this.props.firebase
54-
.user(authUser.user.uid)
55-
.set({
56-
username,
57-
email,
58-
roles,
59-
})
60-
.then(() => {
61-
this.setState({ ...INITIAL_STATE });
62-
this.props.history.push(ROUTES.HOME);
63-
})
64-
.catch(error => {
65-
this.setState({ error });
66-
});
53+
return this.props.firebase.user(authUser.user.uid).set({
54+
username,
55+
email,
56+
roles,
57+
});
58+
})
59+
.then(() => {
60+
this.setState({ ...INITIAL_STATE });
61+
this.props.history.push(ROUTES.HOME);
6762
})
6863
.catch(error => {
6964
if (error.code === ERROR_CODE_ACCOUNT_EXISTS) {

0 commit comments

Comments
 (0)