-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #290 from Jaymyong66/feat/signup_login
로그아웃 기능, auth 상태를 전역으로 관리
- Loading branch information
Showing
9 changed files
with
136 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,4 +15,5 @@ export { | |
LOGIN_API_URL, | ||
LOGIN_STATE_API_URL, | ||
SIGNUP_API_URL, | ||
LOGOUT_API_URL, | ||
} from './authentication'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { createContext, useState, ReactNode } from 'react'; | ||
|
||
interface AuthContextProps { | ||
isLogin: boolean; | ||
handleLoginState: (state: boolean) => void; | ||
} | ||
|
||
export const AuthContext = createContext<AuthContextProps | undefined>(undefined); | ||
|
||
export const AuthProvider = ({ children }: { children: ReactNode }) => { | ||
const [isLogin, setIsLogin] = useState(false); | ||
|
||
const handleLoginState = (state: boolean) => { | ||
setIsLogin(state); | ||
}; | ||
|
||
return <AuthContext.Provider value={{ isLogin, handleLoginState }}>{children}</AuthContext.Provider>; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { useContext } from 'react'; | ||
|
||
import { AuthContext } from '@/contexts/authContext'; | ||
|
||
export const useAuth = () => { | ||
const context = useContext(AuthContext); | ||
|
||
if (!context) { | ||
throw new Error('useAuth must be used within an AuthProvider'); | ||
} | ||
|
||
return context; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { useMutation } from '@tanstack/react-query'; | ||
|
||
import { postLogout } from '@/api/authentication'; | ||
import { useAuth } from '@/hooks/authentication/useAuth'; | ||
|
||
export const useLogoutMutation = () => { | ||
const { handleLoginState } = useAuth(); | ||
|
||
return useMutation({ | ||
mutationFn: () => postLogout(), | ||
onSuccess: () => { | ||
handleLoginState(false); | ||
}, | ||
onError: () => { | ||
console.log('mutation'); | ||
}, | ||
}); | ||
}; |