139 lines
3.0 KiB
Vue
139 lines
3.0 KiB
Vue
<template>
|
|
<div class="auth-page">
|
|
<div class="auth-container">
|
|
<h1>Register</h1>
|
|
<form @submit.prevent="handleRegister">
|
|
<div class="form-group">
|
|
<label for="nickname">Nickname</label>
|
|
<input type="text" id="nickname" v-model="nickname" required />
|
|
</div>
|
|
<div class="form-group">
|
|
<label for="email">Email</label>
|
|
<input type="email" id="email" v-model="email" required />
|
|
</div>
|
|
<div class="form-group">
|
|
<label for="password">Password (min 8 characters)</label>
|
|
<input type="password" id="password" v-model="password" required />
|
|
</div>
|
|
<div v-if="error" class="error-message">{{ error }}</div>
|
|
<div v-if="successMessage" class="success-message">{{ successMessage }}</div>
|
|
<button type="submit" :disabled="loading">
|
|
{{ loading ? 'Registering...' : 'Register' }}
|
|
</button>
|
|
</form>
|
|
<div class="switch-link">
|
|
<p>
|
|
Already have an account?
|
|
<NuxtLink to="/login">Login here</NuxtLink>
|
|
</p>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</template>
|
|
|
|
<script setup>
|
|
import { ref } from 'vue';
|
|
|
|
const api = useApi();
|
|
const nickname = ref('');
|
|
const email = ref('');
|
|
const password = ref('');
|
|
const error = ref(null);
|
|
const loading = ref(false);
|
|
const successMessage = ref('');
|
|
|
|
const handleRegister = async () => {
|
|
loading.value = true;
|
|
error.value = null;
|
|
successMessage.value = '';
|
|
try {
|
|
await api('/auth/register', {
|
|
method: 'POST',
|
|
body: {
|
|
nickname: nickname.value,
|
|
email: email.value,
|
|
password: password.value,
|
|
},
|
|
});
|
|
successMessage.value = 'Registration successful! Please log in.';
|
|
setTimeout(() => {
|
|
navigateTo('/login');
|
|
}, 2000);
|
|
} catch (err) {
|
|
error.value = err.data?.message || 'An error occurred during registration.';
|
|
} finally {
|
|
loading.value = false;
|
|
}
|
|
};
|
|
|
|
definePageMeta({
|
|
layout: 'login',
|
|
});
|
|
</script>
|
|
|
|
<style scoped>
|
|
.auth-page {
|
|
display: flex;
|
|
justify-content: center;
|
|
align-items: center;
|
|
min-height: 100vh;
|
|
background-color: #f0f2f5;
|
|
}
|
|
.auth-container {
|
|
width: 100%;
|
|
max-width: 400px;
|
|
padding: 40px;
|
|
background: white;
|
|
border-radius: 8px;
|
|
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
|
|
}
|
|
h1 {
|
|
text-align: center;
|
|
margin-bottom: 24px;
|
|
}
|
|
.form-group {
|
|
margin-bottom: 16px;
|
|
}
|
|
label {
|
|
display: block;
|
|
margin-bottom: 8px;
|
|
}
|
|
input {
|
|
width: 100%;
|
|
padding: 10px;
|
|
border: 1px solid #ccc;
|
|
border-radius: 4px;
|
|
}
|
|
button {
|
|
width: 100%;
|
|
padding: 12px;
|
|
border: none;
|
|
border-radius: 4px;
|
|
background-color: #28a745;
|
|
color: white;
|
|
font-size: 16px;
|
|
cursor: pointer;
|
|
transition: background-color 0.3s;
|
|
}
|
|
button:disabled {
|
|
background-color: #ccc;
|
|
cursor: not-allowed;
|
|
}
|
|
button:hover:not(:disabled) {
|
|
background-color: #218838;
|
|
}
|
|
.error-message {
|
|
color: red;
|
|
margin-bottom: 16px;
|
|
text-align: center;
|
|
}
|
|
.success-message {
|
|
color: green;
|
|
margin-bottom: 16px;
|
|
text-align: center;
|
|
}
|
|
.switch-link {
|
|
margin-top: 20px;
|
|
text-align: center;
|
|
}
|
|
</style> |