@sapphire/plugin-api
Advanced tools
Comparing version 2.0.2 to 2.0.3
@@ -6,2 +6,8 @@ # Change Log | ||
## [2.0.3](https://github.com/sapphire-project/plugins/compare/@sapphire/plugin-api@2.0.2...@sapphire/plugin-api@2.0.3) (2021-02-16) | ||
### Bug Fixes | ||
- **plugin-api:** automatically remove cookie on invalid token ([#62](https://github.com/sapphire-project/plugins/issues/62)) ([5ce667e](https://github.com/sapphire-project/plugins/commit/5ce667ed6fc1eb1b2b88fea7698041d71c4579b7)) | ||
## [2.0.2](https://github.com/sapphire-project/plugins/compare/@sapphire/plugin-api@2.0.1...@sapphire/plugin-api@2.0.2) (2021-02-13) | ||
@@ -8,0 +14,0 @@ |
@@ -10,2 +10,3 @@ import type { ApiRequest } from './ApiRequest'; | ||
add(name: string, value: string, options?: SecureCookieStoreSetOptions): void; | ||
remove(name: string): void; | ||
protected insert(name: string, entry: string): void; | ||
@@ -12,0 +13,0 @@ protected prepare(name: string, value: string, { expires, maxAge, domain, path, httpOnly }?: SecureCookieStoreSetOptions): string; |
@@ -59,2 +59,5 @@ "use strict"; | ||
} | ||
remove(name) { | ||
this.add(name, '', { expires: new Date(0) }); | ||
} | ||
insert(name, entry) { | ||
@@ -61,0 +64,0 @@ let set = this.response.getHeader('Set-Cookie'); |
@@ -20,4 +20,12 @@ "use strict"; | ||
run(request, response) { | ||
// If there are no cookies, set auth as null: | ||
const authorization = response.cookies.get(this.cookieName); | ||
request.auth = authorization ? this.context.server.auth.decrypt(authorization) : null; | ||
if (!authorization) { | ||
request.auth = null; | ||
return; | ||
} | ||
// Decrypt the cookie, and if the token is invalid, remove the cookie: | ||
request.auth = this.context.server.auth.decrypt(authorization); | ||
if (request.auth === null) | ||
response.cookies.remove(this.cookieName); | ||
} | ||
@@ -24,0 +32,0 @@ } |
@@ -51,3 +51,3 @@ "use strict"; | ||
// Sending an empty cookie with "expires" set to 1970-01-01 makes the browser instantly remove the cookie. | ||
response.cookies.add(this.context.server.auth.cookie, '', { expires: new Date(0) }); | ||
response.cookies.remove(this.context.server.auth.cookie); | ||
return response.json({ success: true }); | ||
@@ -54,0 +54,0 @@ } |
{ | ||
"name": "@sapphire/plugin-api", | ||
"version": "2.0.2", | ||
"version": "2.0.3", | ||
"description": "Plugin for @sapphire/framework to expose a REST API", | ||
@@ -83,3 +83,3 @@ "author": "@sapphire", | ||
}, | ||
"gitHead": "f8102b3f296c3287d9dc965c19743c25529524b2" | ||
"gitHead": "a7641e736d3cb7351e35428d21666518f13b7996" | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
201730
3229