/
auth_apple_reauthenticate_popup.js
41 lines (34 loc) · 1.31 KB
/
auth_apple_reauthenticate_popup.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
// This snippet file was generated by processing the source file:
// ./auth-next/apple.js
//
// To update the snippets in this file, edit the source and then run
// 'npm run snippets'.
// [START auth_apple_reauthenticate_popup_modular]
import { getAuth, reauthenticateWithPopup, OAuthProvider } from "firebase/auth";
// Result from Redirect auth flow.
const auth = getAuth();
const provider = new OAuthProvider('apple.com');
reauthenticateWithPopup(auth.currentUser, provider)
.then((result) => {
// User is re-authenticated with fresh tokens minted and can perform
// sensitive operations like account deletion, or updating their email
// address or password.
// The signed-in user info.
const user = result.user;
// You can also get the Apple OAuth Access and ID Tokens.
const credential = OAuthProvider.credentialFromResult(result);
const accessToken = credential.accessToken;
const idToken = credential.idToken;
// ...
})
.catch((error) => {
// Handle Errors here.
const errorCode = error.code;
const errorMessage = error.message;
// The email of the user's account used.
const email = error.email;
// The credential that was used.
const credential = OAuthProvider.credentialFromError(error);
// ...
});
// [END auth_apple_reauthenticate_popup_modular]