Git Product home page Git Product logo

mysql-registration-passport's Introduction

MySQL Registration with JWT & Passport Authentication

About This App

This application is a full-stack MERN app (MySQL, Express, React and Node.js). It is a user registration application that allows a user to register in the database, log in, view their profile, update it and delete it.

It uses a docker-compose file to spin up a local MySQL database, the API module and the client module all with one command: docker-compose up.

Passport local handles user authencation for the unprotected routes, which are the user registration and login routes.

Once the user has logged in a JWT token is created and sent to the client and storeed in local storage along with user data, Passport JWT takes over at this point and handles all further user authentication for protected routes.

Each request from the client to the server must include the JWT as one of its authorization headers before the route can be accessed. If the JWT is missing, corrupted or expired (it has a 1 hour expiration date from the time it's created on login), the authentication will fail and the route cannot be accessed.

If a user logs out or deletes their user profile, the JWT is removed from local storage and the user is dropped back at the home screen again.

There's also a password reset email that can be sent if a user forgets their password. Nodemailer is the package that enables sending, and the email contains a link with a 1 hour expiration date that users can use to reset their password. They can also update their password once logged in to the app as well from a separate update password screen.

I've added Swagger documentation to the API side of the application for easer, in browser API testing. The Swagger UI can be accessed by running the application then going to http://localhost:3003/api-docs/. From there all of the server-side routes can be accessed and tested, just as if you were using the client side interface. Required properties and params are specified and secured routes requiring a JWT token are noted with the little lock at the top right hand corner of the route.

To add a correctly formatted JWT token into the input box, generate the token with the /loginUser route, copy the token property's value, and paste it into the input with JWT <token string>; the "JWT " is required to format the header authorization correctly.

Running This App

From the home folder, run the following commands:

For the very first build:

  • $ docker-compose build

Every time after that:

  • $ docker-compose up

Your API server should be running at http://localhost:3003, your client server will be running at http://localhost:3031 and your MySQL database will be running at: 127.0.0.1:3307

To stop the services:

  • $ docker compose-stop

To kill the services:

  • CTRL + C and then $ docker compose-down

Troubleshooting:

You may have an error when trying to install all the node modules for the first time from the bcrypt package. The error will look something like: npm ERR! path /app/node_modules/bcrypt/node_modules/abbrev when the api app attempts to start up.

If you encounter this, open a new terminal and type docker ps to get the api's container ID.

Access the container: docker exec -t -i <containerId> /bin/bash

Then run npm install bcrypt. It's not a nice way to do it, but it should work. I don't know why Mac bcrypt and Docker Linux bcrypt can't work together nicely sometimes, but they can't.

mysql-registration-passport's People

Contributors

eyalfishler avatar paigen11 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

mysql-registration-passport's Issues

Its not a issue just need more info

I was reading the article https://itnext.io/implementing-json-web-tokens-passport-js-in-a-javascript-application-with-react-b86b1f313436 Very good explain it step by step. I just want to now why req.logIn() is defined on line no 58 of api/routes/registerUser.js ?

Its getting attached with request object but where it is being called ?
Is it something defined and called in one step (foo(){...});
Code inside the logIn() can be wrote without function definition as that part is any how needs to be implemented at that point

Issue with forget password

Hi,
Thank you for the repo.
i have an issue, when i am trying to click forget password button, getting the below error.

image

Can you please help me in solving the issue.
Kindly waiting for your reply.

Thank you,
Jung lee.

How to get started?

Problem 1 - Follow parent directory instruction

  1. Git Clone ...
  2. Pre-installed Docker and running.
  3. docker-compose build
  4. docker-compose up
  5. From the unix-terminal, copy http://localhost:3000/ or http://172.18.0.4:3000/
  6. The page on the browser is spinning continuously.

Problem 2 - Follow Client folder instruction

  1. Go to client folder, do npm install and npm start, as instructed from Unix-Terminal, copy http://localhost:3000/

  2. Go to localhost:3000 and able to see the website.

  3. Register or login,
    Got this error:
    "Unhandled Rejection (TypeError): Cannot read property 'data' of undefined"
    Note: I've got this error even when the Docker is not running but have Express server running.

  4. Docker and Client Server points me to use localhost:3000.

Problem 3:
If I start the client server, do I need to start the API server as well?

Suggestion:
I need a clearer instruction to get started. There are two sets of instructions, one on the parent directory and another one on the client directory. I don't know which one to follow.
Wonderful project!!

Link buttons not working

I can use api from client using routes inside browser '/login' by example but using buttons not working

BUG:

Linkbutton do not work in the correct mannor.
Button text is linked however the button click event does nothing.
Suggested fix: components/LinkButtons.js
<Link style={linkStyle} to={link}> <Button variant="contained" color="primary" style={buttonStyle}> {buttonText} </Button> </Link>

Sorry my laptop is being daft and submitted this before I was ready

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.