Redirect on Logout

Hey! First of all, thanks for the awesome tutorial! I’ve been having a lot of fun going through it.

However, on the “Redirect on Login and Logout” chapter I get this error when trying to redirect after logout -

"Uncaught (in promise) TypeError: Cannot read property 'push' of undefined"

The Login redirect works, which is super weird, because I’m doing the same thing in both places.

This is my handleLogout function:

  async function handleLogout() {
    await Auth.signOut();

and the handleSubmit function in Login.js:

  async function handleSubmit(event) {


    try {
      await Auth.signIn(, fields.password);
    } catch (e) {

I’m importing useHistory in both files and calling the variable with const history = useHistory();

I’ve been staring at this for so long, I don’t know what might be the cause of this.

I’d appreciate any help! Thanks!

1 Like

That’s really odd. The error makes it sound like something is wrong with React Router. Can you compare your code to the one in the repo: