Giter Club home page Giter Club logo

nodejs-mysql-auth's Introduction

nodejs-mysql-auth

Training project for the implementation of an authentication system with NodeJS, MySQL, Express and JSONWebToken.

Installation

Load this SQL script to set up the database:

DROP DATABASE IF EXISTS `nodejs-mysql-auth`;
CREATE DATABASE `nodejs-mysql-auth`;
USE `nodejs-mysql-auth`;

CREATE TABLE users (
  id INT PRIMARY KEY NOT NULL AUTO_INCREMENT UNIQUE,
  username VARCHAR(255) NOT NULL UNIQUE,
  email VARCHAR(255) NOT NULL UNIQUE,
  password VARCHAR(255) NOT NULL,
  registered_at DATETIME NOT NULL,
  reset_password_token VARCHAR(255),
  reset_password_token_expiration_at DATETIME
) ENGINE = InnoDB;

CREATE TABLE profiles (
  id INT PRIMARY KEY NOT NULL AUTO_INCREMENT UNIQUE,
  user_id INT NOT NULL,
  avatar VARCHAR(255),
  first_name VARCHAR(100),
  last_name VARCHAR(100)
) ENGINE = InnoDB;

CREATE TABLE users_roles (
	id INT PRIMARY KEY NOT NULL AUTO_INCREMENT UNIQUE,
    user_id INT NOT NULL,
    role_id INT NOT NULL
) ENGINE = InnoDB;

CREATE TABLE roles (
	id INT PRIMARY KEY NOT NULL AUTO_INCREMENT UNIQUE,
    name VARCHAR(255) NOT NULL UNIQUE
) ENGINE = InnoDB;

ALTER TABLE users_roles
	ADD CONSTRAINT fk_users_roles__user_id
		FOREIGN KEY (user_id)
		REFERENCES users(id),
	ADD CONSTRAINT fk_users_roles__role_id
		FOREIGN KEY (role_id)
		REFERENCES roles(id);
        
ALTER TABLE profiles
	ADD CONSTRAINT fk_profiles_user_id
		FOREIGN KEY (user_id)
        REFERENCES users(id);

INSERT INTO roles(name) VALUES ('administrator');
INSERT INTO roles(name) VALUES ('moderator');
INSERT INTO roles(name) VALUES ('user');
git clone https://github.com/JuAlexandre/nodejs-mysql-auth.git
cd nodejs-mysql-auth
yarn install

Copy and rename the .env.template file to .env and modify the database informations.

If you use this app without frontend client, you must set the CLIENT_PATH in the .env file at null.

Launch the server:

yarn start

Documentation

Comming soon...

nodejs-mysql-auth's People

Contributors

kanmuruuruu avatar

Watchers

James Cloos avatar Julien avatar

nodejs-mysql-auth's Issues

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.