-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
55 lines (48 loc) · 1.35 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
setup();
function setup() {
// When the login is clicked we initiate interactive login meaning we use the popup
$('#login').click(function(){
login(true);
});
// Noninteractive login to check if an auth token already exists in storage
login(false);
}
/**
* Initiate the auth sequence and handle the result
*
* @param {Boolean=} interactive Whether to use the popup or just try to authenticate with existing tokens stored locally.
*/
async function login(interactive = true) {
const loggedIn = await trelloAuth(interactive);
if(!loggedIn) {
$('#login').show();
} else {
authenticationSuccess();
}
}
/**
* Initiate Authentication with Trello.
*
* @param {Boolean=} interactive Whether to use the popup or just try to authenticate with existing tokens stored locally.
* @return {Promise<boolean>} resolves to true (authenticated) or false (not authenticated)
*/
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>');
}