mirror of
https://github.com/docmost/docmost.git
synced 2026-05-07 14:43:06 +08:00
38ef610e5e
* integrate websocket redis adapter * use APP_SECRET for jwt signing * auto migrate database on startup in production * add updatedAt to update db operations * create enterprise ee package directory * fix comment editor focus * other fixes
26 lines
697 B
TypeScript
26 lines
697 B
TypeScript
import { useAtom } from "jotai";
|
|
import { currentUserAtom } from "@/features/user/atoms/current-user-atom";
|
|
import React, { useEffect } from "react";
|
|
import useCurrentUser from "@/features/user/hooks/use-current-user";
|
|
|
|
export function UserProvider({ children }: React.PropsWithChildren) {
|
|
const [, setCurrentUser] = useAtom(currentUserAtom);
|
|
const { data, isLoading, error } = useCurrentUser();
|
|
|
|
useEffect(() => {
|
|
if (data && data.user && data.workspace) {
|
|
setCurrentUser(data);
|
|
}
|
|
}, [data, isLoading]);
|
|
|
|
if (isLoading) return <></>;
|
|
|
|
if (!data?.user && !data?.workspace) return <></>;
|
|
|
|
if (error) {
|
|
return <>an error occurred</>;
|
|
}
|
|
|
|
return <>{children}</>;
|
|
}
|