Add missing fullname for signup
Signed-off-by: gearnode <bryan@frimin.fr>
This commit is contained in:
@@ -11,6 +11,7 @@ import { useAuth } from "@/contexts/AuthContext";
|
|||||||
export default function RegisterPage() {
|
export default function RegisterPage() {
|
||||||
const [email, setEmail] = useState("");
|
const [email, setEmail] = useState("");
|
||||||
const [password, setPassword] = useState("");
|
const [password, setPassword] = useState("");
|
||||||
|
const [fullName, setFullName] = useState("");
|
||||||
const [isLoading, setIsLoading] = useState(false);
|
const [isLoading, setIsLoading] = useState(false);
|
||||||
const { toast } = useToast();
|
const { toast } = useToast();
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
@@ -19,10 +20,10 @@ export default function RegisterPage() {
|
|||||||
const handleSubmit = async (e: React.FormEvent) => {
|
const handleSubmit = async (e: React.FormEvent) => {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
|
|
||||||
if (!email || !password) {
|
if (!email || !password || !fullName) {
|
||||||
toast({
|
toast({
|
||||||
title: "Error",
|
title: "Error",
|
||||||
description: "Email and password are required",
|
description: "Full name, email, and password are required",
|
||||||
variant: "destructive",
|
variant: "destructive",
|
||||||
});
|
});
|
||||||
return;
|
return;
|
||||||
@@ -37,7 +38,7 @@ export default function RegisterPage() {
|
|||||||
"Content-Type": "application/json",
|
"Content-Type": "application/json",
|
||||||
},
|
},
|
||||||
credentials: "include",
|
credentials: "include",
|
||||||
body: JSON.stringify({ email, password }),
|
body: JSON.stringify({ email, password, fullName }),
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!response.ok) {
|
if (!response.ok) {
|
||||||
@@ -82,6 +83,18 @@ export default function RegisterPage() {
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<form onSubmit={handleSubmit} className="space-y-4">
|
<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">
|
<div className="space-y-2">
|
||||||
<Label htmlFor="email">Email</Label>
|
<Label htmlFor="email">Email</Label>
|
||||||
<Input
|
<Input
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ type (
|
|||||||
RegisterRequest struct {
|
RegisterRequest struct {
|
||||||
Email string `json:"email"`
|
Email string `json:"email"`
|
||||||
Password string `json:"password"`
|
Password string `json:"password"`
|
||||||
|
FullName string `json:"fullName"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// LoginRequest represents the request body for user login
|
// LoginRequest represents the request body for user login
|
||||||
@@ -34,6 +35,7 @@ type (
|
|||||||
UserResponse struct {
|
UserResponse struct {
|
||||||
ID gid.GID `json:"id"`
|
ID gid.GID `json:"id"`
|
||||||
Email string `json:"email"`
|
Email string `json:"email"`
|
||||||
|
FullName string `json:"fullName"`
|
||||||
CreatedAt time.Time `json:"createdAt"`
|
CreatedAt time.Time `json:"createdAt"`
|
||||||
UpdatedAt time.Time `json:"updatedAt"`
|
UpdatedAt time.Time `json:"updatedAt"`
|
||||||
}
|
}
|
||||||
@@ -67,6 +69,7 @@ func RegisterHandler(usrmgrSvc *usrmgr.Service, authCfg AuthConfig) http.Handler
|
|||||||
usrmgr.RegisterUserParams{
|
usrmgr.RegisterUserParams{
|
||||||
Email: req.Email,
|
Email: req.Email,
|
||||||
Password: req.Password,
|
Password: req.Password,
|
||||||
|
FullName: req.FullName,
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -74,6 +77,13 @@ func RegisterHandler(usrmgrSvc *usrmgr.Service, authCfg AuthConfig) http.Handler
|
|||||||
return
|
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
|
// Log the user in
|
||||||
session, err := usrmgrSvc.Login(r.Context(), req.Email, req.Password)
|
session, err := usrmgrSvc.Login(r.Context(), req.Email, req.Password)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -89,6 +99,7 @@ func RegisterHandler(usrmgrSvc *usrmgr.Service, authCfg AuthConfig) http.Handler
|
|||||||
User: UserResponse{
|
User: UserResponse{
|
||||||
ID: user.ID,
|
ID: user.ID,
|
||||||
Email: user.EmailAddress,
|
Email: user.EmailAddress,
|
||||||
|
FullName: user.FullName,
|
||||||
CreatedAt: user.CreatedAt,
|
CreatedAt: user.CreatedAt,
|
||||||
UpdatedAt: user.UpdatedAt,
|
UpdatedAt: user.UpdatedAt,
|
||||||
},
|
},
|
||||||
@@ -144,6 +155,7 @@ func LoginHandler(usrmgrSvc *usrmgr.Service, authCfg AuthConfig) http.HandlerFun
|
|||||||
User: UserResponse{
|
User: UserResponse{
|
||||||
ID: user.ID,
|
ID: user.ID,
|
||||||
Email: user.EmailAddress,
|
Email: user.EmailAddress,
|
||||||
|
FullName: user.FullName,
|
||||||
CreatedAt: user.CreatedAt,
|
CreatedAt: user.CreatedAt,
|
||||||
UpdatedAt: user.UpdatedAt,
|
UpdatedAt: user.UpdatedAt,
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -35,6 +35,7 @@ type (
|
|||||||
RegisterUserParams struct {
|
RegisterUserParams struct {
|
||||||
Email string
|
Email string
|
||||||
Password string
|
Password string
|
||||||
|
FullName string
|
||||||
}
|
}
|
||||||
|
|
||||||
ErrInvalidCredentials struct {
|
ErrInvalidCredentials struct {
|
||||||
@@ -95,8 +96,8 @@ func (s Service) RegisterUser(
|
|||||||
ctx context.Context,
|
ctx context.Context,
|
||||||
params RegisterUserParams,
|
params RegisterUserParams,
|
||||||
) (*coredata.User, error) {
|
) (*coredata.User, error) {
|
||||||
if params.Email == "" || params.Password == "" {
|
if params.Email == "" || params.Password == "" || params.FullName == "" {
|
||||||
return nil, fmt.Errorf("email and password are required")
|
return nil, fmt.Errorf("email, password, and full name are required")
|
||||||
}
|
}
|
||||||
|
|
||||||
// Use a high iteration count for password hashing
|
// Use a high iteration count for password hashing
|
||||||
@@ -111,6 +112,7 @@ func (s Service) RegisterUser(
|
|||||||
ID: gid.New(),
|
ID: gid.New(),
|
||||||
EmailAddress: params.Email,
|
EmailAddress: params.Email,
|
||||||
HashedPassword: hashedPassword,
|
HashedPassword: hashedPassword,
|
||||||
|
FullName: params.FullName,
|
||||||
CreatedAt: now,
|
CreatedAt: now,
|
||||||
UpdatedAt: now,
|
UpdatedAt: now,
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user