mirror of
https://github.com/Sea-Haven-Industries/shoc-frontend-new.git
synced 2026-10-01 08:33:11 +00:00
32 lines
698 B
JavaScript
32 lines
698 B
JavaScript
|
|
const tokenKey = "token";
|
||
|
|
|
||
|
|
export const setUser = (user) => {
|
||
|
|
if (user && user.token) {
|
||
|
|
window.localStorage.setItem(tokenKey, JSON.stringify(user));
|
||
|
|
}
|
||
|
|
else {
|
||
|
|
window.localStorage.removeItem(tokenKey);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
export const getAccessToken = () => {
|
||
|
|
let result = window.localStorage.getItem(tokenKey);
|
||
|
|
if (!result) {
|
||
|
|
return "";
|
||
|
|
}
|
||
|
|
const user = JSON.parse(result);
|
||
|
|
return `Bearer ${user.token}`;
|
||
|
|
}
|
||
|
|
|
||
|
|
export const getUser = () => {
|
||
|
|
let result = window.localStorage.getItem(tokenKey);
|
||
|
|
if (!result) {
|
||
|
|
return {};
|
||
|
|
}
|
||
|
|
|
||
|
|
return JSON.parse(result);
|
||
|
|
}
|
||
|
|
|
||
|
|
export const removeToken = () => {
|
||
|
|
window.localStorage.removeItem(tokenKey);
|
||
|
|
}
|