mirror of
https://github.com/aaronpo97/the-biergarten-app.git
synced 2026-02-16 20:13:49 +00:00
update: add delete user api route, AuthProvider extracted from App.tsx
This commit is contained in:
24
src/contexts/UserContext.tsx
Normal file
24
src/contexts/UserContext.tsx
Normal file
@@ -0,0 +1,24 @@
|
||||
import useUser from '@/hooks/auth/useUser';
|
||||
import GetUserSchema from '@/services/User/schema/GetUserSchema';
|
||||
import { ReactNode, createContext } from 'react';
|
||||
import { z } from 'zod';
|
||||
|
||||
const UserContext = createContext<{
|
||||
user?: z.infer<typeof GetUserSchema>;
|
||||
error?: unknown;
|
||||
isLoading: boolean;
|
||||
mutate?: ReturnType<typeof useUser>['mutate'];
|
||||
}>({ isLoading: true });
|
||||
|
||||
export default UserContext;
|
||||
|
||||
type AuthProviderComponent = (props: { children: ReactNode }) => JSX.Element;
|
||||
|
||||
export const AuthProvider: AuthProviderComponent = ({ children }) => {
|
||||
const { error, isLoading, mutate, user } = useUser();
|
||||
return (
|
||||
<UserContext.Provider value={{ isLoading, error, mutate, user }}>
|
||||
{children}
|
||||
</UserContext.Provider>
|
||||
);
|
||||
};
|
||||
Reference in New Issue
Block a user