-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclientUtils.js
More file actions
55 lines (48 loc) · 1.48 KB
/
clientUtils.js
File metadata and controls
55 lines (48 loc) · 1.48 KB
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
function getParamsObject() {
return Object.fromEntries(new URL(window.location).searchParams);
}
function setCookie(cname, cvalue, exdays) {
const d = new Date();
d.setTime(d.getTime() + (exdays * 24 * 60 * 60 * 1000));
let expires = "expires=" + d.toUTCString();
cvalue = cvalue.replaceAll('+', ' ');
cvalue = encodeURIComponent(cvalue);
document.cookie = cname + "=" + cvalue + ";" + expires + ";path=/";
//console.log("Cookie set: ", cname + "=" + cvalue);
}
function deleteCookie(cname) {
document.cookie = cname + '=; Max-Age=-99999999;';
}
function getCookie(cname) {
let name = cname + "=";
let ca = document.cookie.split(';');
for (let i = 0; i < ca.length; i++) {
let c = ca[i];
while (c.charAt(0) == ' ') {
c = c.substring(1);
}
if (c.indexOf(name) == 0) {
c = c.substring(name.length, c.length);
return decodeURIComponent(c);
}
}
return "";
}
function checkCookie(cname) {
const c = getCookie(cname);
const params = getParamsObject();
if (!c) {
if (params[cname]) {
setCookie(cname, params[cname], 7);
return params[cname];
}
} if (c) {
return c;
}
return "";
}
const preferredLoginMethodCookieName = 'preferredLoginMethod';
const getPreferredLogInMethodCookie = () => getCookie(preferredLoginMethodCookieName);
function setPreferredLogInMethodCookie(providerId) {
setCookie(preferredLoginMethodCookieName, providerId, 6000);
}