-
Notifications
You must be signed in to change notification settings - Fork 1
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 #91 from DoTheZ-Team/GLUE-303-로그인-id-오류-수정
GLUE-303 로그인 아이디를 쿠키에서 활용할 수 있도록 수정
- Loading branch information
Showing
8 changed files
with
29 additions
and
33 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,16 @@ | ||
import { useMutation } from '@tanstack/react-query'; | ||
import { ACCESS_TOKEN } from '@/constants'; | ||
import { ACCESS_TOKEN, BLOG_ID } from '@/constants'; | ||
import Cookies from 'js-cookie'; | ||
import { useUserContext } from '@/components/Common'; | ||
import { postLogin } from '.'; | ||
|
||
export const usePostLogin = (code: string) => { | ||
const { setLoginId } = useUserContext(); | ||
|
||
return useMutation({ | ||
mutationKey: ['login'], | ||
mutationFn: () => postLogin({ code }), | ||
|
||
onSuccess: ({ result: { accessToken, blogId } }) => { | ||
Cookies.set(ACCESS_TOKEN, accessToken); | ||
setLoginId(blogId); | ||
Cookies.set(BLOG_ID, String(blogId)); | ||
}, | ||
}); | ||
}; |
16 changes: 8 additions & 8 deletions
16
src/app/mypage/components/MyPageFetcher/MyPageContext/MyPageProviderWrapper.tsx
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 |
---|---|---|
@@ -1,25 +1,25 @@ | ||
'use client'; | ||
|
||
import { useState } from 'react'; | ||
import { useMemo, useState } from 'react'; | ||
import { MyPageResponse } from '../types'; | ||
import { MyPageProvider } from './index'; | ||
|
||
export function MyPageProviderWrapper({ | ||
children, | ||
initialData, | ||
blogId, | ||
}: { | ||
children: React.ReactNode; | ||
initialData: MyPageResponse; | ||
blogId: number; | ||
}) { | ||
const [myPageData, setMyPageData] = useState<MyPageResponse>(initialData); | ||
|
||
const contextValue = { | ||
blogId, | ||
myPageData, | ||
setMyPageData, | ||
}; | ||
const contextValue = useMemo( | ||
() => ({ | ||
myPageData, | ||
setMyPageData, | ||
}), | ||
[myPageData, setMyPageData], | ||
); | ||
|
||
return <MyPageProvider {...contextValue}>{children}</MyPageProvider>; | ||
} |
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
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