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

168
Views
React Router intercepting API call to Express server

I'm using React Router with Passport.js to set up Facebook login. I've set up the express routes and passport config, but every time I hit the <a href="/api/auth/facebook"> link on my client side, it makes a request to RR because of my express app with this line:

app.get('/*', function(req, res) {
  res.sendFile(path.resolve(__dirname, '../client', 'build', 'index.html'))
});

As I am making a call to the server side route, it returns this error:

Warning: [react-router] Location "/api/auth/facebook" did not match any routes

How can I bypass React Router for this one particular route?

my user_routes.js file looks like:

'user strict';

var bodyparser = require('body-parser');
var User = require('../models/User.js');

module.exports = function loadUserRoutes(router, passport) {
  router.use(bodyparser.json());

  router.get('/auth/facebook', passport.authenticate('facebook', {
    session: false,
    successRedirect: '/chat',
    failureRedirect: '/'
  }));

  router.get('/auth/facebook/callback', passport.authenticate('facebook', {
    session: false,
    successRedirect: '/chat',
    failureRedirect: '/'
  }));

  router.post('/sign_up', passport.authenticate('local-signup', { session: false}), function(req, res) {
    res.json(req.user);
  });

  router.post('/sign_in', passport.authenticate('local-login', { session: false}), function(req, res) {
    res.json(req.user);
  });

  router.get('/signout', function(req, res) {
    req.logout();
    res.end();
  });

  //get auth credentials from server
  router.get('/load_auth_into_state', function(req, res) {
    res.json(req.user);
  });

  // get usernames for validating whether a username is available
  router.get('/all_usernames', function(req, res) {
    User.find({'local.username': { $exists: true } }, {'local.username': 1, _id:0}, function(err, data) {
      if(err) {
        console.log(err);
        return res.status(500).json({msg: 'internal server error'});
      }
      res.json(data);
    });
  })
};
about 4 years ago · Santiago Trujillo
1 answers
Answer question

0

In express routes are matches in the order they get defined.

So before your /* route you need something to handle api requests.

app.get('/api/auth/facebook', passport.authenticate('facebook'))

app.get('/*', function(req, res) {
  res.sendFile(path.resolve(__dirname, '../client', 'build', 'index.html'))
});
about 4 years ago · Santiago Trujillo 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!