Skip to content

Commit d47a87d

Browse files
committed
Update examples to account for change in API related to credentialFromResult
1 parent faeb95c commit d47a87d

28 files changed

+471
-171
lines changed

common/api-review/auth-exp.api.md

-8
Original file line numberDiff line numberDiff line change
@@ -318,9 +318,7 @@ export class EmailAuthProvider implements externs.EmailAuthProvider {
318318
// @public
319319
export class FacebookAuthProvider extends OAuthProvider {
320320
static credential(accessToken: string): externs.OAuthCredential;
321-
// (undocumented)
322321
static credentialFromError(error: FirebaseError): externs.OAuthCredential | null;
323-
// (undocumented)
324322
static credentialFromResult(userCredential: externs.UserCredential): externs.OAuthCredential | null;
325323
static readonly FACEBOOK_SIGN_IN_METHOD = externs.SignInMethod.FACEBOOK;
326324
static readonly PROVIDER_ID = externs.ProviderId.FACEBOOK;
@@ -351,9 +349,7 @@ export function getRedirectResult(auth: externs.Auth, resolver?: externs.PopupRe
351349
// @public
352350
export class GithubAuthProvider extends OAuthProvider {
353351
static credential(accessToken: string): externs.OAuthCredential;
354-
// (undocumented)
355352
static credentialFromError(error: FirebaseError): externs.OAuthCredential | null;
356-
// (undocumented)
357353
static credentialFromResult(userCredential: externs.UserCredential): externs.OAuthCredential | null;
358354
static readonly GITHUB_SIGN_IN_METHOD = externs.SignInMethod.GITHUB;
359355
static readonly PROVIDER_ID = externs.ProviderId.GITHUB;
@@ -363,9 +359,7 @@ export class GithubAuthProvider extends OAuthProvider {
363359
// @public
364360
export class GoogleAuthProvider extends OAuthProvider {
365361
static credential(idToken?: string | null, accessToken?: string | null): externs.OAuthCredential;
366-
// (undocumented)
367362
static credentialFromError(error: FirebaseError): externs.OAuthCredential | null;
368-
// (undocumented)
369363
static credentialFromResult(userCredential: externs.UserCredential): externs.OAuthCredential | null;
370364
static readonly GOOGLE_SIGN_IN_METHOD = externs.SignInMethod.GOOGLE;
371365
static readonly PROVIDER_ID = externs.ProviderId.GOOGLE;
@@ -584,9 +578,7 @@ export function signOut(auth: externs.Auth): Promise<void>;
584578
// @public
585579
export class TwitterAuthProvider extends OAuthProvider {
586580
static credential(token: string, secret: string): externs.OAuthCredential;
587-
// (undocumented)
588581
static credentialFromError(error: FirebaseError): externs.OAuthCredential | null;
589-
// (undocumented)
590582
static credentialFromResult(userCredential: externs.UserCredential): externs.OAuthCredential | null;
591583
// (undocumented)
592584
static readonly PROVIDER_ID = externs.ProviderId.TWITTER;

docs-exp/auth.facebookauthprovider.credentialfromerror.md

+2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
## FacebookAuthProvider.credentialFromError() method
66

7+
Used to extract the underlying [OAuthCredential](./auth.oauthcredential.md) from a [AuthError](./auth-types.autherror.md) which was thrown during a sign-in, link, or reauthenticate operation.
8+
79
<b>Signature:</b>
810

911
```typescript

docs-exp/auth.facebookauthprovider.credentialfromresult.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
## FacebookAuthProvider.credentialFromResult() method
66

7+
Used to extract the underlying [OAuthCredential](./auth.oauthcredential.md) from a [UserCredential](./auth-types.usercredential.md)<!-- -->.
8+
79
<b>Signature:</b>
810

911
```typescript
@@ -14,7 +16,7 @@ static credentialFromResult(userCredential: externs.UserCredential): externs.OAu
1416

1517
| Parameter | Type | Description |
1618
| --- | --- | --- |
17-
| userCredential | externs.[UserCredential](./auth-types.usercredential.md) | |
19+
| userCredential | externs.[UserCredential](./auth-types.usercredential.md) | The user credential. |
1820

1921
<b>Returns:</b>
2022

docs-exp/auth.facebookauthprovider.md

+18-12
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,21 @@ export declare class FacebookAuthProvider extends OAuthProvider
1818
1919
```javascript
2020
// Sign in using a redirect.
21-
const result = await getRedirectResult(auth);
22-
if (result.credential) {
23-
// This gives you a Google Access Token.
24-
const token = result.credential.accessToken;
25-
}
26-
const user = result.user;
27-
28-
// Start a sign in process for an unauthenticated user.
2921
const provider = new FacebookAuthProvider();
22+
// Start a sign in process for an unauthenticated user.
3023
provider.addScope('user_birthday');
3124
await signInWithRedirect(auth, provider);
25+
// This will trigger a full page redirect away from your app
26+
27+
// After returning from the redirect when your app initializes you can obtain the result
28+
const result = await getRedirectResult(auth);
29+
if (result) {
30+
// This is the signed-in user
31+
const user = result.user;
32+
// This gives you a Facebook Access Token.
33+
const credential = provider.credentialFromResult(auth, result);
34+
const token = credential.accessToken;
35+
}
3236

3337
```
3438

@@ -40,10 +44,12 @@ await signInWithRedirect(auth, provider);
4044
const provider = new FacebookAuthProvider();
4145
provider.addScope('user_birthday');
4246
const result = await signInWithPopup(auth, provider);
43-
// This gives you a Facebook Access Token.
44-
const token = result.credential.accessToken;
47+
4548
// The signed-in user info.
4649
const user = result.user;
50+
// This gives you a Facebook Access Token.
51+
const credential = provider.credentialFromResult(auth, result);
52+
const token = credential.accessToken;
4753

4854
```
4955

@@ -60,6 +66,6 @@ const user = result.user;
6066
| Method | Modifiers | Description |
6167
| --- | --- | --- |
6268
| [credential(accessToken)](./auth.facebookauthprovider.credential.md) | <code>static</code> | Creates a credential for Facebook. |
63-
| [credentialFromError(error)](./auth.facebookauthprovider.credentialfromerror.md) | <code>static</code> | |
64-
| [credentialFromResult(userCredential)](./auth.facebookauthprovider.credentialfromresult.md) | <code>static</code> | |
69+
| [credentialFromError(error)](./auth.facebookauthprovider.credentialfromerror.md) | <code>static</code> | Used to extract the underlying [OAuthCredential](./auth.oauthcredential.md) from a [AuthError](./auth-types.autherror.md) which was thrown during a sign-in, link, or reauthenticate operation. |
70+
| [credentialFromResult(userCredential)](./auth.facebookauthprovider.credentialfromresult.md) | <code>static</code> | Used to extract the underlying [OAuthCredential](./auth.oauthcredential.md) from a [UserCredential](./auth-types.usercredential.md)<!-- -->. |
6571

docs-exp/auth.getredirectresult.md

+14-14
Original file line numberDiff line numberDiff line change
@@ -31,23 +31,23 @@ If sign-in succeeded, returns the signed in user. If sign-in was unsuccessful, f
3131

3232

3333
```javascript
34-
// First, we perform the signInWithRedirect.
35-
// Creates the provider.
34+
// Sign in using a redirect.
3635
const provider = new FacebookAuthProvider();
3736
// You can add additional scopes to the provider:
38-
provider.addScope('email');
39-
provider.addScope('user_friends');
40-
// Sign in with redirect:
41-
await signInWithRedirect(auth, provider)
42-
////////////////////////////////////////////////////////////
43-
// The user is redirected to the provider's sign in flow...
44-
////////////////////////////////////////////////////////////
45-
// Then redirected back to the app, where we check the redirect result:
37+
provider.addScope('user_birthday');
38+
// Start a sign in process for an unauthenticated user.
39+
await signInWithRedirect(auth, provider);
40+
// This will trigger a full page redirect away from your app
41+
42+
// After returning from the redirect when your app initializes you can obtain the result
4643
const result = await getRedirectResult(auth);
47-
// The Firebase User instance:
48-
const user = result.user;
49-
// The Facebook AuthCredential containing the Facebook access token:
50-
const credential = result.credential;
44+
if (result) {
45+
// This is the signed-in user
46+
const user = result.user;
47+
// This gives you a Facebook Access Token.
48+
const credential = provider.credentialFromResult(auth, result);
49+
const token = credential.accessToken;
50+
}
5151
// As this API can be used for sign-in, linking and reauthentication,
5252
// check the operationType to determine what triggered this redirect
5353
// operation.

docs-exp/auth.githubauthprovider.credentialfromerror.md

+2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
## GithubAuthProvider.credentialFromError() method
66

7+
Used to extract the underlying [OAuthCredential](./auth.oauthcredential.md) from a [AuthError](./auth-types.autherror.md) which was thrown during a sign-in, link, or reauthenticate operation.
8+
79
<b>Signature:</b>
810

911
```typescript

docs-exp/auth.githubauthprovider.credentialfromresult.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
## GithubAuthProvider.credentialFromResult() method
66

7+
Used to extract the underlying [OAuthCredential](./auth.oauthcredential.md) from a [UserCredential](./auth-types.usercredential.md)<!-- -->.
8+
79
<b>Signature:</b>
810

911
```typescript
@@ -14,7 +16,7 @@ static credentialFromResult(userCredential: externs.UserCredential): externs.OAu
1416

1517
| Parameter | Type | Description |
1618
| --- | --- | --- |
17-
| userCredential | externs.[UserCredential](./auth-types.usercredential.md) | |
19+
| userCredential | externs.[UserCredential](./auth-types.usercredential.md) | The user credential. |
1820

1921
<b>Returns:</b>
2022

docs-exp/auth.githubauthprovider.md

+20-14
Original file line numberDiff line numberDiff line change
@@ -21,33 +21,39 @@ GitHub requires an OAuth 2.0 redirect, so you can either handle the redirect dir
2121
2222
2323
```javascript
24-
// Using a redirect.
25-
const result = await getRedirectResult(auth);
26-
if (result.credential) {
27-
// This gives you a GitHub Access Token.
28-
const token = result.credential.accessToken;
29-
}
30-
const user = result.user;
31-
32-
// Start a sign in process for an unauthenticated user.
24+
// Sign in using a redirect.
3325
const provider = new GithubAuthProvider();
26+
// Start a sign in process for an unauthenticated user.
3427
provider.addScope('repo');
3528
await signInWithRedirect(auth, provider);
29+
// This will trigger a full page redirect away from your app
30+
31+
// After returning from the redirect when your app initializes you can obtain the result
32+
const result = await getRedirectResult(auth);
33+
if (result) {
34+
// This is the signed-in user
35+
const user = result.user;
36+
// This gives you a Github Access Token.
37+
const credential = provider.credentialFromResult(auth, result);
38+
const token = credential.accessToken;
39+
}
3640

3741
```
3842

3943
## Example 2
4044

4145

4246
```javascript
43-
// With popup.
47+
// Sign in using a popup.
4448
const provider = new GithubAuthProvider();
4549
provider.addScope('repo');
4650
const result = await signInWithPopup(auth, provider);
47-
// This gives you a GitHub Access Token.
48-
const token = result.credential.accessToken;
51+
4952
// The signed-in user info.
5053
const user = result.user;
54+
// This gives you a Github Access Token.
55+
const credential = provider.credentialFromResult(auth, result);
56+
const token = credential.accessToken;
5157

5258
```
5359

@@ -64,6 +70,6 @@ const user = result.user;
6470
| Method | Modifiers | Description |
6571
| --- | --- | --- |
6672
| [credential(accessToken)](./auth.githubauthprovider.credential.md) | <code>static</code> | Creates a credential for Github. |
67-
| [credentialFromError(error)](./auth.githubauthprovider.credentialfromerror.md) | <code>static</code> | |
68-
| [credentialFromResult(userCredential)](./auth.githubauthprovider.credentialfromresult.md) | <code>static</code> | |
73+
| [credentialFromError(error)](./auth.githubauthprovider.credentialfromerror.md) | <code>static</code> | Used to extract the underlying [OAuthCredential](./auth.oauthcredential.md) from a [AuthError](./auth-types.autherror.md) which was thrown during a sign-in, link, or reauthenticate operation. |
74+
| [credentialFromResult(userCredential)](./auth.githubauthprovider.credentialfromresult.md) | <code>static</code> | Used to extract the underlying [OAuthCredential](./auth.oauthcredential.md) from a [UserCredential](./auth-types.usercredential.md)<!-- -->. |
6975

docs-exp/auth.googleauthprovider.credentialfromerror.md

+2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
## GoogleAuthProvider.credentialFromError() method
66

7+
Used to extract the underlying [OAuthCredential](./auth.oauthcredential.md) from a [AuthError](./auth-types.autherror.md) which was thrown during a sign-in, link, or reauthenticate operation.
8+
79
<b>Signature:</b>
810

911
```typescript

docs-exp/auth.googleauthprovider.credentialfromresult.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
## GoogleAuthProvider.credentialFromResult() method
66

7+
Used to extract the underlying [OAuthCredential](./auth.oauthcredential.md) from a [UserCredential](./auth-types.usercredential.md)<!-- -->.
8+
79
<b>Signature:</b>
810

911
```typescript
@@ -14,7 +16,7 @@ static credentialFromResult(userCredential: externs.UserCredential): externs.OAu
1416

1517
| Parameter | Type | Description |
1618
| --- | --- | --- |
17-
| userCredential | externs.[UserCredential](./auth-types.usercredential.md) | |
19+
| userCredential | externs.[UserCredential](./auth-types.usercredential.md) | The user credential. |
1820

1921
<b>Returns:</b>
2022

docs-exp/auth.googleauthprovider.md

+20-14
Original file line numberDiff line numberDiff line change
@@ -17,19 +17,23 @@ export declare class GoogleAuthProvider extends OAuthProvider
1717
1818
1919
```javascript
20-
// Using a redirect.
21-
const result = getRedirectResult(auth);
22-
if (result.credential) {
23-
// This gives you a Google Access Token.
24-
const token = result.credential.accessToken;
25-
}
26-
const user = result.user;
27-
20+
// Sign in using a redirect.
21+
const provider = new GoogleAuthProvider();
2822
// Start a sign in process for an unauthenticated user.
29-
var provider = new GoogleAuthProvider();
3023
provider.addScope('profile');
3124
provider.addScope('email');
32-
aiwait signInWithRedirect(auth, provider);
25+
await signInWithRedirect(auth, provider);
26+
// This will trigger a full page redirect away from your app
27+
28+
// After returning from the redirect when your app initializes you can obtain the result
29+
const result = await getRedirectResult(auth);
30+
if (result) {
31+
// This is the signed-in user
32+
const user = result.user;
33+
// This gives you a Google Access Token.
34+
const credential = provider.credentialFromResult(auth, result);
35+
const token = credential.accessToken;
36+
}
3337

3438
```
3539

@@ -42,10 +46,12 @@ const provider = new GoogleAuthProvider();
4246
provider.addScope('profile');
4347
provider.addScope('email');
4448
const result = await signInWithPopup(auth, provider);
45-
// This gives you a Google Access Token.
46-
const token = result.credential.accessToken;
49+
4750
// The signed-in user info.
4851
const user = result.user;
52+
// This gives you a Google Access Token.
53+
const credential = provider.credentialFromResult(auth, result);
54+
const token = credential.accessToken;
4955

5056
```
5157

@@ -62,6 +68,6 @@ const user = result.user;
6268
| Method | Modifiers | Description |
6369
| --- | --- | --- |
6470
| [credential(idToken, accessToken)](./auth.googleauthprovider.credential.md) | <code>static</code> | Creates a credential for Google. At least one of ID token and access token is required. |
65-
| [credentialFromError(error)](./auth.googleauthprovider.credentialfromerror.md) | <code>static</code> | |
66-
| [credentialFromResult(userCredential)](./auth.googleauthprovider.credentialfromresult.md) | <code>static</code> | |
71+
| [credentialFromError(error)](./auth.googleauthprovider.credentialfromerror.md) | <code>static</code> | Used to extract the underlying [OAuthCredential](./auth.oauthcredential.md) from a [AuthError](./auth-types.autherror.md) which was thrown during a sign-in, link, or reauthenticate operation. |
72+
| [credentialFromResult(userCredential)](./auth.googleauthprovider.credentialfromresult.md) | <code>static</code> | Used to extract the underlying [OAuthCredential](./auth.oauthcredential.md) from a [UserCredential](./auth-types.usercredential.md)<!-- -->. |
6773

docs-exp/auth.linkwithpopup.md

+12
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,15 @@ Promise&lt;externs.[UserCredential](./auth-types.usercredential.md)<!-- -->&gt;
2828

2929
If the linking is successful, the returned result will contain the user and the provider's credential.
3030

31+
## Example
32+
33+
34+
```javascript
35+
// Sign in using some other provider.
36+
const result = await signInWithEmailAndPassword(auth, email, password);
37+
// Link using a popup.
38+
const provider = new FacebookAuthProvider();
39+
await linkWithPopup(result.user, provider);
40+
41+
```
42+

docs-exp/auth.linkwithredirect.md

+16
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,19 @@ export declare function linkWithRedirect(user: externs.User, provider: externs.A
2424

2525
Promise&lt;never&gt;
2626

27+
## Example
28+
29+
30+
```javascript
31+
// Sign in using some other provider.
32+
const result = await signInWithEmailAndPassword(auth, email, password);
33+
// Link using a redirect.
34+
const provider = new FacebookAuthProvider();
35+
await linkWithRedirect(result.user, provider);
36+
// This will trigger a full page redirect away from your app
37+
38+
// After returning from the redirect when your app initializes you can obtain the result
39+
const result = await getRedirectResult(auth);
40+
41+
```
42+

0 commit comments

Comments
 (0)