This repository has been archived by the owner on Oct 25, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Google.js
68 lines (61 loc) · 1.61 KB
/
Google.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
import { socialLogin, socialSignup } from '@/utils/social';
import router from '@/routes';
import { getUserFromLocalStorage } from '@/utils/webStorage';
const Google = {
init() {
window.gapi.load('auth2', () => {
const auth2 = window.gapi.auth2.init({
client_id: process.env.VUE_APP_GOOGLE_CLIENT_ID,
cookiepolicy: 'single_host_origin',
});
this.attachSignin(document.getElementById('google-login-btn'), auth2);
});
},
attachSignin(element, auth2) {
auth2.attachClickHandler(
element,
{},
googleUser => {
const profile = googleUser.getBasicProfile();
if (getUserFromLocalStorage()) {
alert('이미 로그인 되어 있습니다.');
router.push('/main');
return;
}
const path = router.history.current.path;
if (path.includes('login')) {
this.login(profile);
} else {
this.signup(profile);
}
},
error => {
// alert(JSON.stringify(error, undefined, 2));
console.log(JSON.stringify(error, undefined, 2));
},
);
},
login(profile) {
this.makeReq(profile).then(req => {
socialLogin(req);
});
},
signup(profile) {
this.makeReq(profile).then(req => {
socialSignup(req);
});
},
makeReq(profile) {
return new Promise((resolve, reject) => {
const req = {
name: profile.getName(),
id: profile.getEmail(),
email: profile.getEmail(),
picture: profile.getImageUrl(),
social: 'Google',
};
resolve(req);
});
},
};
export default Google;