-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlogout.js
42 lines (35 loc) · 974 Bytes
/
logout.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
import sjwt from './sjwt.js';
import getErrorFromCodes from './getErrorFromCodes.js';
import {codes} from './codesMessages.js';
/**
* Logout
*
* @param {object} [args] - options
* @param {string} [args.projectId] - The project id to register with, optional if provided via `sjwt.configure()`
* @returns {any}
*/
const logout = async ({
projectId,
} = {}) => {
let returns = {
success: true,
};
try {
if (sjwt.token) {
const pid = projectId ?? sjwt.projectId;
const url = `${sjwt.authUrl}/${pid}/logout`;
const result = await fetch(url, {
method: 'get',
headers: {
Authorization: `Bearer ${sjwt.token}`,
},
});
returns = await result.json();
}
} catch (error) {
return getErrorFromCodes([codes.UNKNOWN_ERROR]);
}
sjwt.logout();
return returns;
};
export default logout;