Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
added authentication to routes
  • Loading branch information
JamesMessina committed May 11, 2021
commit 6617b200ff80c53d759af0612ccf7ca35b79946c
8 changes: 8 additions & 0 deletions .env
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
DB_HOST=den1.mysql1.gear.host
DB_USER=jmdb11
DB_PASSWORD=Pi45wfTS4U!?
DB_DEFAULT_SCHEMA=jmdb11
AUTH0_IDENTITY=my-music-app
AUTH0_DOMAIN=dev-pjh-gm5k.us.auth0.com
AUTH0_CLIENT_ID=0Vh9mEnb44NI04f4FAUkT6ibufANmGgB
AUTH0_CLIENT_SECRET=AZJo66To9LrDRs75inPLX96x0_7QiuuV8gSyq5_YEdVc-0wOVdFssPNOzP5_SuoF
21 changes: 19 additions & 2 deletions controllers/customers.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
const pool = require('../sql/connection.js');
const mysql = require('mysql');
const mysql = require('mysql');


function getDefaultRoute(req, res){
console.log('in the default route')
res.send('default route');
}

function getCustomers(req, res){
console.log('inside the customers route/path');
Expand Down Expand Up @@ -100,4 +106,15 @@ function getCustomerContactInfoByCustomerId(req, res){
})
}

module.exports = { getCustomers, getCustomersByStoreId, getCustomerContactInfoByCustomerId, getAllCustomerContactInfo }
function createCustomer(req, res){
res.send('in the create customer route');
console.log('success')
}

module.exports = { getCustomers,
getCustomersByStoreId,
getCustomerContactInfoByCustomerId,
getAllCustomerContactInfo,
getDefaultRoute,
createCustomer
}
15 changes: 15 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<h1>HELLO</h1>
<button type="submit" id="submitButton" onclick="test()">submit</button>
<div id="outputTest"></div>
<script src="./index.js"></script>
</body>
</html>
22 changes: 18 additions & 4 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,31 @@
//** requirements */
const express = require('express') //import express
require('dotenv').config();
const express = require('express'); //import express
const app = express() // initialize express into app variable
const bodyParser = require("body-parser"); //import body parserconst port = process.env.PORT || 3306; // streaming port
const bodyParser = require("body-parser"); //import body parser // streaming port
const superHeroesRouter = require('./routes/superHeroes.js');
const usersRouter = require('./routes/users.js');
const customersRouter = require('./routes/customers.js');


//** middleware */
//** middleware */;
app.use(bodyParser.json());
app.use(superHeroesRouter);
app.use(usersRouter);
app.use(customersRouter);


app.get('/logtest', function(req, res){
res.send('success in log test funtion ')
})

function test(){
document.getElementById('submitButton').addEventListener('click', function(){
window.alert('success');
console.log('worked')
document.getElementById('outputTest').innerHTML = 'hello'
})
}




Expand All @@ -22,3 +35,4 @@ app.listen(port, () => {
console.log('app is listening on port:', port);
})


22 changes: 22 additions & 0 deletions middleware/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
const jwksRsa = require('jwks-rsa');
const jwt = require('express-jwt');
require('dotenv').config();

function logger(req, res, next){
console.log('logged');
next();
}

const checkJwt = jwt({
secret: jwksRsa.expressJwtSecret({
cache: true,
rateLimit: true,
jwksRequestsPerMinute: 5,
jwksUri: `https://${process.env.AUTH0_DOMAIN}/.well-known/jwks.json`
}),
audience: process.env.AUTH0_IDENTITY,
issuer: `https://${process.env.AUTH0_DOMAIN}/`,
algorithms: ['RS256']
});

module.exports = {checkJwt, logger};
Loading