Created
October 8, 2019 01:23
-
-
Save mvgolom/5990c321f77672e647f6abdca04b100c to your computer and use it in GitHub Desktop.
services
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import axios from "axios"; | |
import { getToken } from "./auth"; | |
const api = axios.create({ | |
baseURL: "http://127.0.0.1:5000" | |
}); | |
api.interceptors.request.use(async config => { | |
const token = getToken(); | |
if (token) { | |
config.headers.Authorization = `Bearer ${token}`; | |
} | |
return config; | |
}); | |
export default api; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export const TOKEN_KEY = "@web-keeper"; | |
export const TOKEN_KEY_REFRESH = "@web-keeper-refresh" | |
export const isAuthenticated = () => localStorage.getItem(TOKEN_KEY) !== null; | |
export const getToken = () => localStorage.getItem(TOKEN_KEY); | |
export const getRefreshToken = () => localStorage.getItem(TOKEN_KEY_REFRESH); | |
export const login = token => { | |
localStorage.setItem(TOKEN_KEY, token); | |
}; | |
export const login_refresh = token_refresh => { | |
localStorage.setItem(TOKEN_KEY_REFRESH, token_refresh); | |
}; | |
export const logout = () => { | |
localStorage.removeItem(TOKEN_KEY); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment