feat: bare client for non-auth apis

This commit is contained in:
DarkSky
2022-12-22 19:05:16 +08:00
parent c2ce4927c8
commit 593bb77921
7 changed files with 53 additions and 47 deletions
@@ -13,7 +13,7 @@ import type {
LoadWorkspaceHandler,
CreateEditorHandler,
} from './context';
import { downloadWorkspace, getToken } from '@pathfinder/data-services';
import { downloadWorkspace, token } from '@pathfinder/data-services';
import { WebsocketProvider } from './y-websocket';
const getEditorParams = (workspaceId: string) => {
@@ -55,11 +55,9 @@ const DynamicBlocksuite = ({
providers: [IndexedDBDocProvider],
}).register(BlockSchema);
const refreshToken = getToken()?.refreshToken;
if (
websocket &&
refreshToken &&
token.refresh &&
location.search.includes('sync=websocket')
) {
// FIXME: if add websocket provider, the first page will be blank
@@ -71,7 +69,7 @@ const DynamicBlocksuite = ({
workspace.doc,
{
params: {
token: refreshToken,
token: token.refresh,
},
awareness: workspace.meta.awareness.awareness,
}
@@ -2,11 +2,9 @@ import { useMemo, useState, useEffect, useCallback, useRef } from 'react';
import type { ReactNode } from 'react';
import dynamic from 'next/dynamic';
import {
authorizationEvent,
token,
AccessTokenMessage,
getWorkspaces,
WorkspaceType,
getWorkspaceDetail,
} from '@pathfinder/data-services';
import { AppState, AppStateContext } from './context';
import type {
@@ -171,10 +169,10 @@ export const AppStateProvider = ({ children }: { children?: ReactNode }) => {
synced: true,
}));
};
authorizationEvent.onChange(callback);
token.onChange(callback);
return () => {
authorizationEvent.removeCallback(callback);
token.offChange(callback);
};
}, [loadWorkspaceHandler]);