Search code examples
djangofrontendauthorizationaccess-tokenrefresh-token

Django Frontend Autho key and refresh key


I would like to separate my Django frontend and backend. Literally creating 2 Django servers.

What is the best way to store auth access-token and refresh-token on frontend?

What is the best way to validate auth when API is called?

Thanks!


Solution

  • Read about storing jwt on frontend here :

    Should JWT be stored in localStorage or cookie?

    Basically, there can be two ways, either storing it in localstorage or HTTP Cookie. Read about pros and cons of both approach and decide what suits you best. In API, it's best to pass access token in header of request and validating the same using a Django Middleware. Send a refresh request from your frontend if the reponse returns an Unauthorized error and error message something like "Token Expired", which will be created by you on the backend. See this package for more :

    https://django-rest-framework-simplejwt.readthedocs.io/en/latest/