diff options
| author | Wes Bos <wesbos@gmail.com> | 2018-02-08 10:41:16 -0500 |
|---|---|---|
| committer | Wes Bos <wesbos@gmail.com> | 2018-02-08 10:41:16 -0500 |
| commit | 19c9683e2126c68cb9d231293162c756d69c51fb (patch) | |
| tree | 4679ca2dee47740aa0bf6fe623513c4242e027e6 /backend/src/resolvers | |
| parent | eabff7cd396d1f37ceb929e666f082ce57f07919 (diff) | |
WIP
Diffstat (limited to 'backend/src/resolvers')
| -rw-r--r-- | backend/src/resolvers/Mutation.js | 31 | ||||
| -rw-r--r-- | backend/src/resolvers/Query.js | 7 |
2 files changed, 32 insertions, 6 deletions
diff --git a/backend/src/resolvers/Mutation.js b/backend/src/resolvers/Mutation.js index fbae6fe..95be561 100644 --- a/backend/src/resolvers/Mutation.js +++ b/backend/src/resolvers/Mutation.js @@ -2,6 +2,8 @@ const bcrypt = require('bcryptjs'); const jwt = require('jsonwebtoken'); const { forwardTo } = require('prisma-binding'); const { getUserId, Context } = require('../utils'); +const { randomBytes } = require('crypto'); +const { promisify } = require('util'); const mutations = { // Signup Mutations @@ -17,7 +19,7 @@ const mutations = { }; }, - async login(parent, { email, password }, ctx, info) { + async signin(parent, { email, password }, ctx, info) { const user = await ctx.db.query.user({ where: { email } }); if (!user) { throw new Error(`No such user found for email: ${email}`); @@ -40,8 +42,7 @@ const mutations = { }, async deleteItem(parent, args, ctx, info) { - console.log('gonna delete one'); - console.log(args); + // TODO - handle auth for deleting an item return ctx.db.mutation.deleteItem( { where: { @@ -53,7 +54,6 @@ const mutations = { }, async updateItem(parent, args, ctx, info) { - console.log('Updating an item'); const updates = { ...args }; delete updates.id; return ctx.db.mutation.updateItem({ @@ -123,9 +123,30 @@ const mutations = { text: args.text, }, }); - console.log(updatedPost); return updatedPost; }, + + // Send password request + async requestReset(parent, args, ctx, info) { + // 1. find if there is a user with that email + const user = await ctx.db.query.user({ where: { email: args.email } }); + + if (!user) { + throw new Error(`No user with the email ${args.email}`); + } + console.log(user); + // 2. Set a reset token, and a reset date + // const resetToken = await promisify(randomBytes)(20); + // const resetTokenExpiry = Date.now() + 3600000; // 1 hour from now + // console.log({ resetToken, resetTokenExpiry }); + // const res = await ctx.db.mutation.updateUser({ + // where: { email: args.email }, + // data: { resetToken, resetTokenExpiry }, + // }); + + // console.log(res); + // 3. Send them their token via email + }, }; module.exports = mutations; diff --git a/backend/src/resolvers/Query.js b/backend/src/resolvers/Query.js index a2eb749..e6ea299 100644 --- a/backend/src/resolvers/Query.js +++ b/backend/src/resolvers/Query.js @@ -1,4 +1,4 @@ -const { getUserId, Context } = require('../utils'); +const { getUserId, Context, checkForUserId } = require('../utils'); const { forwardTo } = require('prisma-binding'); const Query = { @@ -31,6 +31,11 @@ const Query = { }, me(parent, args, ctx, info) { + const Authorization = ctx.request.get('Authorization'); + if (!Authorization || Authorization === 'null') { + console.log('Authorization is null'); + return null; + } const id = getUserId(ctx); return ctx.db.query.user({ where: { id } }, info); }, |
