Skip to content

Commit

Permalink
jwt-setup
Browse files Browse the repository at this point in the history
  • Loading branch information
MattGalvis committed Sep 12, 2023
1 parent 60429e8 commit 09193f5
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
6 changes: 6 additions & 0 deletions .changeset/smart-shoes-burn.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@baseapp-frontend/authentication": major
"@baseapp-frontend/core": major
---

a
6 changes: 3 additions & 3 deletions packages/core/src/axios.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,13 @@ function createAxiosInstance({ file = false } = {}) {
instance.defaults.headers.patch['Content-Type'] = contentType
instance.defaults.headers.put['Content-Type'] = contentType

instance.interceptors.request.use((request) => {
instance.interceptors.request.use(async (request) => {
let authToken = Cookies.get('Authorization')
if (authToken) {
if (request.headers && !request.headers.Authorization) {
const token = readExpiry(authToken)
if (token.response != null && token.expired === true) {
authToken = refreshToken()
if (token.response != null && token.expired) {
authToken = await refreshToken()
}
request.headers.Authorization = `Token ${authToken}`
}
Expand Down

0 comments on commit 09193f5

Please sign in to comment.