missing fields
This commit is contained in:
1 parent
2d84fae470
commit
78b920aaf6
5 files changed
+61
-7
No files matched your search
@@ -7,6 +7,8 @@ export const useRegisterForm = () => {
|
|||||||
email: "",
|
email: "",
|
||||||
password: "",
|
password: "",
|
||||||
confirm: "",
|
confirm: "",
|
||||||
|
teamId: "",
|
||||||
|
inviteToken: "",
|
||||||
role: ["superadmin"],
|
role: ["superadmin"],
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -5,28 +5,48 @@ import { zodResolver } from "@hookform/resolvers/zod/dist/zod.js";
|
|||||||
import { useRegisterForm } from "@/Hooks/useRegisterForm";
|
import { useRegisterForm } from "@/Hooks/useRegisterForm";
|
||||||
import type { RegisterFormData } from "@/Validation/register";
|
import type { RegisterFormData } from "@/Validation/register";
|
||||||
import { useTranslation } from "react-i18next";
|
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<RegisterFormData, "confirm">;
|
||||||
|
}
|
||||||
|
|
||||||
const RegisterPage = () => {
|
const RegisterPage = () => {
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
const { schema, defaults } = useRegisterForm();
|
const { schema, defaults } = useRegisterForm();
|
||||||
|
const { post, loading } = usePost<RegisterPayload, AuthResponse>();
|
||||||
|
const dispatch = useDispatch();
|
||||||
|
const navigate = useNavigate();
|
||||||
|
|
||||||
const { control, handleSubmit } = useForm<RegisterFormData>({
|
const { control, handleSubmit, setError } = useForm<RegisterFormData>({
|
||||||
resolver: zodResolver(schema),
|
resolver: zodResolver(schema),
|
||||||
defaultValues: defaults,
|
defaultValues: defaults,
|
||||||
});
|
});
|
||||||
|
|
||||||
const onSubmit = (data: RegisterFormData) => {
|
const onSubmit = async (data: RegisterFormData) => {
|
||||||
console.log("Registration data:", data);
|
if (loading) return;
|
||||||
};
|
|
||||||
|
|
||||||
const onError = (errors: any) => {
|
const { confirm, ...userData } = data;
|
||||||
console.log("Validation errors:", errors);
|
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 (
|
return (
|
||||||
<BaseAuthPage
|
<BaseAuthPage
|
||||||
component="form"
|
component="form"
|
||||||
onSubmit={handleSubmit(onSubmit, onError)}
|
onSubmit={handleSubmit(onSubmit)}
|
||||||
title={t("pages.auth.register.title")}
|
title={t("pages.auth.register.title")}
|
||||||
subtitle={t("pages.auth.register.subtitle")}
|
subtitle={t("pages.auth.register.subtitle")}
|
||||||
>
|
>
|
||||||
@@ -100,6 +120,7 @@ const RegisterPage = () => {
|
|||||||
<Button
|
<Button
|
||||||
variant="contained"
|
variant="contained"
|
||||||
type="submit"
|
type="submit"
|
||||||
|
loading={loading}
|
||||||
>
|
>
|
||||||
{t("pages.auth.register.submit")}
|
{t("pages.auth.register.submit")}
|
||||||
</Button>
|
</Button>
|
||||||
|
|||||||
@@ -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;
|
||||||
|
}
|
||||||
@@ -32,6 +32,8 @@ export const registerSchema = z
|
|||||||
(val) => specialCharPattern.test(val),
|
(val) => specialCharPattern.test(val),
|
||||||
"Password must contain a special character"
|
"Password must contain a special character"
|
||||||
),
|
),
|
||||||
|
teamId: z.string().optional(),
|
||||||
|
inviteToken: z.string().optional(),
|
||||||
confirm: z.string().min(1, "Please confirm your password"),
|
confirm: z.string().min(1, "Please confirm your password"),
|
||||||
role: z.array(z.string()).min(1, "Role is required"),
|
role: z.array(z.string()).min(1, "Role is required"),
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -90,6 +90,7 @@ class UserService {
|
|||||||
user.role = invite.role;
|
user.role = invite.role;
|
||||||
user.teamId = invite.teamId;
|
user.teamId = invite.teamId;
|
||||||
} else {
|
} else {
|
||||||
|
console.log("WHITFUSKALG");
|
||||||
// This is the first account, create JWT secret to use if one is not supplied by env
|
// 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");
|
const jwtSecret = this.crypto.randomBytes(64).toString("hex");
|
||||||
await this.settingsRepository.update({ jwtSecret });
|
await this.settingsRepository.update({ jwtSecret });
|
||||||
|
|||||||
Reference in new issue
Block a user