From d122f51a591d76e104d21c9966361a3bb90d4c4a Mon Sep 17 00:00:00 2001 From: hammadj Date: Mon, 16 Jan 2017 17:53:28 -0700 Subject: [PATCH] change loginWithToken to checkToken --- .gitignore | 2 ++ meteor-server/src/Mutation/index.js | 2 -- meteor-server/src/Mutation/loginWithToken.js | 5 ----- meteor-server/src/Queries.js | 11 +++++++++++ meteor-server/src/Query/checkToken.js | 12 ++++++++++++ meteor-server/src/Query/index.js | 9 +++++++++ meteor-server/src/index.js | 6 ++++-- 7 files changed, 38 insertions(+), 9 deletions(-) create mode 100644 .gitignore delete mode 100644 meteor-server/src/Mutation/loginWithToken.js create mode 100644 meteor-server/src/Queries.js create mode 100644 meteor-server/src/Query/checkToken.js create mode 100644 meteor-server/src/Query/index.js diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..13bbe5b --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +.idea/ + diff --git a/meteor-server/src/Mutation/index.js b/meteor-server/src/Mutation/index.js index 10ef82e..eb7fde4 100644 --- a/meteor-server/src/Mutation/index.js +++ b/meteor-server/src/Mutation/index.js @@ -1,5 +1,4 @@ import loginWithPassword from './loginWithPassword' -import loginWithToken from './loginWithToken' import logout from './logout' import changePassword from './changePassword' import createUser from './createUser' @@ -19,7 +18,6 @@ const resolvers = { if (hasService('password')) { resolvers.loginWithPassword = loginWithPassword - resolvers.loginWithToken = loginWithToken resolvers.changePassword = changePassword resolvers.createUser = createUser resolvers.forgotPassword = forgotPassword diff --git a/meteor-server/src/Mutation/loginWithToken.js b/meteor-server/src/Mutation/loginWithToken.js deleted file mode 100644 index d9e1858..0000000 --- a/meteor-server/src/Mutation/loginWithToken.js +++ /dev/null @@ -1,5 +0,0 @@ -import callMethod from '../callMethod' - -export default async function (root, {token}, context) { - return callMethod(context, 'login', {resume: token}) -} diff --git a/meteor-server/src/Queries.js b/meteor-server/src/Queries.js new file mode 100644 index 0000000..9d7ccd6 --- /dev/null +++ b/meteor-server/src/Queries.js @@ -0,0 +1,11 @@ +export default function (options) { + const queries = [] + + queries.push(` + type Query { + # Returns true if token is valid + checkToken(token: String!): SuccessResponse + }`) + + return queries +} diff --git a/meteor-server/src/Query/checkToken.js b/meteor-server/src/Query/checkToken.js new file mode 100644 index 0000000..afbdb0a --- /dev/null +++ b/meteor-server/src/Query/checkToken.js @@ -0,0 +1,12 @@ +import {Accounts} from 'meteor/accounts-base' +import {Meteor} from 'meteor/meteor' + +export default async function (root, { token }, {userId}) { + const user = Meteor.users.findOne({ + _id: userId, + 'services.resume.loginTokens.hashedToken' : Accounts._hashLoginToken(token) + }); + return { + success: !!user + } +} diff --git a/meteor-server/src/Query/index.js b/meteor-server/src/Query/index.js new file mode 100644 index 0000000..4a7ee66 --- /dev/null +++ b/meteor-server/src/Query/index.js @@ -0,0 +1,9 @@ +import checkToken from './checkToken' + +const resolvers = { + checkToken +} + +export default function (options) { + return { Query: resolvers } +} diff --git a/meteor-server/src/index.js b/meteor-server/src/index.js index fec435e..31e8160 100644 --- a/meteor-server/src/index.js +++ b/meteor-server/src/index.js @@ -1,7 +1,9 @@ import './checkNpm' import SchemaTypes from './Auth' import SchemaMutations from './Mutations' +import SchemaQueries from './Queries' import Mutation from './Mutation' +import Query from './Query' import LoginMethodResponse from './LoginMethodResponse' import callMethod from './callMethod' import {loadSchema} from 'graphql-loader' @@ -15,8 +17,8 @@ const initAccounts = function (givenOptions) { ...givenOptions } - const typeDefs = [SchemaTypes(options), ...SchemaMutations(options)] - const resolvers = {...Mutation(options), ...LoginMethodResponse(options)} + const typeDefs = [SchemaTypes(options), ...SchemaMutations(options), ...SchemaQueries(options)] + const resolvers = {...Mutation(options), ...LoginMethodResponse(options), ...Query(options)} loadSchema({typeDefs, resolvers}) }