mirror of
https://github.com/franjsco/tick3t
synced 2024-12-29 10:50:08 +01:00
feat: add auth module
This commit is contained in:
parent
053b47e72d
commit
c2bb646bcf
22
src/utils/auth.js
Normal file
22
src/utils/auth.js
Normal file
@ -0,0 +1,22 @@
|
||||
import { validate } from "../api/authentication";
|
||||
|
||||
export const getAuthHeader = () => {
|
||||
const user = JSON.parse(localStorage.getItem("user"));
|
||||
return user && user.token ? `Bearer ${user.token}` : "";
|
||||
};
|
||||
|
||||
export const validateUser = () => {
|
||||
validate().then(json => {
|
||||
if (!json.success) {
|
||||
localStorage.removeItem("user");
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
export const isLogin = () => {
|
||||
if (localStorage.getItem("user")) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
};
|
Loading…
Reference in New Issue
Block a user