diff options
| author | Wes Bos <wesbos@gmail.com> | 2018-05-16 13:53:07 -0400 |
|---|---|---|
| committer | Wes Bos <wesbos@gmail.com> | 2018-05-16 13:53:07 -0400 |
| commit | fceade857ecccad6884fe03a973215bd9df1a1e7 (patch) | |
| tree | 1af26e1116ac4ca54afa35ba932b1d35ec328861 /backend/src | |
| parent | 7ec0943b5d48eb268d03cfa6321c7d83a0d02883 (diff) | |
simplyfyyyy
Diffstat (limited to 'backend/src')
| -rw-r--r-- | backend/src/resolvers/Mutation.js | 32 | ||||
| -rw-r--r-- | backend/src/resolvers/Query.js | 3 | ||||
| -rw-r--r-- | backend/src/schema.graphql | 13 |
3 files changed, 19 insertions, 29 deletions
diff --git a/backend/src/resolvers/Mutation.js b/backend/src/resolvers/Mutation.js index 153833d..9510cd6 100644 --- a/backend/src/resolvers/Mutation.js +++ b/backend/src/resolvers/Mutation.js @@ -21,19 +21,17 @@ const mutations = { }, info ); - const token = jwt.sign({ userId: user.id }, process.env.APP_SECRET); ctx.response.cookie('token', token, { maxAge: 1000 * 60 * 60 * 24 * 365, httpOnly: true, }); - return { user }; + return user; }, async signout(parent, args, ctx, info) { ctx.response.clearCookie('token'); - // TODO: What do we return here? - return { id: 'abc123' }; + return { message: 'goodbye!' }; }, async signin(parent, { email, password }, ctx, info) { @@ -52,10 +50,7 @@ const mutations = { maxAge: 1000 * 60 * 60 * 24 * 365, httpOnly: true, }); - return { - token, - user, - }; + return user; }, // Create An Item @@ -139,11 +134,9 @@ const mutations = { from: 'wesbos@gmail.com', to: user.email, subject: 'Your password reset token', - // TODO: don't hardcore localhost here html: mail.makeANiceEmail( - `Your password reset link is here! \n\n<a href="${ctx.request.protocol}://${ctx.request.get( - 'host' - )}/reset?resetToken=${resetToken}">Click Here to reset</a>s` + `Your password reset link is here! \n\n<a href="${process.env + .FRONTEND_URL}/reset?resetToken=${resetToken}">Click Here to reset</a>` ), }); return res.updateUser; @@ -182,13 +175,14 @@ const mutations = { resetTokenExpiry: null, }, }); + const token = jwt.sign({ userId: updatedUser.id }, process.env.APP_SECRET); + ctx.response.cookie('token', token, { + maxAge: 1000 * 60 * 60 * 24 * 365, + httpOnly: true, + }); - // 6. send back the Auth Payload for the GraphQL request on the client - return { - // TODO: This should use sub instead of userId - token: jwt.sign({ userId: updatedUser.id }, process.env.APP_SECRET), - user: updatedUser, - }; + // 6. send back the User for the GraphQL request on the client + return updatedUser; }, /* Add to cart @@ -265,7 +259,6 @@ const mutations = { const userId = ctx.request.userId; const user = await ctx.db.query.user( { where: { id: userId } }, - // TODO - can we just pass info here? '{ id, name, email, cart { id, quantity, item { title, price, id, description, image } }}' ); // 1. Recalculate the total for the price @@ -303,7 +296,6 @@ const mutations = { total: charge.amount, charge: charge.id, items: { - // TODO this is going to be create instead create: orderItems, }, user: { diff --git a/backend/src/resolvers/Query.js b/backend/src/resolvers/Query.js index b1e0c5b..7e61c07 100644 --- a/backend/src/resolvers/Query.js +++ b/backend/src/resolvers/Query.js @@ -4,13 +4,12 @@ const { forwardTo } = require('prisma-binding'); const Query = { items(parent, args, ctx, info) { + console.log(args); return ctx.db.query.items({ ...args }, info); }, itemsConnection: forwardTo('db'), - // TODO: Make sure they own this order before looking it up - // order: forwardTo('db'), async order(parent, args, ctx, info) { // 1. make sure they are signed in if (!ctx.request.userId) { diff --git a/backend/src/schema.graphql b/backend/src/schema.graphql index 14d4797..bd60b61 100644 --- a/backend/src/schema.graphql +++ b/backend/src/schema.graphql @@ -7,10 +7,10 @@ type Query { } type Mutation { - signup(email: String!, password: String!, name: String!): AuthPayload! - signin(email: String!, password: String!): AuthPayload! + signup(email: String!, password: String!, name: String!): User! + signin(email: String!, password: String!): User! requestReset(email: String!): User - resetPassword(resetToken: String!, password: String!, confirmPassword: String!): AuthPayload! + resetPassword(resetToken: String!, password: String!, confirmPassword: String!): User! createItem(title: String, description: String, price: Int, image: String, largeImage: String): Item! deleteItem(id: ID!): Item! updateItem(id: ID!, title: String, description: String, price: Int): Item! @@ -18,13 +18,12 @@ type Mutation { removeFromCart(id: ID!): CartItem createOrder(token: String!): Order! updateUser(name: String): User - signout: User + signout: SuccessMessage updatePermissions(permissions: [Permission], userId: ID!): User } -type AuthPayload { - token: String! - user: User! +type SuccessMessage { + message: String } type User { |
