-
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.
* New : 로그인 관련 타입정의 * New : React Query Dev tool 설치 * New : React Query Dev tool 설치 * New : Custom Error handler 추가 * Bug : Storybook 빌드 에러 해결 * New : 로그인 기능 서버 연결
- Loading branch information
1 parent
8ac003a
commit 0ee600b
Showing
20 changed files
with
256 additions
and
39 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,8 @@ | ||
/** | ||
* 로그인 API Path | ||
*/ | ||
export const LOGIN_API_PATH = '/user/login' as const | ||
/** | ||
* 내 정보를 받아오는 Path | ||
*/ | ||
export const MY_INFO = '/user/me' as const |
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,13 +1,21 @@ | ||
import { SigninRequirement } from "@/types/auth/signin" | ||
import { LOGIN_API_PATH } from "@/const/serverPath"; | ||
import axios from "@/libs/axios"; | ||
import { SigninRequirement } from "@/types/auth/signinRequirement"; | ||
import { SigninResponseInterface } from "@/types/auth/signinResponse"; | ||
|
||
/** | ||
* 로그인 관련 로직들이 모여있는 Hook | ||
* @returns login Handler | ||
*/ | ||
export default function useLogin () { | ||
const loginHandler = (props:SigninRequirement)=>{ | ||
const {email,password} = props | ||
console.log(`email : ${email}, password : ${password}`) | ||
} | ||
return loginHandler | ||
export default function useLogin() { | ||
const loginHandler = async (props: SigninRequirement) => { | ||
const { id, password } = props; | ||
const { data } = await axios.post<SigninResponseInterface>(LOGIN_API_PATH, { | ||
id, | ||
password, | ||
}); | ||
return data; | ||
}; | ||
|
||
return {loginHandler}; | ||
} |
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,15 @@ | ||
"use server"; | ||
import { cookies } from "next/headers"; | ||
|
||
interface SetCookieInterface { | ||
key: string; | ||
value: string; | ||
httpOnly?: boolean; | ||
} | ||
export async function setCookie({ key, value, httpOnly }: SetCookieInterface) { | ||
cookies().set({ | ||
name: key, | ||
value: value, | ||
httpOnly: httpOnly ?? true, | ||
}); | ||
} |
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,40 @@ | ||
"use client"; | ||
import useLogin from "@/hooks/useLogin"; | ||
import { SigninRequirement } from "@/types/auth/signinRequirement"; | ||
import { useMutation, useQueryClient } from "@tanstack/react-query"; | ||
import { userInfoQueryKeys } from "./useUserInfoQuery"; | ||
|
||
const useLoginMutation = () => { | ||
const { loginHandler } = useLogin(); | ||
const queryClient = useQueryClient(); | ||
|
||
return useMutation({ | ||
mutationKey: LoginMuataionKey.all, | ||
mutationFn: async ({ id, password }: SigninRequirement) => | ||
await loginHandler({ id, password }), | ||
// 로그인에 성공한 경우, 토큰을 로컬스토리지에 저장, 이전 로그인 쿼리를 인벨리데이트 | ||
onSuccess: async ({ token }) => { | ||
localStorage?.setItem("accessToken", token); | ||
queryClient.invalidateQueries({ queryKey: userInfoQueryKeys.all }); | ||
}, | ||
}); | ||
}; | ||
|
||
/** | ||
* | ||
* @param id | ||
* @returns | ||
*/ | ||
export const LoginMuataionKey = { | ||
/** | ||
* 모든 로그인 관련 키 | ||
*/ | ||
all: ["login"] as const, | ||
/** | ||
* Id 를 기반으로 로그인뮤테이션 키를 리턴 | ||
* @param id 유저아이디 | ||
* @returns 로그인뮤테이션 키 | ||
*/ | ||
byId: (id: SigninRequirement["id"]) => [...LoginMuataionKey.all, id] as const, | ||
}; | ||
export default useLoginMutation; |
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,33 @@ | ||
"use client"; | ||
import { MY_INFO } from "@/const/serverPath"; | ||
import axios from "@/libs/axios"; | ||
import { MyInfoInterface } from "@/types/auth/myInfo"; | ||
import { SigninRequirement } from "@/types/auth/signinRequirement"; | ||
import { useSuspenseQuery } from "@tanstack/react-query"; | ||
|
||
export const useUserInfoQuery = () => | ||
useSuspenseQuery({ | ||
queryKey: userInfoQueryKeys.all, | ||
queryFn: getMyInfoByLocalStorage, | ||
}); | ||
|
||
export const getMyInfoByLocalStorage = async () => { | ||
const accessToken = localStorage.get("accessToken"); | ||
const { data } = await axios.get<MyInfoInterface>(MY_INFO, { | ||
headers: { Authorization: accessToken } | ||
}); | ||
return data; | ||
}; | ||
|
||
export const userInfoQueryKeys = { | ||
/** | ||
* 모든 로그인 관련 쿼리키 | ||
*/ | ||
all: ["me"], | ||
/** | ||
* Id 를 기반으로 로그인뮤테이션 키를 리턴 | ||
* @param id 유저아이디 | ||
* @returns 로그인뮤테이션 키 | ||
*/ | ||
byId: (id: SigninRequirement["id"]) => ["me", id] as const, | ||
}; |
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,13 @@ | ||
export interface MyInfoInterface { | ||
id: string; | ||
nickname: string; | ||
profileImages: ProfileImagesType[]; | ||
introduction: string; | ||
followerCount: number; | ||
} | ||
|
||
export interface ProfileImagesType { | ||
attachNo: number; | ||
attachUrl: string; | ||
attachType: string; | ||
} |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.