This commit is contained in:
117
pages/login.vue
117
pages/login.vue
@@ -1,87 +1,84 @@
|
|||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import AuthProvider from '@/views/pages/authentication/AuthProvider.vue'
|
import AuthProvider from "@/views/pages/authentication/AuthProvider.vue";
|
||||||
import logo from '@images/logo.svg?raw'
|
import logo from "@images/logo.svg?raw";
|
||||||
import authV1BottomShape from '@images/svg/auth-v1-bottom-shape.svg?url'
|
import authV1BottomShape from "@images/svg/auth-v1-bottom-shape.svg?url";
|
||||||
import authV1TopShape from '@images/svg/auth-v1-top-shape.svg?url'
|
import authV1TopShape from "@images/svg/auth-v1-top-shape.svg?url";
|
||||||
|
|
||||||
const form = ref({
|
const form = ref({
|
||||||
user_id: '',
|
user_id: "",
|
||||||
password: '',
|
password: "",
|
||||||
remember: false,
|
remember: false,
|
||||||
})
|
});
|
||||||
|
|
||||||
const isPasswordVisible = ref(false)
|
const isPasswordVisible = ref(false);
|
||||||
const isLoading = ref(false)
|
const isLoading = ref(false);
|
||||||
const errorMessage = ref('')
|
const errorMessage = ref("");
|
||||||
|
|
||||||
const router = useRouter()
|
const router = useRouter();
|
||||||
|
|
||||||
// 컴포넌트 마운트 시 테스트
|
// 컴포넌트 마운트 시 테스트
|
||||||
onMounted(() => {
|
onMounted(() => {});
|
||||||
})
|
|
||||||
|
|
||||||
const handleLogin = async () => {
|
const handleLogin = async () => {
|
||||||
|
|
||||||
if (!form.value.user_id || !form.value.password) {
|
if (!form.value.user_id || !form.value.password) {
|
||||||
errorMessage.value = '아이디와 비밀번호를 입력해주세요.'
|
errorMessage.value = "아이디와 비밀번호를 입력해주세요.";
|
||||||
return
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
isLoading.value = true
|
isLoading.value = true;
|
||||||
errorMessage.value = ''
|
errorMessage.value = "";
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
const response = await $fetch("/api/auth/login", {
|
||||||
const response = await $fetch('/api/auth/login', {
|
method: "POST",
|
||||||
method: 'POST',
|
|
||||||
body: {
|
body: {
|
||||||
user_id: form.value.user_id,
|
user_id: form.value.user_id,
|
||||||
password: form.value.password
|
password: form.value.password,
|
||||||
}
|
},
|
||||||
})
|
});
|
||||||
|
|
||||||
|
|
||||||
if (response.success) {
|
if (response.success) {
|
||||||
|
|
||||||
// 토큰을 쿠키에 저장
|
// 토큰을 쿠키에 저장
|
||||||
const token = useCookie('auth-token', {
|
const token = useCookie("auth-token", {
|
||||||
maxAge: 60 * 60 * 24, // 24시간
|
maxAge: 60 * 60 * 24, // 24시간
|
||||||
secure: true,
|
secure: true,
|
||||||
sameSite: 'strict'
|
sameSite: "strict",
|
||||||
})
|
});
|
||||||
token.value = response.token
|
token.value = response.token;
|
||||||
|
|
||||||
// 사용자 정보를 쿠키에 저장
|
// 사용자 정보를 쿠키에 저장
|
||||||
const user = useCookie('user-info', {
|
const user = useCookie("user-info", {
|
||||||
maxAge: 60 * 60 * 24,
|
maxAge: 60 * 60 * 24,
|
||||||
secure: true,
|
secure: true,
|
||||||
sameSite: 'strict'
|
sameSite: "strict",
|
||||||
})
|
});
|
||||||
user.value = JSON.stringify(response.user)
|
user.value = JSON.stringify(response.user);
|
||||||
|
|
||||||
|
|
||||||
// 대시보드로 리다이렉션
|
// 대시보드로 리다이렉션
|
||||||
await router.push('/dashboard')
|
await router.push("/dashboard");
|
||||||
} else {
|
} else {
|
||||||
errorMessage.value = response.message || '로그인에 실패했습니다.'
|
errorMessage.value = response.message || "로그인에 실패했습니다.";
|
||||||
}
|
}
|
||||||
} catch (error: any) {
|
} catch (error: any) {
|
||||||
console.error('Login error:', error)
|
console.error("Login error:", error);
|
||||||
console.error('Error details:', {
|
console.error("Error details:", {
|
||||||
statusCode: error.statusCode,
|
statusCode: error.statusCode,
|
||||||
statusMessage: error.statusMessage,
|
statusMessage: error.statusMessage,
|
||||||
data: error.data
|
data: error.data,
|
||||||
})
|
});
|
||||||
errorMessage.value = error.data?.statusMessage || error.statusMessage || '로그인 중 오류가 발생했습니다.'
|
errorMessage.value =
|
||||||
|
error.data?.statusMessage ||
|
||||||
|
error.statusMessage ||
|
||||||
|
"로그인 중 오류가 발생했습니다.";
|
||||||
} finally {
|
} finally {
|
||||||
isLoading.value = false
|
isLoading.value = false;
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
|
|
||||||
definePageMeta({
|
definePageMeta({
|
||||||
layout: 'blank',
|
layout: "blank",
|
||||||
middleware: 'guest'
|
middleware: "guest",
|
||||||
})
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
@@ -106,38 +103,28 @@ definePageMeta({
|
|||||||
:class="$vuetify.display.smAndUp ? 'pa-6' : 'pa-0'"
|
:class="$vuetify.display.smAndUp ? 'pa-6' : 'pa-0'"
|
||||||
>
|
>
|
||||||
<VCardItem class="justify-center">
|
<VCardItem class="justify-center">
|
||||||
<NuxtLink
|
<NuxtLink to="/" class="app-logo">
|
||||||
to="/"
|
|
||||||
class="app-logo"
|
|
||||||
>
|
|
||||||
<!-- eslint-disable vue/no-v-html -->
|
<!-- eslint-disable vue/no-v-html -->
|
||||||
<div
|
<!-- <div
|
||||||
class="d-flex"
|
class="d-flex"
|
||||||
v-html="logo"
|
v-html="logo"
|
||||||
/>
|
/>
|
||||||
<h1 class="app-logo-title">
|
<h1 class="app-logo-title">
|
||||||
sneat
|
sneat
|
||||||
</h1>
|
</h1> -->
|
||||||
</NuxtLink>
|
</NuxtLink>
|
||||||
</VCardItem>
|
</VCardItem>
|
||||||
|
|
||||||
<VCardText>
|
<VCardText>
|
||||||
<h4 class="text-h4 mb-1">
|
<h4 class="text-h4 mb-1">음악 관리 시스템👋🏻</h4>
|
||||||
음악 관리 시스템👋🏻
|
<p class="mb-0">계정에 로그인하여 관리 시스템을 시작하세요</p>
|
||||||
</h4>
|
|
||||||
<p class="mb-0">
|
|
||||||
계정에 로그인하여 관리 시스템을 시작하세요
|
|
||||||
</p>
|
|
||||||
</VCardText>
|
</VCardText>
|
||||||
|
|
||||||
<VCardText>
|
<VCardText>
|
||||||
<VForm @submit.prevent="handleLogin">
|
<VForm @submit.prevent="handleLogin">
|
||||||
<VRow>
|
<VRow>
|
||||||
<!-- 오류 메시지 -->
|
<!-- 오류 메시지 -->
|
||||||
<VCol
|
<VCol v-if="errorMessage" cols="12">
|
||||||
v-if="errorMessage"
|
|
||||||
cols="12"
|
|
||||||
>
|
|
||||||
<VAlert
|
<VAlert
|
||||||
type="error"
|
type="error"
|
||||||
variant="tonal"
|
variant="tonal"
|
||||||
@@ -172,7 +159,7 @@ definePageMeta({
|
|||||||
@click:append-inner="isPasswordVisible = !isPasswordVisible"
|
@click:append-inner="isPasswordVisible = !isPasswordVisible"
|
||||||
/>
|
/>
|
||||||
</VCol>
|
</VCol>
|
||||||
|
|
||||||
<VCol cols="12">
|
<VCol cols="12">
|
||||||
<VBtn
|
<VBtn
|
||||||
block
|
block
|
||||||
|
|||||||
Reference in New Issue
Block a user