I’ve been struggling with hours of research, blogs, and YouTube video to resolve this. I’m trying to implement a login, register, logout, and currentUser routes in my controllers. I set authentication successfully in the log in route, however when I try to get the same user I authenticated in the currentUser route, I can access the principal user because it’s always null. I’ve tried billions of implementations and I’m basically now begging for assistance. The code base can found at: https://github.com/abufaarooq/productiv
Execution proceedings:
Register by sending a POST request, to: localhost:8080/api/v1/add, use the payload below:
{
“id”: 1,
“firstName”: “John”,
“lastName”:”Applesead”,
“userName”:”john123″,
“email”: “[email protected]”,
“passWord”: “1234”,
“userRole”: “USER”,
“locked”: false,
“enabled”:true
}
Send another POST request to: localhost:8080/api/v1/login, user the payload below:
{
“username”: “john123”,
“password”: “1234”
}
Send a GET request to: localhost:8080/api/v1/currentUser, no payload required – this end point return null every time. That’s where my issue lays.
Any help I can get would be appreciated. I couldn’t find anything online outside of the SecurityContextHolder being thread local. Is there an alternative solution to bypass this and persist the principal through all threads.