diff --git a/src/utils/auth.js b/src/utils/auth.js new file mode 100644 index 0000000..e568fcb --- /dev/null +++ b/src/utils/auth.js @@ -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; +};