react-express-mongo-boilerplate icon indicating copy to clipboard operation
react-express-mongo-boilerplate copied to clipboard

GraphQL error : You must be logged in

Open AymericBethencourt opened this issue 6 years ago • 3 comments

This error is showing when accessing the boilerplate. I understand you must be logged in but it should not show as an error. Being logged out is normal state that should show the login and registration page without an error. https://i.ibb.co/9TDpVPj/Screenshot-2019-08-06-at-10-26-03.png

AymericBethencourt avatar Aug 06 '19 08:08 AymericBethencourt

I am trying to fix this on the new branch "fix/graphql-error-messages". I am still thinking what should be the right approach, prevent graphql errors on console or filter them in some way. Do you suggest any solutions?

IgorMCesar avatar Aug 06 '19 12:08 IgorMCesar

=> Definitely preventing the graphql error in the first place. You should be able to have graphql requests without being authenticated, for example to fetch data to display on the homepage of the app. For example reddit is fetching the latest articles and comments even though you are not logged in. It's only when you want to post something new that you have to log in, which by the way is I think the next step in your boilerplate, to have something like reddit to post articles and comments in order to really make it a useable boilerplate for any real application, even if people remove the articles and comments and replace them with the actual data of the applications. At least they will have an example of how to actually fetch data, with required authentication or not. Btw I find this project very cool, I'm gonna help you develop it, I've already forked it and started working on the integration with redux-thunk as I saw it was on your todo list. I'll soon submit you a pull request :)

AymericBethencourt avatar Aug 06 '19 16:08 AymericBethencourt

I think that's the right approach too. Request data without authentication is already implemented, I used directives for that. You can see this on server/graphql/schemas/user.js, @auth requires the user to be authenticated and @guest requires a not authenticated request, any other request will be accepted and won't throw an error.

I really appreciate the help! I was trying to maintain the project alone, but is very time consuming, your help is more than welcome =)

IgorMCesar avatar Aug 06 '19 17:08 IgorMCesar