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
@@ -4,6 +4,24 @@ import { AuthProvider } from '../provider/auth';
import { ServerScope } from '../scopes/server';
import { FetchService } from '../services/fetch';
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 function configureDefaultAuthProvider(framework: Framework) {
framework.scope(ServerScope).override(AuthProvider, resolver => {
const fetchService = resolver.get(FetchService);
@@ -62,7 +80,11 @@ export function configureDefaultAuthProvider(framework: Framework) {
});
},
async signOut() {
await fetchService.fetch('/api/auth/sign-out');
const csrfToken = getCookieValue(CSRF_COOKIE_NAME);
await fetchService.fetch('/api/auth/sign-out', {
method: 'POST',
headers: csrfToken ? { 'x-affine-csrf-token': csrfToken } : undefined,
});
},
};
});
@@ -165,6 +165,32 @@ export class AuthService extends Service {
}
}
async createOpenAppSignInCode() {
const res = await this.fetchService.fetch(
'/api/auth/open-app/sign-in-code',
{
method: 'POST',
}
);
const body = (await res.json()) as { code?: string };
if (!body.code) {
throw new Error('Missing open-app sign-in code');
}
return body.code;
}
async signInOpenAppSignInCode(code: string) {
await this.fetchService.fetch('/api/auth/open-app/sign-in', {
method: 'POST',
body: JSON.stringify({ code }),
headers: { 'content-type': 'application/json' },
});
this.session.revalidate();
}
async signInPassword(credential: {
email: string;
password: string;
@@ -146,6 +146,14 @@ export class DesktopApiService extends Service {
await authService.signInOauth(code, state, provider);
break;
}
case 'open-app-signin': {
const code = (payload as { code?: unknown }).code;
if (typeof code !== 'string' || !code) {
throw new Error('Invalid open-app sign-in payload');
}
await authService.signInOpenAppSignInCode(code);
break;
}
}
})().catch(e => {
notify.error({