forked from firebase/snippets-web
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cordova.js
57 lines (51 loc) · 1.83 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
// These samples are intended for Web so this import would normally be
// done in HTML however using modules here is more convenient for
// ensuring sample correctness offline.
import firebase from "firebase/app";
import "firebase/auth";
// 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]
var provider = new firebase.auth.GoogleAuthProvider();
// [END auth_create_google_provider]
}
function cordovaSignInRedirect(provider) {
// [START auth_cordova_sign_in_redirect]
firebase.auth().signInWithRedirect(provider).then(function() {
return firebase.auth().getRedirectResult();
}).then((result) => {
/** @type {firebase.auth.OAuthCredential} */
var credential = result.credential;
// This gives you a Google Access Token.
// You can use it to access the Google API.
var token = credential.accessToken;
// The signed-in user info.
var user = result.user;
// ...
}).catch((error) => {
// Handle Errors here.
var errorCode = error.code;
var errorMessage = error.message;
});
// [END auth_cordova_sign_in_redirect]
}
function cordovaRedirectResult() {
// [START auth_cordova_redirect_result]
firebase.auth().getRedirectResult().then((result) => {
if (result.credential) {
/** @type {firebase.auth.OAuthCredential} */
var credential = result.credential;
// This gives you a Google Access Token.
// You can use it to access the Google API.
var token = credential.accessToken;
// The signed-in user info.
var user = result.user;
// ...
}
}).catch((error) => {
// Handle Errors here.
var errorCode = error.code;
var errorMessage = error.message;
});
// [END auth_cordova_redirect_result]
}