Where to store JWT - ace-han/vue-drf-jwt GitHub Wiki
As per
https://dev.to/rdegges/please-stop-using-local-storage-1i04
https://stackoverflow.com/questions/34817617/should-jwt-be-stored-in-localstorage-or-cookie
We should stop store JWT in localStorage. Instead, we should store JWT in Cookie
- Single Page Application (SPA)
Cookie
- login set
access_tokenandrefresh_tokenin cookies- go to
next=urlif any- before ajax, get CSRF token from
js-cookieand set it in asconfig.headers['X-CSRFToken'] = $csrfTokenaccording tocsrf.pyindjango/middleware/csrf.CsrfViewMiddleware#process_view- for every ajax with response status code 4xx,
do_refresh_tokenand queue-up deferred ajax calls- if
do_refresh_tokenget a newaccess_tokenthen do the queue-up deferred ajax calls- else redirect to login
- Mobile
Android: SharedPreferences
iOS: KeyChain or UserDefault - Weapp and likewise app
localStorage
(Yes, localStorage. But we can do it withweapp-cookieto keep aligned with the operations inSPA)