@sapphire/plugin-api
Version:
Plugin for @sapphire/framework to expose a REST API
27 lines (25 loc) • 945 B
JavaScript
import { __name, __publicField } from '../chunk-S573YWRP.mjs';
import { Middleware } from '../lib/structures/Middleware.mjs';
var _PluginMiddleware = class _PluginMiddleware extends Middleware {
constructor(context) {
super(context, { position: 40 });
__publicField(this, "cookieName");
const { server } = this.container;
this.cookieName = server.auth?.cookie ?? "SAPPHIRE_AUTH";
this.enabled = server.auth !== null;
}
run(request, response) {
const authorization = response.cookies.get(this.cookieName);
if (!authorization) {
request.auth = null;
return;
}
request.auth = this.container.server.auth.decrypt(authorization);
if (request.auth === null) response.cookies.remove(this.cookieName);
}
};
__name(_PluginMiddleware, "PluginMiddleware");
var PluginMiddleware = _PluginMiddleware;
export { PluginMiddleware };
//# sourceMappingURL=auth.mjs.map
//# sourceMappingURL=auth.mjs.map