Skip to content

Commit

Permalink
updates
Browse files Browse the repository at this point in the history
  • Loading branch information
jeancarlos-cpu committed Dec 1, 2019
1 parent 94b66e4 commit a3c70ee
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 12 deletions.
12 changes: 6 additions & 6 deletions resolvers/query.resolver.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,21 @@ const Query = {
if (!userId) throw new Error("unable to query");
return prisma.user({ id: userId });
},
users: (parent, args, { prisma }, info) =>
prisma.users({
users: (parent, args, { prisma }, info) =>{
return prisma.users({
where: {
OR: [
{ name_contains: args.query },
{
// email_contains: args.query
id: args.query
}
]
},
first: args.first,
skip: args.skip,
orderBy: args.orderBy
}),
posts: (parent, args, { prisma, req }, info) =>
})},
posts: (parent, args, { prisma, req }, info) =>
prisma.posts({
where: {
AND: [
Expand All @@ -33,7 +33,7 @@ const Query = {
first: args.first,
skip: args.skip,
orderBy: args.orderBy
}),
}),
myPosts: (parent, args, { prisma, req }, info) => {
const userId = getUserId(req);
return prisma.posts({
Expand Down
2 changes: 1 addition & 1 deletion src/utils/generateToken.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const jwt = require("jsonwebtoken");

const generateToken = userId => {
return jwt.sign({ userId }, process.env.JWT_SECRET, { expiresIn: "7 days" });
return jwt.sign({ userId }, process.env.JWT_SECRET, { expiresIn: "500 ms" });
};

module.exports = {
Expand Down
10 changes: 5 additions & 5 deletions src/utils/getUserId.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ const jwt = require("jsonwebtoken");
const secret = process.env.JWT_SECRET;

const getUserId = (req, authRequired = true) => {

const token = req.req
const token = req.req.headers.authorization
? req.req.headers.authorization
: req.connection.context.Authorization;

if (token) {
console.log(token);

if (token !== "null") {
const decoded = jwt.verify(token, secret);
return decoded.userId;
}
Expand All @@ -16,7 +16,7 @@ const getUserId = (req, authRequired = true) => {
throw new Error("Authentication required");
}

return undefined;
return null;
};

module.exports = {
Expand Down

0 comments on commit a3c70ee

Please sign in to comment.