-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Jaya Singh
committed
Nov 12, 2020
1 parent
8752d93
commit 5efb2ad
Showing
6 changed files
with
110 additions
and
13 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
{ | ||
"name": "job-provider-site", | ||
"version": "1.0.0", | ||
"description": "> A job provoding and posting website", | ||
"main": "index.js", | ||
"scripts": { | ||
"test": "echo \"Error: no test specified\" && exit 1" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/dscnitp/job-provider-site.git" | ||
}, | ||
"keywords": [], | ||
"author": "", | ||
"license": "ISC", | ||
"bugs": { | ||
"url": "https://github.com/dscnitp/job-provider-site/issues" | ||
}, | ||
"homepage": "https://github.com/dscnitp/job-provider-site#readme" | ||
} |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,7 @@ const mongoose = require("mongoose"); | |
require("dotenv").config(); | ||
|
||
mongoose | ||
.connect(process.env.MainDB, { | ||
.connect(MainDB = "mongodb+srv://dscnitp_webdept_worklink:[email protected]/worklinkDB?retryWrites=true&w=majority", { | ||
useNewUrlParser: true, | ||
useUnifiedTopology: true, | ||
useCreateIndex: true, | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,39 @@ | ||
const jwt = require('jsonwebtoken') | ||
const Customer = require('../models/Customer') | ||
const Worker = require('../models/signup_workers') | ||
|
||
const auth = async (req,res,next) => { | ||
try { | ||
console.log("enetered try") | ||
const token = req.header('Authorization').replace('Bearer ', '') | ||
const decoded = jwt.verify(token, process.env.JWT_SECRET) | ||
const customer = await Customer.findOne({_id: decoded._id, 'tokens.token': token }) | ||
|
||
const decoded = jwt.verify(token, "thisismynewcourse") | ||
const customer = await Customer.findOne({_id: decoded._id, 'tokens.token': token}) | ||
console.log(token); | ||
if(customer) | ||
{ | ||
req.token = token | ||
req.customer = customer | ||
console.log("customer found") | ||
next() | ||
} | ||
if(!customer) { | ||
throw new error() | ||
console.log("customer not found") | ||
const worker = await Worker.findOne({_id: decoded._id, 'tokens.token':token}); | ||
if(!worker) | ||
{ | ||
throw new Error(); | ||
console.log("worker not found") | ||
} | ||
req.token = token; | ||
req.worker = worker; | ||
next(); | ||
} | ||
|
||
req.token = token | ||
req.customer = customer | ||
next() | ||
} catch (e) { | ||
|
||
} | ||
catch (e) { | ||
res.status(401).send({error: 'Please authenticate'}) | ||
} | ||
} | ||
|
||
module.exports = auth | ||
module.exports = auth |
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
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