Skip to content

Commit a459a0c

Browse files
committed
chore(auth): include social auth plugins
1 parent 2ad4143 commit a459a0c

File tree

1 file changed

+34
-7
lines changed

1 file changed

+34
-7
lines changed

packages/firebase-auth/README.md

Lines changed: 34 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -157,10 +157,23 @@ A 3rd party library is required to both install the Facebook SDK and trigger the
157157
```ts
158158
import { firebase } from '@nativescript/firebase-core';
159159
import { FacebookAuthProvider } from '@nativescript/firebase-auth';
160-
// Create a credential from the access token
161-
const facebookAuthCredential = FacebookAuthProvider.credential(accessToken);
160+
import { LoginManager, AccessToken } from '@nativescript/facebook';
161+
162+
163+
LoginManager.logInWithPermissions(['public_profile', 'email']).then((result) => {
164+
// Once signed in, get the users AccesToken
165+
const data = await AccessToken.getCurrentAccessToken();
166+
167+
// Create a Firebase credential with the AccessToken
168+
const facebookCredential = FacebookAuthProvider.credential(data.accessToken);
169+
170+
// Sign-in the user with the credential
171+
return auth().signInWithCredential(facebookCredential);
172+
173+
firebase().auth().signInWithCredential(facebookAuthCredential);
174+
});
175+
162176

163-
firebase().auth().signInWithCredential(facebookAuthCredential);
164177
```
165178

166179
** Note **
@@ -176,9 +189,18 @@ A 3rd party library is required to both install the Twitter SDK and trigger the
176189
```ts
177190
import { firebase } from '@nativescript/firebase-core';
178191
import { TwitterAuthProvider } from '@nativescript/firebase-auth';
179-
const twitterAuthCredential = TwitterAuthProvider.credential(authToken, authTokenSecret);
192+
import { Twitter, TwitterSignIn } from '@nativescript/twitter';
193+
194+
Twitter.init('TWITTER_CONSUMER_KEY', 'TWITTER_CONSUMER_SECRET'); // called earlier in the app
195+
196+
// Perform the login request
197+
TwitterSignIn.logIn().then((data) => {
198+
const twitterAuthCredential = TwitterAuthProvider.credential(data.authToken, data.authTokenSecret);
199+
200+
firebase().auth().signInWithCredential(twitterAuthCredential);
201+
});
202+
180203

181-
firebase().auth().signInWithCredential(twitterAuthCredential);
182204
```
183205

184206
#### GitHub
@@ -202,10 +224,15 @@ Most configuration is already setup when using Google Sign-In with Firebase, how
202224
```ts
203225
import { firebase } from '@nativescript/firebase-core';
204226
import { GoogleAuthProvider } from '@nativescript/firebase-auth';
227+
import { GoogleSignin } from '@nativescript/google-signin';
228+
229+
GoogleSignin.configure(); // called earlier in the app
205230

206-
const credential = GoogleAuthProvider.credential(accessToken, idToken);
231+
GoogleSignin.signIn().then((user) => {
232+
const credential = GoogleAuthProvider.credential(user.accessToken, user.idToken);
207233

208-
firebase().auth().signInWithCredential(credential);
234+
firebase().auth().signInWithCredential(credential);
235+
});
209236
```
210237

211238
### Phone Authentication

0 commit comments

Comments
 (0)