From 78b920aaf6149ef48c3bc534235878067bdba8c3 Mon Sep 17 00:00:00 2001 From: Alex Holliday Date: Fri, 6 Feb 2026 23:07:17 +0000 Subject: [PATCH] missing fields --- client/src/Hooks/useRegisterForm.ts | 2 ++ client/src/Pages/Auth/Register/index.tsx | 35 +++++++++++++++++----- client/src/Types/User.ts | 28 +++++++++++++++++ client/src/Validation/register.ts | 2 ++ server/src/service/business/userService.ts | 1 + 5 files changed, 61 insertions(+), 7 deletions(-) create mode 100644 client/src/Types/User.ts diff --git a/client/src/Hooks/useRegisterForm.ts b/client/src/Hooks/useRegisterForm.ts index a043d8ff6..3b5189995 100644 --- a/client/src/Hooks/useRegisterForm.ts +++ b/client/src/Hooks/useRegisterForm.ts @@ -7,6 +7,8 @@ export const useRegisterForm = () => { email: "", password: "", confirm: "", + teamId: "", + inviteToken: "", role: ["superadmin"], }; diff --git a/client/src/Pages/Auth/Register/index.tsx b/client/src/Pages/Auth/Register/index.tsx index e2e4fe802..99ef19951 100644 --- a/client/src/Pages/Auth/Register/index.tsx +++ b/client/src/Pages/Auth/Register/index.tsx @@ -5,28 +5,48 @@ import { zodResolver } from "@hookform/resolvers/zod/dist/zod.js"; import { useRegisterForm } from "@/Hooks/useRegisterForm"; import type { RegisterFormData } from "@/Validation/register"; import { useTranslation } from "react-i18next"; +import { usePost } from "@/Hooks/UseApi"; +import { setAuthState } from "@/Features/Auth/authSlice"; +import { useDispatch } from "react-redux"; +import { useNavigate } from "react-router-dom"; +import type { AuthResponse } from "@/Types/User"; + +interface RegisterPayload { + user: Omit; +} const RegisterPage = () => { const { t } = useTranslation(); const { schema, defaults } = useRegisterForm(); + const { post, loading } = usePost(); + const dispatch = useDispatch(); + const navigate = useNavigate(); - const { control, handleSubmit } = useForm({ + const { control, handleSubmit, setError } = useForm({ resolver: zodResolver(schema), defaultValues: defaults, }); - const onSubmit = (data: RegisterFormData) => { - console.log("Registration data:", data); - }; + const onSubmit = async (data: RegisterFormData) => { + if (loading) return; - const onError = (errors: any) => { - console.log("Validation errors:", errors); + const { confirm, ...userData } = data; + const result = await post("/auth/register", { user: userData }); + + if (result?.success) { + dispatch(setAuthState(result)); + navigate("/uptime"); + } else if (result?.msg) { + if (result.msg.toLowerCase().includes("email")) { + setError("email", { message: result.msg }); + } + } }; return ( @@ -100,6 +120,7 @@ const RegisterPage = () => { diff --git a/client/src/Types/User.ts b/client/src/Types/User.ts new file mode 100644 index 000000000..e09e87678 --- /dev/null +++ b/client/src/Types/User.ts @@ -0,0 +1,28 @@ +export const UserRoles = ["user", "admin", "superadmin", "demo"] as const; +export type UserRole = (typeof UserRoles)[number]; + +export interface UserProfileImage { + data?: Buffer; + contentType?: string; +} + +export interface User { + id: string; + firstName: string; + lastName: string; + email: string; + avatarImage?: string; + profileImage?: UserProfileImage; + isActive: boolean; + isVerified: boolean; + role: UserRole[]; + teamId: string; + checkTTL?: number; + createdAt: string; + updatedAt: string; +} + +export interface AuthResponse { + user: User; + token: string; +} diff --git a/client/src/Validation/register.ts b/client/src/Validation/register.ts index b32a8a2fc..67b425ecd 100644 --- a/client/src/Validation/register.ts +++ b/client/src/Validation/register.ts @@ -32,6 +32,8 @@ export const registerSchema = z (val) => specialCharPattern.test(val), "Password must contain a special character" ), + teamId: z.string().optional(), + inviteToken: z.string().optional(), confirm: z.string().min(1, "Please confirm your password"), role: z.array(z.string()).min(1, "Role is required"), }) diff --git a/server/src/service/business/userService.ts b/server/src/service/business/userService.ts index a0273af99..315c62bb0 100644 --- a/server/src/service/business/userService.ts +++ b/server/src/service/business/userService.ts @@ -90,6 +90,7 @@ class UserService { user.role = invite.role; user.teamId = invite.teamId; } else { + console.log("WHITFUSKALG"); // This is the first account, create JWT secret to use if one is not supplied by env const jwtSecret = this.crypto.randomBytes(64).toString("hex"); await this.settingsRepository.update({ jwtSecret });