@@ -52,7 +52,7 @@ When the user presses the pre-rendered button, we can trigger the initial sign-i
52
52
passing in the scope required for our application:
53
53
54
54
``` js
55
- import auth from ' @react-native-firebase/auth' ;
55
+ import auth , { getAuth } from ' @react-native-firebase/auth' ;
56
56
import { appleAuth } from ' @invertase/react-native-apple-authentication' ;
57
57
58
58
async function onAppleButtonPress () {
@@ -74,7 +74,7 @@ async function onAppleButtonPress() {
74
74
const appleCredential = auth .AppleAuthProvider .credential (identityToken, nonce);
75
75
76
76
// Sign the user in with the credential
77
- return auth ().signInWithCredential (appleCredential);
77
+ return getAuth ().signInWithCredential (appleCredential);
78
78
}
79
79
```
80
80
@@ -84,7 +84,7 @@ with the new authentication state of the user.
84
84
Apple also requires that the app revoke the ` Sign in with Apple ` token when the user chooses to delete their account. This can be accomplished with the ` revokeToken ` API.
85
85
86
86
``` js
87
- import auth from ' @react-native-firebase/auth' ;
87
+ import { getAuth } from ' @react-native-firebase/auth' ;
88
88
import { appleAuth } from ' @invertase/react-native-apple-authentication' ;
89
89
90
90
async function revokeSignInWithAppleToken () {
@@ -99,7 +99,7 @@ async function revokeSignInWithAppleToken() {
99
99
}
100
100
101
101
// Revoke the token
102
- return auth ().revokeToken (authorizationCode);
102
+ return getAuth ().revokeToken (authorizationCode);
103
103
}
104
104
```
105
105
@@ -134,7 +134,7 @@ function FacebookSignIn() {
134
134
The ` onFacebookButtonPress ` can then be implemented as follows:
135
135
136
136
``` js
137
- import auth from ' @react-native-firebase/auth' ;
137
+ import auth , { getAuth } from ' @react-native-firebase/auth' ;
138
138
import { LoginManager , AccessToken } from ' react-native-fbsdk-next' ;
139
139
140
140
async function onFacebookButtonPress () {
@@ -156,7 +156,7 @@ async function onFacebookButtonPress() {
156
156
const facebookCredential = auth .FacebookAuthProvider .credential (data .accessToken );
157
157
158
158
// Sign-in the user with the credential
159
- return auth ().signInWithCredential (facebookCredential);
159
+ return getAuth ().signInWithCredential (facebookCredential);
160
160
}
161
161
```
162
162
@@ -165,7 +165,7 @@ async function onFacebookButtonPress() {
165
165
To use Facebook Limited Login instead of "classic" Facebook Login, the ` onFacebookButtonPress ` can then be implemented as follows:
166
166
167
167
``` js
168
- import auth from ' @react-native-firebase/auth' ;
168
+ import auth , { getAuth } from ' @react-native-firebase/auth' ;
169
169
import { LoginManager , AuthenticationToken } from ' react-native-fbsdk-next' ;
170
170
import { sha256 } from ' react-native-sha256' ;
171
171
@@ -197,7 +197,65 @@ async function onFacebookButtonPress() {
197
197
const facebookCredential = auth .FacebookAuthProvider .credential (data .authenticationToken , nonce);
198
198
199
199
// Sign-in the user with the credential
200
- return auth ().signInWithCredential (facebookCredential);
200
+ return getAuth ().signInWithCredential (facebookCredential);
201
+ }
202
+ ```
203
+
204
+ Upon successful sign-in, any [ ` onAuthStateChanged ` ] ( /auth/usage#listening-to-authentication-state ) listeners will trigger
205
+ with the new authentication state of the user.
206
+
207
+ ## Twitter
208
+
209
+ Using the external [ ` @react-native-twitter-signin/twitter-signin ` ] ( https://github.com/react-native-twitter-signin/twitter-signin ) library,
210
+ we can sign-in the user with Twitter and generate a credential which can be used to sign-in with Firebase.
211
+
212
+ To get started, install the library and ensure you have completed setup, following the required [ prerequisites] ( https://github.com/react-native-twitter-signin/twitter-signin#prerequisites ) list.
213
+
214
+ Ensure the "Twitter" sign-in provider is enabled on the [ Firebase Console] ( https://console.firebase.google.com/project/_/authentication/providers ) .
215
+
216
+ Before triggering a sign-in request, you must initialize the Twitter SDK using your accounts consumer key & secret:
217
+
218
+ ``` js
219
+ import { NativeModules } from ' react-native' ;
220
+ const { RNTwitterSignIn } = NativeModules;
221
+
222
+ RNTwitterSignIn .init (' TWITTER_CONSUMER_KEY' , ' TWITTER_CONSUMER_SECRET' ).then (() =>
223
+ console .log (' Twitter SDK initialized' ),
224
+ );
225
+ ```
226
+
227
+ Once initialized, setup your application to trigger a sign-in request with Twitter using the ` login ` method.
228
+
229
+ ``` jsx
230
+ import React from ' react' ;
231
+ import { Button } from ' react-native' ;
232
+
233
+ function TwitterSignIn () {
234
+ return (
235
+ < Button
236
+ title= " Twitter Sign-In"
237
+ onPress= {() => onTwitterButtonPress ().then (() => console .log (' Signed in with Twitter!' ))}
238
+ / >
239
+ );
240
+ }
241
+ ```
242
+
243
+ The ` onTwitterButtonPress ` can then be implemented as follows:
244
+
245
+ ``` js
246
+ import auth , { getAuth } from ' @react-native-firebase/auth' ;
247
+ import { NativeModules } from ' react-native' ;
248
+ const { RNTwitterSignIn } = NativeModules;
249
+
250
+ async function onTwitterButtonPress () {
251
+ // Perform the login request
252
+ const { authToken , authTokenSecret } = await RNTwitterSignIn .logIn ();
253
+
254
+ // Create a Twitter credential with the tokens
255
+ const twitterCredential = auth .TwitterAuthProvider .credential (authToken, authTokenSecret);
256
+
257
+ // Sign-in the user with the credential
258
+ return getAuth ().signInWithCredential (twitterCredential);
201
259
}
202
260
```
203
261
@@ -250,7 +308,7 @@ function GoogleSignIn() {
250
308
The ` onGoogleButtonPress ` can then be implemented as follows:
251
309
252
310
``` js
253
- import auth from ' @react-native-firebase/auth' ;
311
+ import auth , { getAuth } from ' @react-native-firebase/auth' ;
254
312
import { GoogleSignin } from ' @react-native-google-signin/google-signin' ;
255
313
256
314
async function onGoogleButtonPress () {
@@ -273,7 +331,7 @@ async function onGoogleButtonPress() {
273
331
const googleCredential = auth .GoogleAuthProvider .credential (signInResult .data .idToken );
274
332
275
333
// Sign-in the user with the credential
276
- return auth ().signInWithCredential (googleCredential);
334
+ return getAuth ().signInWithCredential (googleCredential);
277
335
}
278
336
` ` `
279
337
@@ -310,7 +368,7 @@ function MicrosoftSignIn() {
310
368
` onMicrosoftButtonPress` can be implemented as the following:
311
369
312
370
` ` ` js
313
- import auth from ' @react-native-firebase/auth' ;
371
+ import auth , { getAuth } from ' @react-native-firebase/auth' ;
314
372
315
373
const onMicrosoftButtonPress = async () => {
316
374
// Generate the provider object
@@ -327,7 +385,7 @@ const onMicrosoftButtonPress = async () => {
327
385
});
328
386
329
387
// Sign-in the user with the provider
330
- return auth ().signInWithRedirect (provider);
388
+ return getAuth ().signInWithRedirect (provider);
331
389
};
332
390
` ` `
333
391
@@ -406,7 +464,7 @@ To achieve this, you should replace sign-in method in any of the supported socia
406
464
This code demonstrates linking a Google provider to an account that is already signed in using Firebase authentication.
407
465
408
466
` ` ` js
409
- import auth from ' @react-native-firebase/auth' ;
467
+ import auth , { getAuth } from ' @react-native-firebase/auth' ;
410
468
import { GoogleSignin } from ' @react-native-google-signin/google-signin' ;
411
469
412
470
async function onGoogleLinkButtonPress () {
@@ -419,7 +477,7 @@ async function onGoogleLinkButtonPress() {
419
477
const googleCredential = auth .GoogleAuthProvider .credential (idToken);
420
478
421
479
// Link the user's account with the Google credential
422
- const firebaseUserCredential = await auth ().currentUser .linkWithCredential (googleCredential);
480
+ const firebaseUserCredential = await getAuth ().currentUser .linkWithCredential (googleCredential);
423
481
// Handle the linked account as needed in your app
424
482
return ;
425
483
}
0 commit comments