Skip to content

final auth changes #8

Merged
merged 1 commit into from Apr 23, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 1 addition & 2 deletions api/controllers/items.js
Expand Up @@ -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,
Expand Down
6 changes: 2 additions & 4 deletions api/controllers/messages.js
Expand Up @@ -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 = {
Expand Down Expand Up @@ -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 = {
Expand Down