fullstack-apollo-express-mongodb-boilerplate
fullstack-apollo-express-mongodb-boilerplate copied to clipboard
Can not SingUp if previous session is expired
If token is expired, there is no way to SignUp, as it tries to use current token.
See getMe method in index.js
Thanks for reporting! Do you have a suggestion how to fix it? :)
@rwieruch Hi, I am not GraphQL expert, but I do have an idea.
I'd do next check on the backend before getting me object:
let me = {};
if (req.body.operationName !== 'signUp' && req.body.operationName !== 'signIn') {
me = await getMe(req);
}
And those operations should be named on client:
const SIGN_UP = gql`
mutation signUp( ...
What do you think?
I think we can fix this issue like this.
const getMe = async req => {
const token = req.headers['x-token'];
if (token) {
try {
return await jwt.verify(token, process.env.SECRET);
} catch (e) {
// throw new AuthenticationError(
// 'Your session expired. Sign in again.',
// );
}
}
return null;
};