구글, 카카오 로그인 추가 #33

Merged
klaus merged 2 commits from test into main 2026-01-29 08:08:49 +00:00
7 changed files with 155 additions and 41 deletions
Showing only changes of commit 6bbee48d4d - Show all commits

View File

@@ -1,3 +1,4 @@
VUE_APP_API_URL=https://test-api.sodalive.net
NODE_ENV=development
VUE_APP_GOOGLE_CLIENT_ID=758414412471-mosodbj2chno7l1j0iihldh6edmk0gk9.apps.googleusercontent.com
VUE_APP_KAKAO_JS_KEY=2be3c619ed36fd3e138bf45812c57d7f

View File

@@ -1,3 +1,4 @@
VUE_APP_API_URL=https://api.sodalive.net
NODE_ENV=production
VUE_APP_GOOGLE_CLIENT_ID=983594297130-5hrmkh6vpskeq6v34350kmilf74574h2.apps.googleusercontent.com
VUE_APP_KAKAO_JS_KEY=378e800dd9029907c559390e786157ef

View File

@@ -9,6 +9,7 @@
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Roboto:100,300,400,500,700,900">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@mdi/font@latest/css/materialdesignicons.min.css">
<script src="https://accounts.google.com/gsi/client" async defer></script>
<script src="https://developers.kakao.com/sdk/js/kakao.min.js"></script>
</head>
<body>
<noscript>

View File

@@ -20,4 +20,16 @@ async function loginGoogle(idToken) {
);
}
export { login, logout, loginGoogle }
async function loginKakao(accessToken) {
return Vue.axios.post(
"/member/login/kakao",
{ container: "api" },
{
headers: {
Authorization: `Bearer ${accessToken}`,
},
}
);
}
export { login, logout, loginGoogle, loginKakao }

BIN
src/assets/kakao_login.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.9 KiB

View File

@@ -112,6 +112,31 @@ const accountStore = {
});
},
async LOGIN_KAKAO({commit}, {accessToken}) {
let result = false
let errorMessage = null
try {
let res = await memberApi.loginKakao(accessToken)
if (res.data.success === true) {
commit("LOGIN", res.data.data)
result = true
} else {
errorMessage = res.data.message
}
} catch (e) {
errorMessage = '카카오 로그인 정보를 확인해주세요.'
}
return new Promise((resolve, reject) => {
if (result) {
resolve();
} else {
reject(errorMessage)
}
});
},
async LOGOUT({commit}) {
let result = false
let errorMessage = null

View File

@@ -1,9 +1,16 @@
<template>
<v-app>
<v-main>
<v-container
align-center
justify-center
<v-container fluid>
<v-row
align="start"
justify="center"
style="padding-top: 10vh;"
>
<v-col
cols="12"
sm="8"
md="4"
>
<v-card class="elevation-12">
<v-card-text>
@@ -34,18 +41,39 @@
</v-card-actions>
<v-divider />
<v-card-text class="text-center">
<div
style="display: flex; flex-direction: column; align-items: center; gap: 10px;"
>
<div
id="google-login-btn"
style="display: flex; justify-content: center;"
style="width: 192px; height: 45px; display: flex; align-items: center; justify-content: center;"
/>
<v-btn
width="192"
height="45"
class="pa-0"
elevation="0"
color="transparent"
@click="loginKakao"
>
<img
src="@/assets/kakao_login.png"
alt="카카오 로그인 버튼"
style="width: 100%; height: 100%; display: block;"
>
</v-btn>
</div>
</v-card-text>
</v-card>
</v-col>
</v-row>
</v-container>
</v-main>
</v-app>
</template>
<script>
/* global Kakao */
export default {
name: "Login",
@@ -57,9 +85,55 @@ export default {
mounted() {
this.initGoogleLogin();
this.initKakaoLogin();
},
methods: {
initKakaoLogin() {
if (typeof Kakao !== 'undefined') {
if (!Kakao.isInitialized()) {
Kakao.init(process.env.VUE_APP_KAKAO_JS_KEY);
}
} else {
setTimeout(() => {
this.initKakaoLogin();
}, 500);
}
},
loginKakao() {
if (typeof Kakao !== 'undefined') {
if (!Kakao.isInitialized()) {
this.initKakaoLogin();
this.notifyError('카카오 SDK가 초기화되지 않았습니다. 잠시 후 다시 시도해주세요.');
return;
}
if (Kakao.Auth && typeof Kakao.Auth.login === 'function') {
Kakao.Auth.login({
success: (authObj) => {
this.$store.dispatch('accountStore/LOGIN_KAKAO', { accessToken: authObj.access_token })
.then(() => {
this.$router.push(this.$route.query.redirect || '/')
})
.catch((message) => {
this.notifyError(message);
})
},
fail: (err) => {
this.notifyError('카카오 로그인에 실패했습니다.');
console.error(err);
},
});
} else {
this.notifyError('카카오 인증 모듈을 불러오지 못했습니다. 페이지를 새로고침 해주세요.');
}
} else {
this.initKakaoLogin();
this.notifyError('카카오 SDK를 불러오는 중입니다. 잠시 후 다시 시도해주세요.');
}
},
initGoogleLogin() {
/* global google */
if (typeof google !== 'undefined') {
@@ -69,7 +143,7 @@ export default {
});
google.accounts.id.renderButton(
document.getElementById("google-login-btn"),
{ theme: "outline", size: "large" }
{ theme: "outline", size: "large", width: 192 }
);
} else {
setTimeout(() => {