test branch to demonstrate wrong session.
Note we're running in production mode (one server), there is no dev mode.
Make sure you have mongo running locally.
- clone repo and switch to local-prod-test branch
git clone https://github.com/nikrb/cra-passport-twitter.git
cd cra-passport-twitter
git checkout local-prod-test
- run mongo locally
- copy .env.sample to .env (optionally provide your own mongo/twitter app credentials)
cp .env.sample .env
- install client packages
cd client
yarn
ornpm install
- install server packages (if install fails on node pre gyp, workaround is to install node-gyp first)
cd ..
yarn
ornpm install
- build client
cd client
yarn build
ornpm build
- run server
cd ..
node server
- browse to localhost:5000
- click twitter login
- authorize app
- click authed? button
- console displays user not authenticated
This repo is a work in progress. Uses base template and adds in twitter auth using passport.
To get the anchor tag href link through to the back end specify the full url and add the rel external attribute:
<a rel="external" href="http://localhost:5000/auth/login/twitter" >Login in with Twitter</a>
This works great with the development version, but not with the production version. The difference is the dev version uses react-scripts to run webpack-dev-server on port 3000 and the backend server runs on 5000. The production version just uses one port (on 5000) and the rel external attribute doesn't seem to work as the react-router-dom.BrowserRouter redirects us to the homepage using the cache app (from service worker)
So far I can only get production to work by removing the service worker/registration.
TODO:
- get it to work with the service worker of course
- add the passport-local functionality back in
- integrate the twitter login to work along side local login
create a base for react authentication
- node.js
- react.js
- react-router-dom (react-router v4)
- mongodb & mongoose
- passport.js (passport-local)
This project was bootstrapped with Create React App.
Following vlad's authentication blog
Heroku deployment taken from mars demo with an updated version to show mongodb and websocket connection here
unixy:
sudo apt-get install mongodb-org
- clone repo
- create .env file, e.g.
dbUri=mongodb://localhost:27017/testdb
jwtSecret=somesecretphrase
- npm install (top level and client dirs)
- startup mongo
- npm run start-dev
Create a new mongodb on mLab.
After creating the heroku app (heroku create
) setup the environment using
the heroku dashboard.
git clone https://github.com/nikrb/auth-react-base.git
cd auth-react-base/
heroku create
git push heroku master