Skip to content

Commit

Permalink
feat: 카카오 연령대 추가동의 기능 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
choisohyun committed Jul 30, 2022
1 parent 67e6bd5 commit 64060e9
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 9 deletions.
2 changes: 1 addition & 1 deletion .env.development
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
VITE_KAKAO_JAVASCRIPT_KEY=02e0caae3e4116da61d734a06528cd86
VITE_KAKAO_RESTAPI_KEY=09bebf5106adf50d6a204a7ac2c22779
VITE_KAKAO_OPEN_URL=https://kauth.kakao.com/oauth/authorize?client_id={clientId}&redirect_uri={redirectUri}&response_type=code&prompt=login
VITE_KAKAO_OPEN_URL=https://kauth.kakao.com/oauth/authorize?client_id={clientId}&redirect_uri={redirectUri}&response_type=code
VITE_SERVER_URL=https://lonessum.com/api
2 changes: 1 addition & 1 deletion .env.production
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
VITE_KAKAO_JAVASCRIPT_KEY=02e0caae3e4116da61d734a06528cd86
VITE_KAKAO_RESTAPI_KEY=09bebf5106adf50d6a204a7ac2c22779
VITE_KAKAO_OPEN_URL=https://kauth.kakao.com/oauth/authorize?client_id={clientId}&redirect_uri={redirectUri}&response_type=code&prompt=login
VITE_KAKAO_OPEN_URL=https://kauth.kakao.com/oauth/authorize?client_id={clientId}&redirect_uri={redirectUri}&response_type=code
VITE_SERVER_URL=https://lonessum.com/api
6 changes: 2 additions & 4 deletions src/components/domain/landing/LandingContainer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,14 @@ import { palette } from '@/lib/styles/palette';
import styled from 'styled-components';
import { useNavigate } from 'react-router-dom';
import { useLoginState } from '@/atoms/userState';
import { goKakaoLogin } from '@/utils/goKakaoLogin';

function LandingContainer() {
const navigate = useNavigate();
const { isLogin } = useLoginState();

const handleKakaoLoginClick = () => {
const clientId = import.meta.env.VITE_KAKAO_JAVASCRIPT_KEY;
const redirectUri = encodeURI(`${window.location.origin}/oauth/kakao`);
const loginUrl = import.meta.env.VITE_KAKAO_OPEN_URL.replace('{clientId}', clientId).replace('{redirectUri}', redirectUri);
window.location.href = loginUrl;
goKakaoLogin('LOGIN');
};

return (
Expand Down
6 changes: 6 additions & 0 deletions src/lib/api/oauth.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import apiClient from '@/lib/api/index';

export const getOauthKakaoAge = async (params: { code: string }) => {
const res = await apiClient.get(`/oauth/kakao/age&code=${params.code}`);
return res.data;
};
23 changes: 20 additions & 3 deletions src/pages/AgreementSurvey.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,29 +3,46 @@ import { SurveyTemplate } from '@/components/domain/survey';
import useAgreementCheck from '@/hooks/agreement/useAgreementCheck';
import { palette } from '@/lib/styles/palette';
import { Title } from '@/lib/styles/styledComponents';
import React from 'react';
import React, { useEffect } from 'react';
import styled from 'styled-components';
import { FormWrapper } from './AuthMail';
import Path from '@/router/Path';
import { useMatch } from 'react-router-dom';
import { useLocation, useMatch } from 'react-router-dom';
import { useDatingNavigate, useMeetingNavigate } from '@/hooks/common/useNavigate';
import { useMeetingSessionState, useDatingSessionState } from '@/hooks/common';
import { goKakaoLogin } from '@/utils/goKakaoLogin';
import { getOauthKakaoAge } from '@/lib/api/oauth';

const AgreementSurvey = () => {
const location = useLocation();
const matchMeeting = useMatch('/meeting/*');
const meetingNavigate = matchMeeting ? useMeetingNavigate() : useDatingNavigate();
const { initMeetingState, setMeetingData } = useMeetingSessionState();
const { initDatingState, setDatingData } = useDatingSessionState();
const { checkedList, checkedChoiceList, onChangeCheck, onChangeChoiceCheck, onCheckAll, isEssentialChecked, isAllchecked } = useAgreementCheck();

useEffect(() => {
const searchParams = new URLSearchParams(location.search);
const code = searchParams.get('code') ?? '';

getOauthKakaoAge({ code })
.then((response) => {
console.log(response);
meetingNavigate(Path.KakaoIdSurvey);
})
.catch((e) => {
console.error(e);
});
}, [location]);

const handleNextClick = () => {
if (initMeetingState) {
matchMeeting
? setMeetingData({ ...initMeetingState, agreement: isAllchecked })
: setDatingData({ ...initDatingState, agreement: isAllchecked });
}

meetingNavigate(Path.KakaoIdSurvey);
goKakaoLogin('ADDITIONAL');
};

return (
Expand Down
8 changes: 8 additions & 0 deletions src/utils/goKakaoLogin.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
export const goKakaoLogin = (type: 'LOGIN' | 'ADDITIONAL') => {
const clientId = import.meta.env.VITE_KAKAO_JAVASCRIPT_KEY;
const path = type === 'LOGIN' ? '/oauth/kakao' : '/dating/agreement';
const query = type === 'LOGIN' ? '&prompt=login' : '&scope=age_range';
const redirectUri = encodeURI(`${window.location.origin}${path}`);

window.location.href = import.meta.env.VITE_KAKAO_OPEN_URL.replace('{clientId}', clientId).replace('{redirectUri}', redirectUri) + query;
};

0 comments on commit 64060e9

Please sign in to comment.