Skip to content

Commit dd92ec8

Browse files
author
pooya parsa
committed
fix(storage): accept expires as a number for cookie
thanks to @enVolt
1 parent c5e742b commit dd92ec8

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

docs/api/options.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,9 +87,10 @@ auth: {
8787
```
8888

8989
* **prefix** - Default token prefix used in building a key for token storage in the browser's localStorage.
90-
* **options** - Additional cookie options, passed to [js-cookie](https://github.com/js-cookie/js-cookie) `set` and `get` functions. See full details on options they support and their defaults [here](https://github.com/js-cookie/js-cookie#cookie-attributes), which includes:
90+
* **options** - Additional cookie options, passed to [cookie](https://www.npmjs.com/package/cookie).
9191
* `path` - path where the cookie is visible. Default is '/'.
9292
* `expires` - can be used to specify cookie lifetime in `Number` of days or specific `Date`. Default is session only.
93+
* `maxAge` - Specifies the number (in seconds) to be the value for the `Max-Age` (preferred over `expires`)
9394
* `domain` - domain (and by extension subdomain/s) where the cookie is visible. Default is domain and all subdomains.
9495
* `secure` - sets whether the cookie requires a secure protocol (https). Default is false, **should be set to true if possible**.
9596

lib/core/storage.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,11 @@ export default class Storage {
214214
_options.maxAge = -1
215215
}
216216

217+
// Accept expires as a number for js-cookie compatiblity
218+
if (typeof _options.expires === 'number') {
219+
_options.expires = new Date(new Date() * 1 + _options.expires * 864e+5)
220+
}
221+
217222
const serializedCookie = serializeCookie(_key, _value, _options)
218223

219224
if (process.client) {

0 commit comments

Comments
 (0)