mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-27 02:42:25 +08:00
chore: drop old client support (#14369)
This commit is contained in:
@@ -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 } : {}),
|
||||
},
|
||||
});
|
||||
};
|
||||
|
||||
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user