refactor(core): initial multiple servers infra (#8745)

This is the initial refactoring of affine to support multiple servers, but many more changes are needed to make multi-server actually work.
This commit is contained in:
EYHN
2024-11-27 06:44:46 +00:00
parent 3f4cb5be40
commit 6b4a1aa917
80 changed files with 1141 additions and 519 deletions

View File

@@ -15,7 +15,7 @@ import {
useNavigationType,
} from 'react-router-dom';
import { AuthService } from '../../cloud';
import { AuthService, ServersService } from '../../cloud';
import type { DesktopApi } from '../entities/electron-api';
@OnEvent(ApplicationStarted, e => e.setupStartListener)
@@ -140,10 +140,19 @@ export class DesktopApiService extends Service {
private setupAuthRequestEvent() {
this.events.ui.onAuthenticationRequest(({ method, payload }) => {
(async () => {
const authService = this.framework.get(AuthService);
if (!(await this.api.handler.ui.isActiveTab())) {
return;
}
// TODO: support multiple servers
const affineCloudServer = this.framework
.get(ServersService)
.server$('affine-cloud').value;
if (!affineCloudServer) {
throw new Error('Affine Cloud server not found');
}
const authService = affineCloudServer.scope.get(AuthService);
switch (method) {
case 'magic-link': {
const { email, token } = payload;