UNPKG

@sapphire/plugin-api

Version:

Plugin for @sapphire/framework to expose a REST API

32 lines (29 loc) 1.3 kB
'use strict'; var Middleware_cjs = require('../lib/structures/Middleware.cjs'); var __defProp = Object.defineProperty; var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value; var __name = (target, value) => __defProp(target, "name", { value, configurable: true }); var __publicField = (obj, key, value) => __defNormalProp(obj, key + "" , value); var _PluginMiddleware = class _PluginMiddleware extends Middleware_cjs.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; exports.PluginMiddleware = PluginMiddleware; //# sourceMappingURL=auth.cjs.map //# sourceMappingURL=auth.cjs.map