@@ -52,7 +52,7 @@ When the user presses the pre-rendered button, we can trigger the initial sign-i
5252passing in the scope required for our application:
5353
5454``` js
55- import auth from ' @react-native-firebase/auth' ;
55+ import auth , { getAuth } from ' @react-native-firebase/auth' ;
5656import { appleAuth } from ' @invertase/react-native-apple-authentication' ;
5757
5858async function onAppleButtonPress () {
@@ -74,7 +74,7 @@ async function onAppleButtonPress() {
7474 const appleCredential = auth .AppleAuthProvider .credential (identityToken, nonce);
7575
7676 // Sign the user in with the credential
77- return auth ().signInWithCredential (appleCredential);
77+ return getAuth ().signInWithCredential (appleCredential);
7878}
7979```
8080
@@ -84,7 +84,7 @@ with the new authentication state of the user.
8484Apple 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.
8585
8686``` js
87- import auth from ' @react-native-firebase/auth' ;
87+ import { getAuth } from ' @react-native-firebase/auth' ;
8888import { appleAuth } from ' @invertase/react-native-apple-authentication' ;
8989
9090async function revokeSignInWithAppleToken () {
@@ -99,7 +99,7 @@ async function revokeSignInWithAppleToken() {
9999 }
100100
101101 // Revoke the token
102- return auth ().revokeToken (authorizationCode);
102+ return getAuth ().revokeToken (authorizationCode);
103103}
104104```
105105
@@ -134,7 +134,7 @@ function FacebookSignIn() {
134134The ` onFacebookButtonPress ` can then be implemented as follows:
135135
136136``` js
137- import auth from ' @react-native-firebase/auth' ;
137+ import auth , { getAuth } from ' @react-native-firebase/auth' ;
138138import { LoginManager , AccessToken } from ' react-native-fbsdk-next' ;
139139
140140async function onFacebookButtonPress () {
@@ -156,7 +156,7 @@ async function onFacebookButtonPress() {
156156 const facebookCredential = auth .FacebookAuthProvider .credential (data .accessToken );
157157
158158 // Sign-in the user with the credential
159- return auth ().signInWithCredential (facebookCredential);
159+ return getAuth ().signInWithCredential (facebookCredential);
160160}
161161```
162162
@@ -165,7 +165,7 @@ async function onFacebookButtonPress() {
165165To use Facebook Limited Login instead of "classic" Facebook Login, the ` onFacebookButtonPress ` can then be implemented as follows:
166166
167167``` js
168- import auth from ' @react-native-firebase/auth' ;
168+ import auth , { getAuth } from ' @react-native-firebase/auth' ;
169169import { LoginManager , AuthenticationToken } from ' react-native-fbsdk-next' ;
170170import { sha256 } from ' react-native-sha256' ;
171171
@@ -197,7 +197,65 @@ async function onFacebookButtonPress() {
197197 const facebookCredential = auth .FacebookAuthProvider .credential (data .authenticationToken , nonce);
198198
199199 // 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);
201259}
202260```
203261
@@ -250,7 +308,7 @@ function GoogleSignIn() {
250308The ` onGoogleButtonPress ` can then be implemented as follows:
251309
252310``` js
253- import auth from ' @react-native-firebase/auth' ;
311+ import auth , { getAuth } from ' @react-native-firebase/auth' ;
254312import { GoogleSignin } from ' @react-native-google-signin/google-signin' ;
255313
256314async function onGoogleButtonPress () {
@@ -273,7 +331,7 @@ async function onGoogleButtonPress() {
273331 const googleCredential = auth .GoogleAuthProvider .credential (signInResult .data .idToken );
274332
275333 // Sign-in the user with the credential
276- return auth ().signInWithCredential (googleCredential);
334+ return getAuth ().signInWithCredential (googleCredential);
277335}
278336` ` `
279337
@@ -310,7 +368,7 @@ function MicrosoftSignIn() {
310368` onMicrosoftButtonPress` can be implemented as the following:
311369
312370` ` ` js
313- import auth from ' @react-native-firebase/auth' ;
371+ import auth , { getAuth } from ' @react-native-firebase/auth' ;
314372
315373const onMicrosoftButtonPress = async () => {
316374 // Generate the provider object
@@ -327,7 +385,7 @@ const onMicrosoftButtonPress = async () => {
327385 });
328386
329387 // Sign-in the user with the provider
330- return auth ().signInWithRedirect (provider);
388+ return getAuth ().signInWithRedirect (provider);
331389};
332390` ` `
333391
@@ -406,7 +464,7 @@ To achieve this, you should replace sign-in method in any of the supported socia
406464This code demonstrates linking a Google provider to an account that is already signed in using Firebase authentication.
407465
408466` ` ` js
409- import auth from ' @react-native-firebase/auth' ;
467+ import auth , { getAuth } from ' @react-native-firebase/auth' ;
410468import { GoogleSignin } from ' @react-native-google-signin/google-signin' ;
411469
412470async function onGoogleLinkButtonPress () {
@@ -419,7 +477,7 @@ async function onGoogleLinkButtonPress() {
419477 const googleCredential = auth .GoogleAuthProvider .credential (idToken);
420478
421479 // 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);
423481 // Handle the linked account as needed in your app
424482 return ;
425483}
0 commit comments