Skip to content

Commit

Permalink
feature-059: 소셜 로그인 후 처리
Browse files Browse the repository at this point in the history
  • Loading branch information
whistleJs committed Feb 12, 2024
1 parent 5d6d044 commit fe5e7a4
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
5 changes: 4 additions & 1 deletion src/apis/social-account.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import { APIResponse } from '@/models/config/axios';
import { LoginResponse } from '@/models/user';

import axios from './config/instance';

export const kakaoLoginAPI = (code: string) => {
return axios.get(`/kakao-login?code=${code}`);
return axios.get<APIResponse<LoginResponse>>(`/kakao-login?code=${code}`);
};
9 changes: 8 additions & 1 deletion src/pages/SocialAccountPage.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,22 @@
import { useEffect } from 'react';
import { useLocation, useNavigate } from 'react-router-dom';
import { useSetRecoilState } from 'recoil';

import { kakaoLoginAPI } from '@/apis/social-account';

import { userTokenState } from '@/stores/user';

const SocialAccountPage = () => {
const navigate = useNavigate();
const { search } = useLocation();
const setUserToken = useSetRecoilState(userTokenState);

const callAPI = async (code: string) => {
try {
console.log(await kakaoLoginAPI(code));
const { token } = (await kakaoLoginAPI(code)).data.result;

setUserToken(token);
navigate('/');
} catch (e) {
console.error(e);
navigate('/sign-in');
Expand Down

0 comments on commit fe5e7a4

Please sign in to comment.