fix(workspace): check affine login auth (#2070)

This commit is contained in:
Himself65
2023-04-21 20:44:29 -05:00
committed by GitHub
parent 2c95a0a757
commit 1ca9fb8ff4
19 changed files with 211 additions and 73 deletions

View File

@@ -403,7 +403,7 @@ export function createWorkspaceApis(prefixUrl = '/') {
},
})
.then(r =>
r.status === 403
!r.ok
? Promise.reject(new RequestError(MessageCode.noPermission))
: r
)

View File

@@ -4,6 +4,8 @@ import {
isExpired,
parseIdToken,
} from '@affine/workspace/affine/login';
import { WorkspaceFlavour } from '@affine/workspace/type';
import { cleanupWorkspace } from '@affine/workspace/utils';
import { assertExists } from '@blocksuite/global/utils';
import * as url from 'lib0/url';
import * as websocket from 'lib0/websocket';
@@ -28,6 +30,10 @@ export class WebsocketClient {
public connect(callback: (message: any) => void) {
const loginResponse = getLoginStorage();
if (!loginResponse || isExpired(parseIdToken(loginResponse.token))) {
cleanupWorkspace(WorkspaceFlavour.AFFINE);
return;
}
assertExists(loginResponse, 'loginResponse is null');
const encodedParams = url.encodeQueryParams({
token: loginResponse.token,