The authService.register method is the frontend service layer that handles user registration. This method calls the backend /api/register endpoint to create new user accounts.
This documentation covers the frontend service layer from the RespondeIA frontend repository. The backend API endpoints are hosted separately.
Source Code
From modules/auth/services/auth.service.ts:
export const authService = {
// ...
register : async ( data : any ) => {
const res = await fetch ( '/api/register' , {
method: 'POST' ,
body: JSON . stringify ( data ),
});
return res . json ();
}
};
Parameters
Registration data object containing user information. The user’s email address.
Returns
Returns a Promise that resolves to the parsed JSON response from the backend API.
Usage Example
From modules/auth/components/RegisterForm.tsx:
const RegisterForm = () => {
const [ formData , setFormData ] = useState ({
firstName: "" ,
lastName: "" ,
email: "" ,
password: ""
});
const handleSubmit = async ( e : React . FormEvent ) => {
e . preventDefault ();
try {
const result = await authService . register ( formData );
console . log ( 'Registration successful' , result );
// Redirect to login or dashboard
} catch ( error ) {
console . error ( 'Registration failed' , error );
}
};
return (
< form onSubmit = { handleSubmit } >
< Input
value = {formData. firstName }
onChange = {(e) => setFormData ({ ... formData , firstName : e . target . value })}
placeholder = "Juan"
/>
< Input
value = {formData. lastName }
onChange = {(e) => setFormData ({ ... formData , lastName : e . target . value })}
placeholder = "Pérez"
/>
< Input
type = "email"
value = {formData. email }
onChange = {(e) => setFormData ({ ... formData , email : e . target . value })}
placeholder = "[email protected] "
/>
< Input
type = "password"
value = {formData. password }
onChange = {(e) => setFormData ({ ... formData , password : e . target . value })}
placeholder = "Mínimo 8 caracteres"
/>
< Button type = "submit" > Registrarse </ Button >
</ form >
);
};
authService.login Authenticate users after registration
RegisterForm Component UI component using the register service
useAuthStore Zustand store for authentication state
Authentication Guide Complete authentication workflow guide