Implement frontend auth and user features - WIP

This commit is contained in:
Philipinho
2023-08-27 21:38:59 +01:00
parent 3e7c2de9a4
commit 54a748ced7
30 changed files with 765 additions and 6 deletions
@@ -0,0 +1,25 @@
"use client"
import { useAtom } from "jotai";
import { currentUserAtom } from "@/features/user/atoms/current-user-atom";
import { 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}</>
}