I have a DRF project using Simple-JWT for authentication. When a user logs in, they get a response containing the access and refresh tokens in the serializer.data. However:
When testing on the Apis I can manually copy and paste these tokens and add them to headers when making requests. However in production,
- Where are these tokens stored on the user's side?
- How will the user be able to add the
accesstoken to requests that are protected? (they can't copy-paste like me) - How will they use the
refreshtoken to renew theaccesstoken.
So, if you're talking about the client side, where users will be using your application using the front-end:
The tokens can be stored on local storage of your browser
All the authenticated URL requests must contain a bearer token where you will add the
access_tokenwhich your API will return after authentication and is currently saved in your local storage.for getting refresh token, add a URL like below where you will send a post request:
Finally someone can use this code on JS side for saving or retrieving tokens from
localstorage: