-
Notifications
You must be signed in to change notification settings - Fork 3
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 #73 from INFP-Study/feature/axios-api-template
[FEATURE] E4-S3 ํ์๊ฐ์ Store ์์ฑ #25
- Loading branch information
Showing
6 changed files
with
91 additions
and
1 deletion.
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 |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import { put } from 'redux-saga/effects'; | ||
import * as authStore from '../store/auth'; | ||
import { authAPI } from '../utils/api/auth'; | ||
import axios from 'axios'; | ||
|
||
import { INNER_ERROR } from '../constants'; | ||
import { finishLoading, startLoading } from '../store/loding'; | ||
|
||
function* googleLoginSaga(action) { | ||
try { | ||
yield put(startLoading(authStore.getGoogleLogin)); | ||
const { data } = yield axios.get(authAPI.GOOGLE_LOGIN(params.payload)); | ||
console.log(data); | ||
yield put({ type: authStore.getGoogleLoginSuccess, payload: data }); | ||
} catch (e) { | ||
if (axios.isAxiosError(e)) { | ||
const { errorMessage } = e.response.data; | ||
yield put({ | ||
type: authStore.getGoogleLoginFail, | ||
payload: errorMessage, | ||
}); | ||
} else { | ||
console.log(e); | ||
yield put({ | ||
type: authStore.getGoogleLoginFail, | ||
payload: INNER_ERROR, | ||
}); | ||
} | ||
} finally { | ||
yield put(finishLoading(authStore.getGoogleLogin)); | ||
} | ||
} | ||
export { googleLoginSaga }; |
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,36 @@ | ||
import { takeLatest } from 'redux-saga/effects'; | ||
import { createSlice } from '@reduxjs/toolkit'; | ||
import { googleLoginSaga } from '../saga/auth'; | ||
|
||
const initialState = { | ||
googleSignup: { | ||
error: null, | ||
}, | ||
}; | ||
const authSlice = createSlice({ | ||
name: 'auth', | ||
initialState, | ||
reducers: { | ||
getGoogleLogin: (state) => state, | ||
getGoogleLoginSuccess: (state, action) => { | ||
state.user.userId = action.payload.userId; | ||
localStorage.setItem('user', action.payload.accessToken); | ||
return state; | ||
}, | ||
getGoogleLoginFail: (state, action) => { | ||
state.googleSignup.error = action.payload; | ||
return state; | ||
}, | ||
}, | ||
}); | ||
|
||
const { actions, reducer: authReducer } = authSlice; | ||
|
||
export const { getGoogleLogin, getGoogleLoginSuccess, getGoogleLoginFail } = | ||
actions; | ||
|
||
export { authReducer, initialState }; | ||
|
||
export function* authSaga() { | ||
yield takeLatest(getGoogleLogin.type, googleLoginSaga); | ||
} |
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
Empty file.
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,12 @@ | ||
const isDev = window.location.origin.includes('localhost'); | ||
const SERVER_ORIGIN = isDev | ||
? 'http://localhost:3000' | ||
: 'https://ciat-bakend.choicloudlab.com'; | ||
|
||
export const API_DOMAIN = SERVER_ORIGIN; | ||
export const API_END_POINT = `${SERVER_ORIGIN}/api`; | ||
|
||
export const authAPI = { | ||
GOOGLE_LOGIN: `${API_END_POINT}/test`, | ||
GET_POST: (id) => `${API_END_POINT}/board/${id}`, | ||
}; |