This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const express = require("express"); | |
const bodyParser = require("body-parser"); | |
const cors = require("cors"); | |
const app = express(); | |
// CORS multiple Domain | |
var allowlist = [ | |
'http://localhost:3000', | |
'http://localhost:4200', |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const { authJwt } = require("../middleware"); | |
const controller = require("../controllers/user.controller"); | |
module.exports = function(app) { | |
app.use(function(req, res, next) { | |
res.header( | |
"Access-Control-Allow-Headers", | |
"x-access-token, Origin, Content-Type, Accept" | |
); | |
next(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const { verifyRegister } = require("../middleware"); | |
const controller = require("../controllers/auth.controller"); | |
module.exports = function(app) { | |
app.use(function(req, res, next) { | |
res.header( | |
"Access-Control-Allow-Headers", | |
"x-access-token, Origin, Content-Type, Accept" | |
); | |
next(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const authJwt = require("./authJwt"); | |
const verifyRegister = require("./verifyRegister"); | |
module.exports = { | |
authJwt, | |
verifyRegister | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const jwt = require("jsonwebtoken"); | |
const config = require("../config/auth.config.js"); | |
const db = require("../models"); | |
const User = db.user; | |
verifyToken = (req, res, next) => { | |
let token = req.headers["x-access-token"]; | |
if (!token) { | |
return res.status(403).send({ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const db = require("../models"); | |
const User = db.user; | |
checkDuplicateUsernameOrEmail = (req, res, next) => { | |
// Username | |
User.findOne({ | |
where: { | |
username: req.body.username | |
} | |
}).then(user => { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
exports.allAccess = (req, res) => { | |
res.status(200).send("Authentication with JSON Web Token (JWT)"); | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const db = require("../models"); | |
const config = require("../config/auth.config"); | |
const User = db.user; | |
var jwt = require("jsonwebtoken"); | |
var bcrypt = require("bcryptjs"); | |
exports.register = (req, res) => { | |
// Save User to Database | |
User.create({ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const config = require("../config/db.config.js"); | |
const Sequelize = require("sequelize"); | |
const sequelize = new Sequelize( | |
config.DB, | |
config.USER, | |
config.PASSWORD, | |
{ | |
host: config.HOST, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module.exports = (sequelize, Sequelize) => { | |
const User = sequelize.define("users", { | |
username: { | |
type: Sequelize.STRING | |
}, | |
email: { | |
type: Sequelize.STRING | |
}, | |
password: { | |
type: Sequelize.STRING |
NewerOlder