-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
72 lines (70 loc) · 1.93 KB
/
index.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
65
66
67
68
69
70
71
72
import Meteor from '@meteorrn/core';
import { GoogleSignin } from '@react-native-google-signin/google-signin';
/**
* Login with Google using Meteor Accounts and React Native
* @param configuration Options for the configure method of GoogleSignin.
* @param callback function to see if there is error
* @returns {Promise<void> | Promise.Promise}
*/
Meteor.loginWithGoogle = async function(configuration, callback) {
try {
GoogleSignin.configure(configuration);
await GoogleSignin.hasPlayServices({
showPlayServicesUpdateDialog: true
});
let userInfo;
const isSignedIn = await GoogleSignin.isSignedIn();
if (!isSignedIn) {
userInfo = await GoogleSignin.signIn();
if (!userInfo) {
callback({ reason: 'Something went wrong obtaining user info', details: { userInfo } });
return;
}
} else {
userInfo = await GoogleSignin.signInSilently();
if (!userInfo) {
callback({ reason: 'Something went wrong obtaining user info', details: { userInfo } });
return;
}
}
const tokens = await GoogleSignin.getTokens();
Meteor._startLoggingIn();
Meteor.call(
'login',
{
googleSignIn: true,
accessToken: tokens.accessToken,
refreshToken: undefined,
idToken: tokens.idToken,
serverAuthCode: userInfo.serverAuthCode,
email: userInfo.user.email,
imageUrl: userInfo.user.photo,
userId: userInfo.user.id
},
(error, response) => {
if (error) {
GoogleSignin.revokeAccess();
GoogleSignin.signOut();
}
Meteor._endLoggingIn();
Meteor._handleLoginCallback(error, response);
typeof callback == 'function' && callback(error);
}
);
} catch (error) {
callback({ reason: 'Error in Google Signing', details: error });
}
};
Meteor.logoutFromGoogle = function() {
return Promise((resolve, reject)=>{
Meteor.logout((error) => {
if (!error) {
GoogleSignin.revokeAccess();
GoogleSignin.signOut();
resolve();
}else{
reject(error);
}
});
})
};