core: handle CsrfTokenError and DomainNotFoundError

This commit is contained in:
undefined committed 2022-11-14 20:20:00 +08:00
1 parent 00f83d805a
commit 3371f39ef4
2 files changed
+6 -2

No files matched your search

+5 -2
View File
@@ -17,10 +17,13 @@ export default async (ctx: KoaContext, next) => {
if (user._id === 0) delete user.viewLang;
user.avatarUrl = avatar(user.avatar, 128);
ctx.HydroContext.user = user;
if (!domain) throw new NotFoundError(args.domainId);
if (!domain) {
ctx.pendingError = new NotFoundError(args.domainId);
args.domainId = 'system';
}
if (request.method === 'post' && request.headers.referer) {
const host = new URL(request.headers.referer).host;
if (host !== request.host) throw new CsrfTokenError(host);
if (host !== request.host) ctx.pendingError = new CsrfTokenError(host);
}
await next();
};