I'm using JWT's for user authentication on my e-commerce website. Once a user successfully logs in, I'm sending them a JWT which is stored in the browser's localstorage.
Once the client has the JWT, I'm trying to figure out the best (or a standardized) way for the client to fetch certain data for that user? This data includes their shopping cart, wishlist, order history, etc. I can think of a few possible solutions:
Include all data in the JWT. This is probably the wrong approach. Seems like only data such as
user_id
,phone_number
, andemail_address
should be stored in a JWT (source).Allow the client to parse a
user_id
(e.g.75
) from the JWT. Client then hits/users/75
(JWT required for authentication) to fetch the user's data. However, this seems redundant because both the endpoint and the JWT point to the user.Create some endpoints like
/user/shopping_cart
and/user/wishlist
for the client to hit (JWT required for authentication). The backend will determine which user is making the request based on the JWT. This seems like the better option.
I would bet option 3 is the best approach?