React Intermediate: Handling Sign In Callback - [008]

In this episode we show you how to handle the sign in callback.

We'll start off by importing the withRoute higher order component from the react-router5 library.

// ...import { Link, withRoute } from 'react-router5'

We will also need to wrap our component with the withRoute HOC

// all the way at the bottomexport default withRoute(SignIn)

Let's implement the callback function.

// ...class Auth extends React.Component {  // ...  submitForm = (e) => {    e.preventDefault()    // router is exposed to us via the withRoute HOC    const { auth, router } = this.props    // replace null with an anonymous function    auth.createSession(, this.password.value, () => {      router.navigate('posts')    })  }  // ...}

You'll see that we have a router exposed to us we can then call on the router to navigate us to a different page inside of the callback function.