DEV Community

loading...

Discussion on: API Guard - JWT authentication solution for Rails APIs

gokul595 profile image
Gokul Murali Author

Hi Bora, You are right. You can store the JWT in the local storage and pass it in the request header every time in the API.

For displaying current user profile you can create an API (Ex: /profile) and just add the before_action: authenticate_and_set_user and you will have the current logged in user object in the @current_user instance variable which you can send in the response and use it in the Front end. You can call this API request whenever your web app loads in the browser and show those details.

Let me know if this clarifies.

Thread Thread
borasumer profile image
Bora Sumer

Yeah, I have handled it that way, the only thing it is missing is the forgot password functionality. I think I can just update the password field of the user by sending a a request to the controller with the token. That should do it securely I assume. Thank you for your help again Gokul. Really appreciated.