mirror of
https://github.com/docmost/docmost.git
synced 2026-05-17 14:54:05 +08:00
24 lines
641 B
TypeScript
24 lines
641 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) {
|
|
setCurrentUser(data);
|
|
}
|
|
}, [data, isLoading, setCurrentUser]);
|
|
|
|
if (isLoading) return <></>;
|
|
|
|
if (error) {
|
|
return <>an error occurred</>;
|
|
}
|
|
|
|
return <>{children}</>;
|
|
}
|