1
0
mirror of https://github.com/Unleash/unleash.git synced 2024-12-28 00:06:53 +01:00
unleash.unleash/packages/unleash-frontend/public/js/stores/UserStore.js
Simen Bekkhus 5aa14262a2 Fix linting errors (#145)
* Use pretty (svg) badges

* Fix build
2020-02-20 08:30:27 +01:00

36 lines
843 B
JavaScript

'use strict';
let _username;
// Ref: http://stackoverflow.com/questions/10730362/get-cookie-by-name
function readCookie (cookieName) {
const nameEQ = `${cookieName}=`;
const ca = document.cookie.split(';');
for (let i = 0;i < ca.length;i++) {
let c = ca[i];
while (c.charAt(0) == ' ') { // eslint-disable-line eqeqeq
c = c.substring(1, c.length);
}
if (c.indexOf(nameEQ) === 0) {
return c.substring(nameEQ.length, c.length);
}
}
return null;
}
const UserStore = {
init () {
_username = readCookie('username');
},
set (username) {
_username = username;
document.cookie = `username=${_username}; expires=Thu, 18 Dec 2099 12:00:00 UTC`;
},
get () {
return _username;
},
};
module.exports = UserStore;