Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ The app is using `nodemon`. Any changes made (and saved) will cause the server t
Navigate to the `sql/connections.js` file and alter the following fields to reflect your database setup. These will be the same credentials we used to set up a connection in MySQL Workbench.

NOTE: The code-block below is just an example but yours may be the same

```
host: 'localhost',
user: 'root',
Expand Down
4 changes: 2 additions & 2 deletions controllers/auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ const bcrypt = require('bcrypt')
const jwt = require('jsonwebtoken')
const pool = require('../sql/connection')
const { handleSQLError } = require('../sql/error')
require("dotenv").config()

// for bcrypt
const saltRounds = 10
Expand Down Expand Up @@ -39,7 +40,6 @@ const login = (req, res) => {
password: password,
audience: process.env.AUTH0_IDENTITY,
connection: 'Username-Password-Authentication',
scope: 'openid',
client_id: process.env.AUTH0_CLIENT_ID,
client_secret: process.env.AUTH0_CLIENT_SECRET
}
Expand All @@ -52,8 +52,8 @@ const login = (req, res) => {
})
.catch(e => {
res.send(e)
console.log(e)
})

// let sql = "SELECT * FROM usersCredentials WHERE username = ?"
// sql = mysql.format(sql, [ username ])

Expand Down
1 change: 1 addition & 0 deletions controllers/users.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
const mysql = require('mysql')
const pool = require('../sql/connection')
const { handleSQLError } = require('../sql/error')
require('dotenv').config()

const getAllUsers = (req, res) => {
pool.query("SELECT * FROM users", (err, rows) => {
Expand Down
1 change: 1 addition & 0 deletions middleware/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const jwksRsa = require('jwks-rsa');
const jwt = require('express-jwt');
require('dotenv').config()

const logger = () => {}

Expand Down
6 changes: 3 additions & 3 deletions routers/users.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ router.get('/', usersController.getAllUsers)

router.get('/:id', usersController.getUserById)

router.post('/', usersController.createUser)
router.post('/', checkJwt, usersController.createUser)

router.put('/:id', usersController.updateUserById)
router.put('/:id', checkJwt, usersController.updateUserById)

router.delete('/:first_name', usersController.deleteUserByFirstName)
router.delete('/:first_name', checkJwt, usersController.deleteUserByFirstName)

module.exports = router
9 changes: 5 additions & 4 deletions sql/connection.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
const mysql = require('mysql')
require("dotenv").config()

class Connection {
constructor() {
if (!this.pool) {
console.log('creating mysql connection...')
this.pool = mysql.createPool({
connectionLimit: 100,
host: 'localhost',
user: 'root',
password: 'password',
database: 'admin'
host: process.env.DB_HOST,
user: process.env.DB_USER,
password: process.env.DB_PASSWORD,
database: process.env.DB_DATABASE
})

return this.pool
Expand Down