chore: drop old client support (#14369)

This commit is contained in:
DarkSky
2026-02-05 02:49:33 +08:00
committed by GitHub
parent de29e8300a
commit 403f16b404
103 changed files with 3293 additions and 997 deletions

View File

@@ -11,15 +11,40 @@
* @param init Request initialization options
* @returns Promise with the fetch Response
*/
const CSRF_COOKIE_NAME = 'affine_csrf_token';
function getCookieValue(name: string) {
if (typeof document === 'undefined') {
return null;
}
const cookies = document.cookie ? document.cookie.split('; ') : [];
for (const cookie of cookies) {
const idx = cookie.indexOf('=');
const key = idx === -1 ? cookie : cookie.slice(0, idx);
if (key === name) {
return idx === -1 ? '' : cookie.slice(idx + 1);
}
}
return null;
}
export const affineFetch = (
input: RequestInfo | URL,
init?: RequestInit
): Promise<Response> => {
const method = init?.method?.toUpperCase() ?? 'GET';
const csrfToken =
method !== 'GET' && method !== 'HEAD'
? getCookieValue(CSRF_COOKIE_NAME)
: null;
return fetch(input, {
...init,
headers: {
...init?.headers,
'x-affine-version': BUILD_CONFIG.appVersion,
...(csrfToken ? { 'x-affine-csrf-token': csrfToken } : {}),
},
});
};

View File

@@ -64,7 +64,7 @@ export function UserDropdown({ isCollapsed }: UserDropdownProps) {
const relative = useRevalidateCurrentUser();
const handleLogout = useCallback(() => {
affineFetch('/api/auth/sign-out')
affineFetch('/api/auth/sign-out', { method: 'POST' })
.then(() => {
toast.success('Logged out successfully');
return relative();