feat: 认证相关

This commit is contained in:
2025-09-06 19:56:13 +08:00
parent 5a25f350c7
commit cd99485c9a
13 changed files with 148 additions and 45 deletions

View File

@@ -0,0 +1,23 @@
import type Koa from 'koa';
import type { Middleware } from './types.ts';
export class Authorization implements Middleware {
private readonly ignoreAuth = [
'/api/auth/login',
'/api/auth/info',
'/api/auth/url',
];
apply(app: Koa) {
app.use(async (ctx: Koa.Context, next: Koa.Next) => {
console.log('ctx.path', ctx.path)
if (this.ignoreAuth.includes(ctx.path)) {
return next();
}
if (ctx.session.isNew) {
ctx.throw(401, 'Unauthorized');
}
await next();
});
}
}