質問編集履歴

1

実際のコードを修正

2020/08/07 11:23

投稿

_taizo
_taizo

スコア1

test CHANGED
File without changes
test CHANGED
@@ -28,35 +28,105 @@
28
28
 
29
29
  ```javascript
30
30
 
31
- console.log('twitter');
31
+ const {RNTwitterSignIn} = NativeModules;
32
32
 
33
- await RNTwitterSignIn.init(
33
+ const TwitterKeys = {
34
34
 
35
- TwitterKeys.TWITTER_CONSUMER_KEY,
35
+ TWITTER_CONSUMER_KEY: 'TWITTER_CONSUMER_KEY',
36
36
 
37
- TwitterKeys.TWITTER_CONSUMER_SECRET,
37
+ TWITTER_CONSUMER_SECRET: 'TWITTER_CONSUMER_SECRET',
38
38
 
39
- );
39
+ };
40
-
41
- console.log('twitter2');
42
40
 
43
41
 
44
42
 
45
- // Also returns: name, userID & userName
43
+ _socialSignIn = async providerId => {
46
44
 
47
- const {authToken, authTokenSecret} = await RNTwitterSignIn.logIn();
45
+ try {
48
46
 
47
+ const credential = await getCredential(providerId);
48
+
49
+ await auth()
50
+
51
+ .signInWithCredential(credential)
52
+
53
+ .then(res => {
54
+
55
+ let userData = {
56
+
57
+ uid: res.user.uid,
58
+
59
+ displayName: res.user.displayName,
60
+
61
+ email: res.user.providerData[0].email,
62
+
63
+ photoURL: res.user.photoURL,
64
+
65
+ // userID: res.additionalUserInfo.username,
66
+
67
+ created_at: Date.now(),
68
+
69
+ updated_at: Date.now(),
70
+
71
+ };
72
+
73
+ if (res.additionalUserInfo.isNewUser) {
74
+
75
+ return firestore()
76
+
49
- console.log('twitter3');
77
+ .collection('users')
78
+
79
+ .doc(res.user.uid)
80
+
81
+ .set(userData);
82
+
83
+ }
50
84
 
51
85
 
52
86
 
53
- credential = auth.TwitterAuthProvider.credential(
87
+ this.props.globalState.setUserData(userData);
54
88
 
55
- authToken,
89
+ })
56
90
 
57
- authTokenSecret,
91
+ .then(() => {
58
92
 
93
+ console.log('success');
94
+
95
+ })
96
+
97
+ .catch(err => {
98
+
99
+ console.log(err);
100
+
101
+ });
102
+
103
+
104
+
105
+ this.props.navigation.navigate('App');
106
+
107
+ } catch (e) {
108
+
109
+ if (e.code === 'auth/account-exists-with-different-credential') {
110
+
111
+ Alert.alert(
112
+
113
+ 'ログインエラー',
114
+
115
+ '他のログイン方法で\nアカウント登録されています',
116
+
117
+ [{text: 'OK', onPress: () => console.log('OK Pressed')}],
118
+
59
- );
119
+ );
120
+
121
+ }
122
+
123
+ console.log(e.message);
124
+
125
+ }
126
+
127
+ };
128
+
129
+ }
60
130
 
61
131
  ```
62
132