revision 확인과 서버 event 기반 선택 갱신은 무가점으로 두고 PostgreSQL projection을 다시 만드는 초기·수동·복구 갱신만 1점을 기록한다. 인증 범위에 묶인 1회용 realtime 증표와 회귀 검증을 추가한다.
29 lines
1008 B
TypeScript
29 lines
1008 B
TypeScript
import { createTRPCProxyClient, httpBatchLink } from '@trpc/client';
|
|
import type { AppRouter } from '@sammo-ts/game-api';
|
|
import { REALTIME_ACCESS_GRANT_HEADER } from '@sammo-ts/common';
|
|
import { resolveBatchRealtimeAccessGrant } from './realtimeAccessGrant';
|
|
|
|
const getGameToken = (): string | null => {
|
|
if (typeof window === 'undefined') {
|
|
return null;
|
|
}
|
|
|
|
return window.localStorage.getItem('sammo-game-token');
|
|
};
|
|
|
|
export const trpc = createTRPCProxyClient<AppRouter>({
|
|
links: [
|
|
httpBatchLink({
|
|
url: import.meta.env.VITE_GAME_API_URL ?? '/api/trpc',
|
|
headers({ opList }) {
|
|
const token = getGameToken();
|
|
const refreshGrant = resolveBatchRealtimeAccessGrant(opList);
|
|
return {
|
|
...(token ? { authorization: `Bearer ${token}` } : {}),
|
|
...(refreshGrant ? { [REALTIME_ACCESS_GRANT_HEADER]: refreshGrant } : {}),
|
|
};
|
|
},
|
|
}),
|
|
],
|
|
});
|