I write authentication interface in middleware
authenticate.js
module.exports = options => {
return async function auth(ctx, next) {
console.log("99999999999999999")
let { app } = this
const { redis } = app;
let sign = ctx.get("x-sign");
let user_id = ctx.get("x-user-id");
if (!user_id) {
ctx.throw(412, "invalid user id");
}
// if (!sign) {
// ctx.throw(412, "invalid sign");
// }
let token = await redis.get(user_id);
if (!token) {
ctx.throw(412, "invalid user");
}
await next();
console.log("9999999999999")
};
};
load middleware in config.default.js
config.middleware = ["authenticate"]
use psotman to request the interface, but do not use this middleware at all. What is the reason?
I disabled csrf