Where should we store the JWT for SPA? Memory, Cookie, or LocalStorage?
Published in
5 min readJun 7, 2020
Introduction
I develop an SPA application on Django/DWF recently. I used JSON Web Token (JWT) to authorize users for login and other operations. It’s Okay for me to create endpoints with JWT secure, exchange JWT with social medias’ access token.
However, the security issue is a critical issue for JWT. Where should we store the JWT? I tried some ways and wrote this note.
It includes the following topics.
- The safest place: Browser’s Memory
- Should we store JWT in the LocalStorage?
- Double tokens policy: HttpOnly Cookie + CSRF token
- Summary