Skip to content

Commit

Permalink
fix(storage): accept expires as a number for cookie
Browse files Browse the repository at this point in the history
thanks to @enVolt
  • Loading branch information
pooya parsa committed May 31, 2019
1 parent c5e742b commit dd92ec8
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
3 changes: 2 additions & 1 deletion docs/api/options.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,10 @@ auth: {
```

* **prefix** - Default token prefix used in building a key for token storage in the browser's localStorage.
* **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:
* **options** - Additional cookie options, passed to [cookie](https://www.npmjs.com/package/cookie).
* `path` - path where the cookie is visible. Default is '/'.
* `expires` - can be used to specify cookie lifetime in `Number` of days or specific `Date`. Default is session only.
* `maxAge` - Specifies the number (in seconds) to be the value for the `Max-Age` (preferred over `expires`)
* `domain` - domain (and by extension subdomain/s) where the cookie is visible. Default is domain and all subdomains.
* `secure` - sets whether the cookie requires a secure protocol (https). Default is false, **should be set to true if possible**.

Expand Down
5 changes: 5 additions & 0 deletions lib/core/storage.js
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,11 @@ export default class Storage {
_options.maxAge = -1
}

// Accept expires as a number for js-cookie compatiblity
if (typeof _options.expires === 'number') {
_options.expires = new Date(new Date() * 1 + _options.expires * 864e+5)
}

const serializedCookie = serializeCookie(_key, _value, _options)

if (process.client) {
Expand Down

0 comments on commit dd92ec8

Please sign in to comment.