-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
44 lines (38 loc) · 894 Bytes
/
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
setup();
function setup() {
$('#login').click(login);
login(false);
}
function isAuthenticated() {
return new Promise((resolve, reject) => {
Trello.rest('GET', '/members/me', () => resolve(true), () => resolve(false));
});
}
async function login(interactive = true) {
const loggedIn = await trelloAuth(interactive);
if(!loggedIn) {
$('#login').show();
} else {
authenticationSuccess();
}
}
function trelloAuth(interactive = true){
return new Promise((resolve, reject) => {
Trello.authorize({
type: 'popup',
name: 'FamilySearch Trello Tab',
scope: {
read: 'true',
write: 'true'
},
interactive,
expiration: 'never',
success: () => resolve(true),
error: () => resolve(false)
});
});
}
function authenticationSuccess() {
$('#login').hide();
document.write('<h2>Authenticated</h2>');
}