From 9c63c09f4d27b5e8fb64a492e650e38e46f8498e Mon Sep 17 00:00:00 2001 From: fantasticit Date: Thu, 26 May 2022 00:36:52 +0800 Subject: [PATCH] server: fix get user error --- packages/server/src/guard/document-auth.guard.ts | 3 +++ 1 file changed, 3 insertions(+) diff --git a/packages/server/src/guard/document-auth.guard.ts b/packages/server/src/guard/document-auth.guard.ts index c9278833..5a5e1ced 100644 --- a/packages/server/src/guard/document-auth.guard.ts +++ b/packages/server/src/guard/document-auth.guard.ts @@ -47,6 +47,9 @@ export class DocumentAuthorityGuard implements CanActivate { throw new HttpException('您不是该文档的创建者,无法操作', HttpStatus.FORBIDDEN); } } else if (needAuth) { + if (!user) { + throw new HttpException('请登录后使用', HttpStatus.UNAUTHORIZED); + } const authority = await this.documentService.getDocumentAuthority(documentId, user.id); if (!authority || !authority[needAuth]) { throw new HttpException('您无权操作此文档', HttpStatus.FORBIDDEN);