Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

151
Views
How do I get my app to redirect a user to a page after they have registered?

Perhaps I am placing the second router.replace('/contact'); line in the wrong position? Though that doesn't make sense given the redirect works well when a user logs in. Any assistance is greatly appreciated.

    if (isLogin) {
  const result = await signIn('credentials', {
    redirect: false,
    email: enteredEmail,
    password: enteredPassword,
  });

  if (!result.error) {
    // set some auth state
    router.replace('/contact');
  }
} else {
  try {
    const result = await createUser(enteredEmail, enteredPassword);
    console.log("hi");
    console.log(result);
    router.replace('/contact');
  } catch (error) {
    console.log(error);
  }
}

}

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

This is how I do it in React:

import { useHistory } from "react-router-dom";

const Example = () => {
    let history = useHistory();

    //inside function:
   try {
     const result = await createUser(enteredEmail, enteredPassword);
     history.push('/'); //route you want here, 
   } 
   ...
}
about 4 years ago · Juan Pablo Isaza Report

0

I don't know much about Next. In case of using only React, assuming there is a Button to check the credentials, I would use Link of 'react-router-dom' to wrap the Button like this:

<Link to={`/${redirect}`}>
    <Button onClick={handleSubmit(email, password)}>
        Submit
    </Button>
</Link>

Declare state of redirect:

const [redirect, setRedirect] = React.useState('contact');

Declare function handleSubmit:

const handleSubmit = (enteredEmail, enteredPassword) => {
    const result = await signIn('credentials', {
        redirect: false,
        email: enteredEmail,
        password: enteredPassword,
    });
    if (!result.error) {
        setRedirect('contact');
    }
    else setRedirect('user');
}
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!