Skip to content
This repository has been archived by the owner on Nov 18, 2024. It is now read-only.

Commit

Permalink
reroute when signup
Browse files Browse the repository at this point in the history
  • Loading branch information
khylpe committed May 13, 2024
1 parent 3b51436 commit c97ce3c
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions frontend/src/components/signUpForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,12 @@ import {
firstNameRegex,
lastNameRegex,
} from '@/utils/regex';
import { useRouter } from 'next/navigation';

export default function SignUpForm() {
const { setUser } = useUser();
const [isSignUpLoading, setSignUpLoading] = useState(false);
const router = useRouter();

type SignUpForm = {
email: string;
Expand All @@ -35,7 +37,7 @@ export default function SignUpForm() {
pattern: new RegExp(lastNameRegex),
message: "Le nom de famille n'est pas valide",
};

async function handleSignUpForm(form: SignUpForm): Promise<User | null> {
setSignUpLoading(true);
try {
Expand All @@ -46,12 +48,19 @@ export default function SignUpForm() {
data: form,
withCredentials: true,
responseType: 'json',
timeout: 10000, // * Increased value because we had some timeout errors
});

const userData: User = response.data.user;
setUser(userData);
message.success('Inscription réussie. Bienvenue ! 🎉');

if (userData && response.status === 200) {
setUser(userData);
message.success('Inscription réussie. Bienvenue ! 🎉');
if (userData.role === 'Utilisateur') {
router.push('/profil'); // * Redirect to the home page
} else {
router.push('/dashboard'); // * Redirect to the home page
}
}
return userData; // * Not sure if this is necessary. Information is already stored in the userProvider
} catch (error) {
const axiosError = error as AxiosError;
Expand Down

0 comments on commit c97ce3c

Please sign in to comment.