0

We are using Create React App for building our web application. We would like to integrate our Create React App with Passport.js. I am having a hard time integrating these two considering my app uses classes and passport.js does not follow the same as described below.

https://github.com/chrisprice/adfs-example-integration/blob/master/index.js

Can someone suggest me how to integrate these?

user25010
  • 25
  • 1
  • 7

1 Answers1

0

It has nothing to do with classes, but rather ES6 modules, vs NodeJS Common Modules. Luckily, Create React App will use babel underneath to transpile ES6 import statements.

Essentially turn your var foo = require('bar') statements into import foo from 'bar';

SO:

var app = require('express')(),
  cookieParser = require('cookie-parser'),
  jwt = require('jsonwebtoken'),
  passport = require('passport'),
  OAuth2Strategy = require('passport-oauth').OAuth2Strategy,
  fs = require('fs');

Should be

import express from 'express';
import cookieParser from 'cookie-parser';
import jwt from 'jsonwebtoken';
import passport from 'passport';
import { OAuth2Strategy } from 'passport-oauth';
import fs from 'fs';

const app = express();

This assumes you have those npm modules already installed.

IIRC, Create React App ONLY creates a the front-end application. PassportJS is designed to be used in a middle-tier/backend, like an express app. You'll need to create an express app, and mount the passportjs middleware inside the express app.

Alan
  • 45,915
  • 17
  • 113
  • 134