-
-
Notifications
You must be signed in to change notification settings - Fork 48
/
index.js
58 lines (54 loc) · 1.5 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
(function () {
function err (msg) {
typeof console !== 'undefined' && console.error(`[g-signin-button] ${msg}`)
}
function install (Vue) {
Vue.component('g-signin-button', {
name: 'g-signin-button',
render (createElement) {
return createElement('div', {
attrs: {
class: 'g-signin-button'
},
ref: 'signinBtn'
}, this.$slots.default)
},
props: {
params: {
type: Object,
required: true,
default () {
return {}
}
}
},
mounted () {
if (!window.gapi) {
err('"https://apis.google.com/js/api:client.js" needs to be included as a <script>.')
return
}
if (!this.params.clientId && !this.params.client_id) {
err('Client Id must be specified.')
return
}
window.gapi.load('auth2', () => {
const auth2 = window.gapi.auth2.init(this.params)
auth2.attachClickHandler(this.$refs.signinBtn, {}, googleUser => {
this.$emit('success', googleUser)
}, error => {
this.$emit('error', error)
this.$emit('failure', error) // an alias
})
})
}
})
}
if (typeof exports === 'object') {
module.exports = install
} else if (typeof define === 'function' && define.amd) {
/*global define*/
define([], function () { return install })
} else if (window.Vue) {
window.Vue.use(install)
}
})()