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