Skip to content

Commit

Permalink
🎉 oauth login 설정
Browse files Browse the repository at this point in the history
  • Loading branch information
oaoong committed Nov 1, 2023
1 parent 614b690 commit a46a159
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 14 deletions.
3 changes: 2 additions & 1 deletion src/config/apiEndPoint.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const ApiEndPoint = {
login: () => '/login',
kakaoLogin: () => '/oauth2/authorize/kakao/login',
googleLogin: () => '/oauth2/authorize/google/login',
test: () => '/test',
} as const

Expand Down
48 changes: 48 additions & 0 deletions src/lib/msw/mocks/authHandlers.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import { rest } from 'msw'
import ApiEndPoint from '@/config/apiEndPoint'
import { Environment } from '@/config/environment'

const baseUrl = Environment.apiAddress()

const authHandlers = [
rest.get(`${baseUrl}${ApiEndPoint.kakaoLogin()}`, async (_req, res, ctx) => {
return res(
ctx.status(200),
ctx.text('성공했습니다.'),
ctx.json({
data: {
userInfo: {
userId: 1,
nickname: '병원에 간 미어캣',
imageUrl: 'http://asdf~',
},
token: {
accessToken: 'asdfasdf',
refreshToken: 'asdfa',
},
},
}),
)
}),
rest.get(`${baseUrl}${ApiEndPoint.googleLogin()}`, async (_req, res, ctx) => {
return res(
ctx.status(200),
ctx.text('성공했습니다.'),
ctx.json({
data: {
userInfo: {
userId: 1,
nickname: '병원에 간 미어캣',
imageUrl: 'http://asdf~',
},
token: {
accessToken: 'asdfasdf',
refreshToken: 'asdfa',
},
},
}),
)
}),
]

export default authHandlers
3 changes: 2 additions & 1 deletion src/lib/msw/mocks/handlers.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import authHandlers from './authHandlers'
import { testHandlers } from './testHandler'

export const handlers = [...testHandlers]
export const handlers = [...testHandlers, ...authHandlers]
25 changes: 13 additions & 12 deletions src/services/auth/auth.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
import ApiEndPoint from '@/config/apiEndPoint'
import { Environment } from '@/config/environment'

const postLogin = async () => {
const response = await fetch(Environment.apiAddress() + ApiEndPoint.login(), {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
})
const data = await response.json()
return data
import apiClient from '../apiClient'

const getKakaoLogin = async () => {
const response = await apiClient.get(ApiEndPoint.kakaoLogin())

return response
}

const getGoogleLogin = async () => {
const response = await apiClient.get(ApiEndPoint.googleLogin())

return response
}

export { postLogin }
export { getKakaoLogin, getGoogleLogin }

0 comments on commit a46a159

Please sign in to comment.