mirror of
https://github.com/multica-ai/multica.git
synced 2026-07-24 19:41:14 +02:00
- Extract MulticaIcon and ThemeProvider to packages/ui (remove duplication) - Extract shared CSS (scrollbar, shiki, entrance-spin) to packages/ui/styles/base.css - Add NavigationAdapter.openInNewTab/getShareableUrl for platform-agnostic navigation - Fix window.open() / window.location.href in shared views to use NavigationAdapter - Add resolve.dedupe for React in electron-vite config - Fix desktop tsconfig (noImplicitAny: true) - Use catalog: for all desktop dependencies - Add shadcn + tw-animate-css to desktop dependencies (fix phantom deps) - Add typecheck scripts to all shared packages Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
55 lines
1.4 KiB
TypeScript
55 lines
1.4 KiB
TypeScript
"use client";
|
|
|
|
import { useEffect, type ReactNode } from "react";
|
|
import { getApi } from "../api";
|
|
import { useAuthStore } from "../auth";
|
|
import { useWorkspaceStore } from "../workspace";
|
|
import { createLogger } from "../logger";
|
|
import { defaultStorage } from "./storage";
|
|
import type { StorageAdapter } from "../types/storage";
|
|
|
|
const logger = createLogger("auth");
|
|
|
|
export function AuthInitializer({
|
|
children,
|
|
onLogin,
|
|
onLogout,
|
|
storage = defaultStorage,
|
|
}: {
|
|
children: ReactNode;
|
|
onLogin?: () => void;
|
|
onLogout?: () => void;
|
|
storage?: StorageAdapter;
|
|
}) {
|
|
useEffect(() => {
|
|
const token = storage.getItem("multica_token");
|
|
if (!token) {
|
|
onLogout?.();
|
|
useAuthStore.setState({ isLoading: false });
|
|
return;
|
|
}
|
|
|
|
const api = getApi();
|
|
api.setToken(token);
|
|
const wsId = storage.getItem("multica_workspace_id");
|
|
|
|
Promise.all([api.getMe(), api.listWorkspaces()])
|
|
.then(([user, wsList]) => {
|
|
onLogin?.();
|
|
useAuthStore.setState({ user, isLoading: false });
|
|
useWorkspaceStore.getState().hydrateWorkspace(wsList, wsId);
|
|
})
|
|
.catch((err) => {
|
|
logger.error("auth init failed", err);
|
|
api.setToken(null);
|
|
api.setWorkspaceId(null);
|
|
storage.removeItem("multica_token");
|
|
storage.removeItem("multica_workspace_id");
|
|
onLogout?.();
|
|
useAuthStore.setState({ user: null, isLoading: false });
|
|
});
|
|
}, []);
|
|
|
|
return <>{children}</>;
|
|
}
|