-
Notifications
You must be signed in to change notification settings - Fork 253
/
Copy pathcordova.js
64 lines (55 loc) · 1.99 KB
/
cordova.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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
// [SNIPPET_REGISTRY disabled]
// [SNIPPETS_SEPARATION enabled]
// Docs: https://source.corp.google.com/piper///depot/google3/third_party/devsite/firebase/en/docs/auth/web/cordova.md
function createGoogleProvider() {
// [START auth_create_google_provider]
const { GoogleAuthProvider } = require("firebase/auth/cordova");
const provider = new GoogleAuthProvider();
// [END auth_create_google_provider]
}
function cordovaSignInRedirect() {
// [START auth_cordova_sign_in_redirect]
const { getAuth, signInWithRedirect, getRedirectResult, GoogleAuthProvider } = require("firebase/auth/cordova");
const auth = getAuth();
signInWithRedirect(auth, new GoogleAuthProvider())
.then(() => {
return getRedirectResult(auth);
})
.then((result) => {
const credential = GoogleAuthProvider.credentialFromResult(result);
// This gives you a Google Access Token.
// You can use it to access the Google API.
const token = credential.accessToken;
// The signed-in user info.
const user = result.user;
// ...
}).catch((error) => {
// Handle Errors here.
const errorCode = error.code;
const errorMessage = error.message;
});
// [END auth_cordova_sign_in_redirect]
}
function cordovaRedirectResult() {
// [START auth_cordova_redirect_result]
const { getAuth, getRedirectResult, GoogleAuthProvider } = require("firebase/auth/cordova");
const auth = getAuth();
getRedirectResult(auth)
.then((result) => {
const credential = GoogleAuthProvider.credentialFromResult(result);
if (credential) {
// This gives you a Google Access Token.
// You can use it to access the Google API.
const token = credential.accessToken;
// The signed-in user info.
const user = result.user;
// ...
}
})
.catch((error) => {
// Handle Errors here.
const errorCode = error.code;
const errorMessage = error.message;
});
// [END auth_cordova_redirect_result]
}