Skip to content

There can be more than Notion and Miro. AFFiNE(pronounced [ə‘fain]) is a next-gen knowledge base that brings planning, sorting and creating all together. Privacy first, open-source, customizable and ready to use.

fix(server): hotfix auth & doc push (#6168)

liuyia721b3887ba4
diff --git a/packages/backend/server/src/core/auth/guard.ts b/packages/backend/server/src/core/auth/guard.ts
index d1ff3ab89d..a60822001e 100644
--- a/packages/backend/server/src/core/auth/guard.ts
+++ b/packages/backend/server/src/core/auth/guard.ts
@@ -11,7 +11,7 @@ import {
} from '@nestjs/common';
import { ModuleRef, Reflector } from '@nestjs/core';
-import { Config, getRequestResponseFromContext } from '../../fundamentals';
+import { getRequestResponseFromContext } from '../../fundamentals';
import { AuthService, parseAuthUserSeqNum } from './service';
function extractTokenFromHeader(authorization: string) {
@@ -27,7 +27,6 @@ export class AuthGuard implements CanActivate, OnModuleInit {
private auth!: AuthService;
constructor(
- private readonly config: Config,
private readonly ref: ModuleRef,
private readonly reflector: Reflector
) {}
@@ -43,17 +42,6 @@ export class AuthGuard implements CanActivate, OnModuleInit {
let sessionToken: string | undefined =
req.cookies[AuthService.sessionCookieName];
- // backward compatibility for client older then 0.12
- // TODO: remove
- if (!sessionToken) {
- sessionToken =
- req.cookies[
- this.config.https
- ? '__Secure-next-auth.session-token'
- : 'next-auth.session-token'
- ];
- }
-
if (!sessionToken && req.headers.authorization) {
sessionToken = extractTokenFromHeader(req.headers.authorization);
}
diff --git a/packages/backend/server/src/core/doc/manager.ts b/packages/backend/server/src/core/doc/manager.ts
index faa50ecc7d..87c09fd826 100644
--- a/packages/backend/server/src/core/doc/manager.ts
+++ b/packages/backend/server/src/core/doc/manager.ts
@@ -272,11 +272,15 @@ export class DocManager implements OnModuleInit, OnModuleDestroy {
updates: Buffer[],
retryTimes = 10
) {
- const lastSeq = await this.getUpdateSeq(workspaceId, guid, updates.length);
- const now = Date.now();
- let timestamp = now;
- await new Promise<void>((resolve, reject) => {
+ const timestamp = await new Promise<number>((resolve, reject) => {
defer(async () => {
+ const lastSeq = await this.getUpdateSeq(
+ workspaceId,
+ guid,
+ updates.length
+ );
+ const now = Date.now();
+ let timestamp = now;
let turn = 0;
const batchCount = 10;
for (const batch of chunk(updates, batchCount)) {
@@ -303,14 +307,16 @@ export class DocManager implements OnModuleInit, OnModuleDestroy {
});
turn++;
}
+
+ return timestamp;
})
.pipe(retry(retryTimes)) // retry until seq num not conflict
.subscribe({
- next: () => {
+ next: timestamp => {
this.logger.debug(
`pushed ${updates.length} updates for ${guid} in workspace ${workspaceId}`
);
- resolve();
+ resolve(timestamp);
},
error: e => {
this.logger.error('Failed to push updates', e);