Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add method to check the status of the token #34

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions meteor-server/src/Mutations.js
Original file line number Diff line number Diff line change
@@ -8,6 +8,9 @@ export default function (options) {
type Mutation {
# Log the user in with a password.
loginWithPassword (username: String, email: String, password: HashedPassword, plainPassword: String): LoginMethodResponse

# Log the user in with a token
loginWithToken (token: String!): LoginMethodResponse
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We still need to delete this mutation


# Create a new user.
createUser (username: String, email: String, password: HashedPassword, plainPassword: String, profile: CreateUserProfileInput): LoginMethodResponse
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({
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's faster to do find().count()? I don't know

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Both might be appropriate (IMO),
also find().limit(1)

Copy link
Owner

@nicolaslopezj nicolaslopezj Jan 17, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But count() would only bring a Int from the db and find() would return the whole document

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So in this case it'll be faster, you're right.

_id: userId,
'services.resume.loginTokens.hashedToken' : Accounts._hashLoginToken(token)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't forget to check the date

});
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'
@@ -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})
}