-
Notifications
You must be signed in to change notification settings - Fork 0
/
login.js
45 lines (40 loc) · 1.09 KB
/
login.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
console.info('[sola]: extension injected')
var solaLogin = new SolaLogin()
window.addEventListener("message", (event) => {
if (event.source !== window) {
return
}
// login event
if (event.data.type && (event.data.type === "SOLA_LOGIN")) {
solaLogin.login(event.data.user_id, event.data.user_domain, event.data.auth_token, event.data.avatar)
}
// logout event
if (event.data.type && (event.data.type === "SOLA_LOGOUT")) {
solaLogin.logout()
}
}, false)
function SolaLogin () {
/**
* Login method
* @param user_id
* @param user_domain
* @param auth_token
* @param avatar
*/
this.login = function (user_id, user_domain, auth_token, avatar) {
chrome.storage.local.set({
user_id: user_id,
user_domain: user_domain,
auth_token: auth_token,
avatar: avatar,
})
}
this.logout = function () {
chrome.storage.local.set({
user_id: '',
user_domain: '',
auth_token: '',
avatar: ''
})
}
}