feat(auth): implement registration page and logic

This commit is contained in:
2025-06-17 08:46:35 +03:00
parent df460f57ab
commit c4a1c2cde0
6 changed files with 200 additions and 5 deletions

39
src/stores/auth.ts Normal file
View File

@@ -0,0 +1,39 @@
import { defineStore } from "pinia";
import { ref } from "vue";
import { registerUser as apiRegisterUser } from "@/api/auth";
import type { RegisterRequest } from "@/types";
import router from "@/router";
export const useAuthStore = defineStore("auth", () => {
// State
const isLoading = ref(false);
const error = ref<string | null>(null);
// Actions
async function handleRegister(userData: RegisterRequest) {
isLoading.value = true;
error.value = null;
try {
await apiRegisterUser(userData);
// После успешной регистрации перенаправляем на страницу входа
await router.push({ name: "login" });
// Можно добавить сообщение об успехе ("тост")
// alert('Регистрация прошла успешно! Теперь вы можете войти.');
} catch (e: any) {
// Обрабатываем ошибки от Axios
if (e.response && e.response.data) {
error.value = e.response.data;
} else {
error.value = "Произошла неизвестная ошибка";
}
} finally {
isLoading.value = false;
}
}
return {
isLoading,
error,
handleRegister,
};
});