Skip to content
Permalink
Browse files
Merge pull request #8 from caracold/finalAuth
final auth changes
  • Loading branch information
caracold committed Apr 23, 2020
2 parents 6df6ff6 + 4d6071f commit 4365623
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 6 deletions.
@@ -43,8 +43,7 @@ exports.getAllItems = (req, res, next) => {
//Handle post request to create a new item in the database
exports.newItem = (req, res, next) => {
//The poster's id is obtained from the token and stored in the databse along with the item
const decoded = jwt.decode(req.headers.authorization.split(' ')[1]);
const userId = decoded.username;
const userId = req.userData._id;
const item = new Item({
_id: new mongoose.Types.ObjectId(),
name: req.body.name,
@@ -7,8 +7,7 @@ const mongoose = require('mongoose');
//Handles get request to show all messages in the database targetted at the user
exports.getInbox = (req, res, next) => {
//By obtaning the username from the token, finds the messages within the database that are specifically targetted at the user
const decoded = jwt.decode(req.headers.authorization.split(' ')[1]);
const userId = decoded.username;
const userId = req.userData._id;
Message.find({ destination: userId }).select('-__v').exec()
.then(docs => {
const response = {
@@ -72,8 +71,7 @@ exports.sendMessage = (req, res, next) => {

//Handles get requests where for messages sent by, rather than to, the user
exports.getSent = (req, res, next) => {
const decoded = jwt.decode(req.headers.authorization.split(' ')[1]);
const userId = decoded.username;
const userId = req.userData._id;
Message.find({ sender: userId }).select('-__v').exec()
.then(docs => {
const response = {

0 comments on commit 4365623

Please sign in to comment.