I want to implement JWT auth in my Next app. Currently, I see the flow as following:
- email and password are sent to the server to log in
- server returns a response with status 200 and jwt access token in httpOnly cookies
The main problem is I don't really know which way to choose to go further. At every reloading page or starting of my Next app I want to fetch data about user, so there is endpoint, lets say /me, which returns info about the user and in the same time checks if the token expired.
Is this correct way to go down? Or it can be better? I went through every video tutorial and they just use old plain local storage, which is not very secure.
If this is a nice way, how to correctly implement this fetching of user data at every reload of app? I use Next 13