fix:新建项目更新项目选项
This commit is contained in:
@@ -48,6 +48,7 @@ type AuthContextValue = {
|
||||
login: (username: string, password: string) => Promise<void>;
|
||||
logout: () => Promise<void>;
|
||||
setCurrentWorkspace: (workspaceId: string) => void;
|
||||
refreshWorkspaces: () => Promise<void>;
|
||||
};
|
||||
|
||||
const AuthContext = createContext<AuthContextValue | null>(null);
|
||||
@@ -167,6 +168,23 @@ export function AuthProvider({ children }: { children: ReactNode }) {
|
||||
window.localStorage.setItem(workspaceStorageKey, workspace.workspace_id);
|
||||
}, [workspaces]);
|
||||
|
||||
const refreshWorkspaces = useCallback(async () => {
|
||||
try {
|
||||
const session = await authRequest<AuthSession>("/api/v1/auth/me");
|
||||
const storedId = typeof window === "undefined"
|
||||
? null
|
||||
: window.localStorage.getItem(workspaceStorageKey);
|
||||
const newWorkspace = selectWorkspace(session, storedId);
|
||||
setWorkspaces(session.workspaces);
|
||||
setWorkspace(newWorkspace);
|
||||
if (newWorkspace && typeof window !== "undefined") {
|
||||
window.localStorage.setItem(workspaceStorageKey, newWorkspace.workspace_id);
|
||||
}
|
||||
} catch (error) {
|
||||
console.error("刷新 workspace 列表失败:", error);
|
||||
}
|
||||
}, []);
|
||||
|
||||
const value = useMemo<AuthContextValue>(() => ({
|
||||
user,
|
||||
workspaces,
|
||||
@@ -175,7 +193,8 @@ export function AuthProvider({ children }: { children: ReactNode }) {
|
||||
login,
|
||||
logout,
|
||||
setCurrentWorkspace,
|
||||
}), [currentWorkspace, loading, login, logout, setCurrentWorkspace, user, workspaces]);
|
||||
refreshWorkspaces,
|
||||
}), [currentWorkspace, loading, login, logout, setCurrentWorkspace, user, workspaces, refreshWorkspaces]);
|
||||
|
||||
if (loading) {
|
||||
return (
|
||||
|
||||
Reference in New Issue
Block a user