Skip to content
Permalink
Browse files
fix(storage): accept expires as a number for cookie
thanks to @enVolt
  • Loading branch information
pooya parsa committed May 31, 2019
1 parent c5e742b commit dd92ec89a7aafa04e1b95148db1940504fc08a1a
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
@@ -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**.

@@ -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) {

0 comments on commit dd92ec8

Please sign in to comment.