DEV Community

Sumit Chahar
Sumit Chahar

Posted on

Handling Routes for our passport application

In the previous article we registered our application on Github and we've got our config variable. We need to setup our routes for passport authentication with Github.

In our index.js file in the routes folder we will set up the routes to use OAuth.

Now we need to configure our routes for handling the OAuth process

Our index.js file will look like this,

Index.js file

  • '/' the index route to render our index page where we'll have our login button.

  • '/success' to redirect user if auth is successful.

  • '/failure' to redirect user to failure page if auth is unsuccessful or an error occurs.

  • '/auth/github' we'll make a get request to auth/github route and pass the middleware passport.authenticate passing "github" as param to authenticate with Github strategy.

  • '/auth/github/callback' this route will work after the OAuth process is complete and we get either an error which means the failureRedirect option will trigger and we'll be redirect to the /failure route. If auth is successful then we'll be redirected to the success page and the users profile data will be available to us.

  • '/logout' for logging out of current session.

The auth/github route makes use of Github Strategy which is a defined protocol that has to be followed and there are different strategies for different OAuth provider for example, google OAuth strategy will be different in comparision to the Github OAuth Strategy.

We'll set up our OAuth strategy in the next article.

Go to next article 👉

Top comments (0)