Open sgup opened 4 years ago
Did you find out ? How do we check the token on server? Can it use seperated Redis for Token checking
I think i got this:
schema:
` import { gql } from 'apollo-server-express';
export default gql
type Query { users: [User!] user(_id: ID!): User
}
extend type Mutation { updateUser(username: String!): User!
resumeLogin(token:String!,services:VaildSerivesEnumType!): User
}
type Email { address: String verified: Boolean }
type Token { token: String! }
type lastlogin{ date:Date ipAddr:String }
type UserStatus{ lastlogin:lastlogin userAgent:String online:Boolean page:String idle:Boolean }
enum VaildSerivesEnumType{ password google }
type User { id: ID username: String displayName: String password:String roles: [String!] heartbeat:Date hideMe:Boolean status:UserStatus
registered_emails: [Email]
createdAt:Date
emails: [Email]
picture:String
coverImg:String
description:String
brief:String
}
`
resolver: ` import { Resolvers } from 'meteor/nicolaslopezj:apollo-accounts/src/Mutation/hashPassword.js' import { combineResolvers } from 'graphql-resolvers'; import { isAuthenticated } from './authorization';
import { Accounts } from 'meteor/accounts-base';
export default { Query: { users: async(parent, args, { models }) => { return await Meteor.users.find(); }, user: async(parent, { _id }, { models }) => { return await Meteor.users.findById(_id); }, },
Mutation: {
resumeLogin: async(parent, { token, services }, { models }) => {
const hashedToken = Accounts._hashLoginToken(token);
let selector = {};
if ('password' == services) {
selector['services.resume.loginTokens.hashedToken'] = hashedToken
} else if ('google' == services) {
selector['services.google.accessToken'] = hashedToken
} else {
return
}
// console.log('selector', selector)
return await Meteor.users.find(selector).fetch()[0];
},
...Resolvers,
updateUser: combineResolvers(
isAuthenticated,
async(parent, { username }, { models, me }) => {
return await models.User.findByIdAndUpdate(
me.id, { username }, { new: true },
);
},
),
},
}; And then you can resume login on each request that need auth:
mutation{
resumeLogin(token:"TOKEN",services:password){
id
}
}`
enum:
` import { GraphQLEnumType, } from 'graphql';
const VaildSerivesEnumType = new GraphQLEnumType({ name: 'VAILD_SERIVCES', values: { password: { value: 'password', }, google: { value: 'google', }, }, }); `
Hi, I have a react native app where I'd like to just use the login token if a valid one is available. Is this the correct way?