Skip to content

Commit

Permalink
change loginWithToken to checkToken
Browse files Browse the repository at this point in the history
  • Loading branch information
META-DREAMER committed Jan 17, 2017
1 parent 1920faf commit d122f51
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 9 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
.idea/

2 changes: 0 additions & 2 deletions meteor-server/src/Mutation/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import loginWithPassword from './loginWithPassword'
import loginWithToken from './loginWithToken'
import logout from './logout'
import changePassword from './changePassword'
import createUser from './createUser'
Expand All @@ -19,7 +18,6 @@ const resolvers = {

if (hasService('password')) {
resolvers.loginWithPassword = loginWithPassword
resolvers.loginWithToken = loginWithToken
resolvers.changePassword = changePassword
resolvers.createUser = createUser
resolvers.forgotPassword = forgotPassword
Expand Down
5 changes: 0 additions & 5 deletions meteor-server/src/Mutation/loginWithToken.js

This file was deleted.

11 changes: 11 additions & 0 deletions meteor-server/src/Queries.js
Original file line number Diff line number Diff line change
@@ -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
}
12 changes: 12 additions & 0 deletions meteor-server/src/Query/checkToken.js
Original file line number Diff line number Diff line change
@@ -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
}
}
9 changes: 9 additions & 0 deletions meteor-server/src/Query/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import checkToken from './checkToken'

const resolvers = {
checkToken
}

export default function (options) {
return { Query: resolvers }
}
6 changes: 4 additions & 2 deletions meteor-server/src/index.js
Original file line number Diff line number Diff line change
@@ -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'
Expand All @@ -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})
}
Expand Down

0 comments on commit d122f51

Please sign in to comment.