# Should I store JWT tokens in IndexedDB?

**URL:** <https://community.auth0.com/t/should-i-store-jwt-tokens-in-indexeddb/63100>\
**Category:** JWT.io\
**Tags:** jwt\
**Created:** [May 20, 2021, 9:31am UTC](https://community.auth0.com/t/should-i-store-jwt-tokens-in-indexeddb/63100 "2021-05-20T09:31:00Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![karandave09](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/karandave09/32/27445_2.png) [@karandave09](https://community.auth0.com/u/karandave09)\
**Post date:** [May 20, 2021, 9:31am UTC](https://community.auth0.com/t/should-i-store-jwt-tokens-in-indexeddb/63100/1 "2021-05-20T09:31:00Z")

</div>

After reading some articles, I realize that using localStorage and sessionStorage is a bad idea for storing JWT tokens, and cookies with `httpOnly` should be used instead.

As I read more and learn some about indexedDB today, I wonder if indexedDB is a secure option for storing JWT tokens as well?

Ref link: [cookies - Should I store JWT tokens in IndexedDB? - Stack Overflow](https://stackoverflow.com/questions/62360200/should-i-store-jwt-tokens-in-indexeddb)

---

<div class="post-metadata">

**Author:** ![dan.woda](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/dan.woda/32/18340_2.png) [@dan.woda](https://community.auth0.com/u/dan.woda)\
**Post date:** [May 24, 2021, 8:18pm UTC](https://community.auth0.com/t/should-i-store-jwt-tokens-in-indexeddb/63100/3 "2021-05-24T20:18:39Z")

</div>

Hi @karandave09,

Welcome to the Community!

It looks like indexedDB is subject to the same risks as localstorage and won’t solve for this.

---

<div class="post-metadata">

**Author:** ![karandave09](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/karandave09/32/27445_2.png) [@karandave09](https://community.auth0.com/u/karandave09)\
**Post date:** [May 27, 2021, 7:40am UTC](https://community.auth0.com/t/should-i-store-jwt-tokens-in-indexeddb/63100/4 "2021-05-27T07:40:02Z")

</div>

Hey @dan.woda,

Thank you for your reply.

Wanted a suggestion;  
So where should one store jwt token for a complete client-side (kind of a widget) single page application?

---

<div class="post-metadata">

**Author:** ![dan.woda](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/dan.woda/32/18340_2.png) [@dan.woda](https://community.auth0.com/u/dan.woda)\
**Post date:** [May 27, 2021, 7:06pm UTC](https://community.auth0.com/t/should-i-store-jwt-tokens-in-indexeddb/63100/5 "2021-05-27T19:06:49Z")

</div>

We recommend [refresh token rotation](https://auth0.com/docs/tokens/refresh-tokens/refresh-token-rotation), or [silent authentication](https://auth0.com/docs/authorization/configure-silent-authentication) (based on a cookie session), to get new access tokens in SPAs without leaving them vulnerable to XSS attacks in localstorage.

If you haven’t looking into using our SPA SDK, I highly recommend it.

> **[GitHub - auth0/auth0-spa-js: Auth0 authentication for Single Page...](https://github.com/auth0/auth0-spa-js)**
>
> Auth0 authentication for Single Page Applications (SPA) with PKCE - GitHub - auth0/auth0-spa-js: Auth0 authentication for Single Page Applications (SPA) with PKCE

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/auth0/original/3X/b/5/b560f266932fcce5d57f09a6595bd50518cae3f3.jpeg) [@system](https://community.auth0.com/u/system)\
**Post date:** [June 11, 2021, 7:07pm UTC](https://community.auth0.com/t/should-i-store-jwt-tokens-in-indexeddb/63100/6 "2021-06-11T19:07:16Z")

</div>

This topic was automatically closed 15 days after the last reply. New replies are no longer allowed.
