-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
136 additions
and
39 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
declare global { | ||
interface Window { | ||
Kakao: any; | ||
kakao: any; | ||
} | ||
} | ||
|
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,27 @@ | ||
@import '@/styles/globals.scss'; | ||
|
||
.kakaoBtn { | ||
width: 90%; | ||
max-width: 350px; | ||
height: 52px; | ||
padding: 16px; | ||
display: flex; | ||
justify-content: center; | ||
align-items: center; | ||
flex-shrink: 0; | ||
border-radius: 12px; | ||
background: #ffe400; | ||
color: #222; | ||
@include BOLD; | ||
line-height: 130%; | ||
letter-spacing: -0.16px; | ||
position: relative; | ||
cursor: pointer; | ||
|
||
.kakaoIcon { | ||
position: absolute; | ||
left: 24px; | ||
display: flex; | ||
align-items: center; | ||
} | ||
} |
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,75 @@ | ||
import { useState } from 'react'; | ||
import { useRouter } from 'next/router'; | ||
import styles from './Login.module.scss'; | ||
import IconComponent from '@/components/Asset/Icon'; | ||
import BASE_URL from '@/constants/baseurl'; | ||
|
||
interface AuthObj { | ||
access_token: string; | ||
expires_in: number; | ||
refresh_token: string; | ||
refresh_token_expires_in: number; | ||
scope: string; | ||
token_type: string; | ||
} | ||
|
||
interface ErrorResponse { | ||
error: string; | ||
error_description: string; | ||
} | ||
|
||
export default function Login() { | ||
const [loading, setLoading] = useState(false); | ||
const APP_KEY = process.env.NEXT_PUBLIC_KAKAO_MAP_APP_KEY; | ||
|
||
const router = useRouter(); | ||
|
||
const handleLogin = async () => { | ||
setLoading(true); | ||
|
||
if (!window.Kakao.isInitialized()) { | ||
window.Kakao.init(APP_KEY); | ||
} | ||
|
||
window.Kakao.Auth.login({ | ||
success: async (authObj: AuthObj) => { | ||
try { | ||
const response = await BASE_URL.post('/auth/login', { | ||
kakaoAccessToken: authObj.access_token, | ||
}); | ||
|
||
localStorage.setItem('access_token', authObj.access_token); | ||
router.push('/map'); | ||
} catch (error) { | ||
console.error('로그인 실패:', error); | ||
} finally { | ||
setLoading(false); | ||
} | ||
}, | ||
fail: (error: ErrorResponse) => { | ||
console.error('로그인 실패:', error); | ||
setLoading(false); | ||
}, | ||
}); | ||
}; | ||
|
||
return ( | ||
<div | ||
className={styles.kakaoBtn} | ||
onClick={handleLogin} | ||
role="button" | ||
tabIndex={0} | ||
aria-disabled={loading} | ||
> | ||
<div className={styles.kakaoIcon}> | ||
<IconComponent | ||
name="landingKakao" | ||
alt="Kakao Icon" | ||
width={24} | ||
height={24} | ||
/> | ||
</div> | ||
{loading ? '로그인 중...' : '카카오로 계속하기'} | ||
</div> | ||
); | ||
} |
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,26 @@ | ||
import axios, { InternalAxiosRequestConfig } from 'axios'; | ||
|
||
const BASE_URL = axios.create({ | ||
baseURL: 'http://ec2-13-124-234-41.ap-northeast-2.compute.amazonaws.com:3000', | ||
}); | ||
|
||
BASE_URL.interceptors.request.use( | ||
async (config: InternalAxiosRequestConfig) => { | ||
const token = localStorage.getItem('access_token'); | ||
if (token) { | ||
config.headers['Authorization'] = `Bearer ${token}`; | ||
} | ||
|
||
if (config.headers['exclude-access-token']) { | ||
delete config.headers['exclude-access-token']; | ||
return config; | ||
} | ||
|
||
return config; | ||
}, | ||
error => { | ||
return Promise.reject(error); | ||
} | ||
); | ||
|
||
export default BASE_URL; |
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