Skip to content

Commit

Permalink
feat/BibimMandu-IssueTacker#215: 로그인 사용자 context 구현
Browse files Browse the repository at this point in the history
  • Loading branch information
qkdflrgs committed Aug 18, 2023
1 parent 6a38c0e commit 5d70906
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions FE/src/context/AuthContext.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { createContext, useContext, useState, ReactNode } from "react";
import { UserProfile } from "../type";

interface AuthContextType {
profile: UserProfile | undefined;
updateProfile(data: UserProfile): void;
}

const AuthContext = createContext<AuthContextType | undefined>(undefined);

interface AuthProviderProps {
children: ReactNode;
}

export function AuthProvider({ children }: AuthProviderProps) {
const [profile, setProfile] = useState<UserProfile>();

const updateProfile = (data: UserProfile) => {
setProfile(data);
};

return (
<AuthContext.Provider value={{ profile, updateProfile }}>
{children}
</AuthContext.Provider>
);
}

export function useAuth(): AuthContextType {
const context = useContext(AuthContext);
if (!context) {
throw new Error("useAuth must be used within an AuthProvider");
}
return context;
}

0 comments on commit 5d70906

Please sign in to comment.