Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- export const Auth = {
- isAuthenticated: false,
- authenticate() {
- this.isAuthenticated = true;
- },
- admin() {
- this.admin = jwtDecode(Token.jwt).admin;
- },
- logout() {
- this.isAuthenticated = false;
- },
- };
- export const checkAuth = () => {
- if (cookies.get('jwt') == null) return false;
- const jwt = jwtDecode(cookies.get('jwt').jwt);
- const currentTime = Date.now() / 1000;
- if (jwt.exp < currentTime) {
- return false;
- }
- return Auth.authenticate();
- };
- export const AUTH_REQUEST = (username, password) => {
- const url = `${getBaseUrl()}/m/v1/auth`;
- const data = {
- username,
- password,
- };
- return axios.post(url, data).then((response) => {
- cookies.set('jwt', response.data, { path: '/' });
- Auth.authenticate();
- });
- };
- AUTH_REQUEST.propTypes = {
- username: PropTypes.string.isRequired,
- password: PropTypes.string.isRequired,
- };
Add Comment
Please, Sign In to add comment