chore: fix jwt token issue

This commit is contained in:
2024-09-23 09:16:35 -03:00
parent f0185058be
commit 519e5a42a2
2 changed files with 13 additions and 6 deletions
+9 -5
View File
@@ -1,6 +1,10 @@
import { API_TOKEN } from '../app-constants/app-constants';
const tokenState = localStorage.getItem(API_TOKEN);
function getToken(): string {
const tokenState = localStorage.getItem(API_TOKEN);
return tokenState ?? '';
}
/**
*
@@ -25,7 +29,7 @@ const api = {
mode: 'cors',
headers: {
'Content-Type': 'application/json',
Authorization: `Bearer ${tokenState}`
Authorization: `Bearer ${getToken()}`
}
});
if (response.ok) {
@@ -42,7 +46,7 @@ const api = {
mode: 'cors',
headers: {
'Content-Type': 'application/json',
Authorization: `Bearer ${tokenState}`
Authorization: `Bearer ${getToken()}`
},
body: JSON.stringify(payload)
});
@@ -60,7 +64,7 @@ const api = {
mode: 'cors',
headers: {
'Content-Type': 'application/json',
Authorization: `Bearer ${tokenState}`
Authorization: `Bearer ${getToken()}`
},
body: JSON.stringify(payload)
});
@@ -78,7 +82,7 @@ const api = {
mode: 'cors',
headers: {
'Content-Type': 'application/json',
Authorization: `Bearer ${tokenState}`
Authorization: `Bearer ${getToken()}`
}
});
if (response.status === 204) {
@@ -40,7 +40,10 @@ public class JwtAuthenticationFilter extends OncePerRequestFilter {
return;
}
String jwtToken = authorizationHeader.substring(7);
String jwtToken = authorizationHeader;
if (authorizationHeader.startsWith("Bearer ")) {
jwtToken = authorizationHeader.substring(7);
}
String email = jwtService.getEmailFromToken(jwtToken);
if (!Objects.isNull(email)