Add missing fullname for signup

Signed-off-by: gearnode <bryan@frimin.fr>
This commit is contained in:
gearnode
2025-02-25 23:24:52 +01:00
parent af23a3e605
commit 3ee3b37dac
3 changed files with 32 additions and 5 deletions

View File

@@ -11,6 +11,7 @@ import { useAuth } from "@/contexts/AuthContext";
export default function RegisterPage() {
const [email, setEmail] = useState("");
const [password, setPassword] = useState("");
const [fullName, setFullName] = useState("");
const [isLoading, setIsLoading] = useState(false);
const { toast } = useToast();
const navigate = useNavigate();
@@ -19,10 +20,10 @@ export default function RegisterPage() {
const handleSubmit = async (e: React.FormEvent) => {
e.preventDefault();
if (!email || !password) {
if (!email || !password || !fullName) {
toast({
title: "Error",
description: "Email and password are required",
description: "Full name, email, and password are required",
variant: "destructive",
});
return;
@@ -37,7 +38,7 @@ export default function RegisterPage() {
"Content-Type": "application/json",
},
credentials: "include",
body: JSON.stringify({ email, password }),
body: JSON.stringify({ email, password, fullName }),
});
if (!response.ok) {
@@ -82,6 +83,18 @@ export default function RegisterPage() {
</div>
<form onSubmit={handleSubmit} className="space-y-4">
<div className="space-y-2">
<Label htmlFor="fullName">Full Name</Label>
<Input
id="fullName"
type="text"
placeholder="John Doe"
value={fullName}
onChange={(e) => setFullName(e.target.value)}
required
/>
</div>
<div className="space-y-2">
<Label htmlFor="email">Email</Label>
<Input

View File

@@ -16,6 +16,7 @@ type (
RegisterRequest struct {
Email string `json:"email"`
Password string `json:"password"`
FullName string `json:"fullName"`
}
// LoginRequest represents the request body for user login
@@ -34,6 +35,7 @@ type (
UserResponse struct {
ID gid.GID `json:"id"`
Email string `json:"email"`
FullName string `json:"fullName"`
CreatedAt time.Time `json:"createdAt"`
UpdatedAt time.Time `json:"updatedAt"`
}
@@ -67,6 +69,7 @@ func RegisterHandler(usrmgrSvc *usrmgr.Service, authCfg AuthConfig) http.Handler
usrmgr.RegisterUserParams{
Email: req.Email,
Password: req.Password,
FullName: req.FullName,
},
)
if err != nil {
@@ -74,6 +77,13 @@ func RegisterHandler(usrmgrSvc *usrmgr.Service, authCfg AuthConfig) http.Handler
return
}
organizationID, _ := gid.ParseGID("AZSfP_xAcAC5IAAAAAAltA")
err = usrmgrSvc.AddUserToOrganization(r.Context(), user.ID, organizationID)
if err != nil {
http.Error(w, fmt.Sprintf("Failed to add user to organization: %v", err), http.StatusInternalServerError)
return
}
// Log the user in
session, err := usrmgrSvc.Login(r.Context(), req.Email, req.Password)
if err != nil {
@@ -89,6 +99,7 @@ func RegisterHandler(usrmgrSvc *usrmgr.Service, authCfg AuthConfig) http.Handler
User: UserResponse{
ID: user.ID,
Email: user.EmailAddress,
FullName: user.FullName,
CreatedAt: user.CreatedAt,
UpdatedAt: user.UpdatedAt,
},
@@ -144,6 +155,7 @@ func LoginHandler(usrmgrSvc *usrmgr.Service, authCfg AuthConfig) http.HandlerFun
User: UserResponse{
ID: user.ID,
Email: user.EmailAddress,
FullName: user.FullName,
CreatedAt: user.CreatedAt,
UpdatedAt: user.UpdatedAt,
},

View File

@@ -35,6 +35,7 @@ type (
RegisterUserParams struct {
Email string
Password string
FullName string
}
ErrInvalidCredentials struct {
@@ -95,8 +96,8 @@ func (s Service) RegisterUser(
ctx context.Context,
params RegisterUserParams,
) (*coredata.User, error) {
if params.Email == "" || params.Password == "" {
return nil, fmt.Errorf("email and password are required")
if params.Email == "" || params.Password == "" || params.FullName == "" {
return nil, fmt.Errorf("email, password, and full name are required")
}
// Use a high iteration count for password hashing
@@ -111,6 +112,7 @@ func (s Service) RegisterUser(
ID: gid.New(),
EmailAddress: params.Email,
HashedPassword: hashedPassword,
FullName: params.FullName,
CreatedAt: now,
UpdatedAt: now,
}