forked from zatech/emojis
-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathauth.js
More file actions
40 lines (35 loc) · 918 Bytes
/
Copy pathauth.js
File metadata and controls
40 lines (35 loc) · 918 Bytes
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
function getAuth(argv, env) {
let auth;
if (argv.auth) {
// If `--auth` is set, try and use that.
try {
auth = JSON.parse(argv.auth);
} catch (error) {
throw 'Invalid JSON for `--auth`';
}
} else {
// Otherwise try the environment.
try {
auth = JSON.parse(env.EMOJME_AUTH);
} catch (error) {
throw 'Invalid JSON for `EMOJME_AUTH`';
}
}
// Sanity checks on authentication data.
if (!auth) {
throw 'Missing `--auth` or `EMOJME_AUTH`';
}
if (!auth.token) {
throw 'Missing token in JSON `--auth` or `EMOJME_AUTH`';
}
if (!auth.domain) {
throw 'Missing domain in JSON `--auth` or `EMOJME_AUTH`';
}
if (!auth.cookie) {
throw 'Missing cookie in JSON `--auth` or `EMOJME_AUTH`';
}
return auth;
}
export {
getAuth,
};