Do not receive Headers from Front-end with JWT

Hi, I work on a website and I send a token with axios with the front-end
export default {
data() {
return {
produits: [] // Tableau pour stocker les produits
};
},
created() {
// Appel à l'API pour récupérer les produits
axios
.get("http://localhost:8080/api/produits", {
headers: {
"Authorization": `Bearer ${localStorage.getItem("token")}`
}
}) // URL du back-end
.then((response) => {
this.produits = response.data; // On stocke les produits dans la variable produits
console.log("Produits après assignation : ", this.produits);
})
.catch((error) => {
console.error("Il y a une erreur lors de la récupération des produits : ", error);
});
}
};
export default {
data() {
return {
produits: [] // Tableau pour stocker les produits
};
},
created() {
// Appel à l'API pour récupérer les produits
axios
.get("http://localhost:8080/api/produits", {
headers: {
"Authorization": `Bearer ${localStorage.getItem("token")}`
}
}) // URL du back-end
.then((response) => {
this.produits = response.data; // On stocke les produits dans la variable produits
console.log("Produits après assignation : ", this.produits);
})
.catch((error) => {
console.error("Il y a une erreur lors de la récupération des produits : ", error);
});
}
};
but my jwt filter don't see the headers Authorization, it's always null I don"t know why. The filter is used with SecurityConfig with addFilterBefore(...)
public class JwtFilter extends OncePerRequestFilter {

private final UserService userService;
private final JwtUtils jwtUtils;

@Override
protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) throws ServletException, IOException {
System.out.println("Executing JWT Filter");
System.out.println("request: " + request);

// Permet de récupérer le token via le header
final String authorizationHeader = request.getHeader("Authorization");
System.out.println("Authorization header: " + authorizationHeader);

String email = null;
String jwt = null;

//-----

}
public class JwtFilter extends OncePerRequestFilter {

private final UserService userService;
private final JwtUtils jwtUtils;

@Override
protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) throws ServletException, IOException {
System.out.println("Executing JWT Filter");
System.out.println("request: " + request);

// Permet de récupérer le token via le header
final String authorizationHeader = request.getHeader("Authorization");
System.out.println("Authorization header: " + authorizationHeader);

String email = null;
String jwt = null;

//-----

}
`
2 Replies
JavaBot
JavaBot4w ago
This post has been reserved for your question.
Hey @Maxence! Please use /close or the Close Post button above when your problem is solved. Please remember to follow the help guidelines. This post will be automatically marked as dormant after 300 minutes of inactivity.
TIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here. 💤 Post marked as dormant
This post has been inactive for over 300 minutes, thus, it has been archived. If your question was not answered yet, feel free to re-open this post or create a new one. In case your post is not getting any attention, you can try to use /help ping. Warning: abusing this will result in moderative actions taken against you.
JavaBot
JavaBot4w ago
Post Closed
This post has been closed by <@429241766257098752> for the following reason:
no help

Did you find this page helpful?