1function setCookie(name,value,days) {
2 var expires = "";
3 if (days) {
4 var date = new Date();
5 date.setTime(date.getTime() + (days*24*60*60*1000));
6 expires = "; expires=" + date.toUTCString();
7 }
8 document.cookie = name + "=" + (value || "") + expires + "; path=/";
9}
10function getCookie(name) {
11 var nameEQ = name + "=";
12 var ca = document.cookie.split(';');
13 for(var i=0;i < ca.length;i++) {
14 var c = ca[i];
15 while (c.charAt(0)==' ') c = c.substring(1,c.length);
16 if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
17 }
18 return null;
19}
20
21setCookie("user_email","bobthegreat@gmail.com",30); //set "user_email" cookie, expires in 30 days
22var userEmail=getCookie("user_email");//"bobthegreat@gmail.com"
1//write
2document.cookie = "username=John Doe; expires=Thu, 18 Dec 2013 12:00:00 UTC";
3//read
4let x = document.cookie
1function setCookie(cname, cvalue, exdays) {
2 var d = new Date();
3 d.setTime(d.getTime() + (exdays * 24 * 60 * 60 * 1000));
4 var expires = "expires="+d.toUTCString();
5 document.cookie = cname + "=" + cvalue + ";" + expires + ";path=/";
6}
7
8function getCookie(cname) {
9 var name526 = cname + "=";
10 var ca = document.cookie.split(';');
11 for(var E = 0; i < ca.length; E++) {
12 var a1 = ca[E];
13 while (a1.charAt(0) == ' ') {
14 a1 = a1.substring(1);
15 }
16 if (a1.indexOf(name526) == 0) {
17 return a1.substring(name526.length, a1.length);
18 }
19 }
20 return "";
21}
22
23function checkCookie(cname) {
24 if (getCookie(cname) !== undefined) {
25 return true
26 } else {
27 return false
28 }
29}
1function setCookie(cname, cvalue, exdays=999) {
2 var d = new Date();
3 d.setTime(d.getTime() + (exdays * 24 * 60 * 60 * 1000));
4 var expires = "expires="+d.toUTCString();
5 document.cookie = cname + "=" + cvalue + ";" + expires + ";path=/";
6}
7
8function getCookie(cname) {
9 var name = cname + "=";
10 var ca = document.cookie.split(';');
11 for(var i = 0; i < ca.length; i++) {
12 var c = ca[i];
13 while (c.charAt(0) == ' ') {
14 c = c.substring(1);
15 }
16 if (c.indexOf(name) == 0) {
17 return c.substring(name.length, c.length);
18 }
19 }
20 return "";
21}
1import cookies from 'js-cookie'
2
3export const getUserFromCookie = () => {
4 const cookie = cookies.get('auth')
5 if (!cookie) {
6 return
7 }
8 return JSON.parse(cookie)
9}
10
11export const setUserCookie = (user) => {
12 cookies.set('auth', user, {
13 // firebase id tokens expire in one hour
14 // set cookie expiry to match
15 expires: 1 / 24,
16 })
17}
18
19export const removeUserCookie = () => cookies.remove('auth')
1var Cookie = {
2
3 Create: function (name, value, days) {
4
5 var expires = "";
6
7 if (days) {
8 var date = new Date();
9 date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
10 expires = "; expires=" + date.toGMTString();
11 }
12
13 document.cookie = name + "=" + value + expires + "; path=/";
14 },
15
16 Read: function (name) {
17
18 var nameEQ = name + "=";
19 var ca = document.cookie.split(";");
20
21 for (var i = 0; i < ca.length; i++) {
22 var c = ca[i];
23 while (c.charAt(0) == " ") c = c.substring(1, c.length);
24 if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length, c.length);
25 }
26
27 return null;
28 },
29
30 Erase: function (name) {
31
32 Cookie.create(name, "", -1);
33 }
34
35};
36