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

Can not SingUp if previous session is expired #9

Open
animir opened this issue Mar 2, 2019 · 3 comments
Open

Can not SingUp if previous session is expired #9

animir opened this issue Mar 2, 2019 · 3 comments

Comments

@animir
Copy link

animir commented Mar 2, 2019

If token is expired, there is no way to SignUp, as it tries to use current token.

See getMe method in index.js

@rwieruch
Copy link
Member

rwieruch commented Mar 3, 2019

Thanks for reporting! Do you have a suggestion how to fix it? :)

@animir
Copy link
Author

animir commented Mar 3, 2019

@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?

@syJSdev
Copy link

syJSdev commented May 15, 2020

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;
};

Why?

* Many projects may have more public API. (as well as `signUp` and `signIn` )

syJSdev added a commit to syJSdev/fullstack-apollo-express-mongodb-boilerplate that referenced this issue May 15, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants