Closed richardpatsch closed 5 years ago
It should be fixed now. It was because there was no sample data and I never caught the case when there are no messages available. Can you try again to clone it?
now I'm getting this:
@richardpatsch I met the same problem that 400 Bad Request
from the Graphql server. As the GrapQL error
message said 'Your session expired. Sign in again.', that should happened at the following code snippet in the server/src/index.js
.
if (token) {
try {
return await jwt.verify(token, process.env.SECRET);
} catch (e) {
throw new AuthenticationError(
'Your session expired. Sign in again.',
);
}
}
and the question is how the null
token expected value from token = req.headers['x-token'];
can involve the if statement. I try to console.log(req.headers)
it and see the result is like { ..., 'x-token': 'null', ...}
. You 'token' value is equal to String 'null' not null
.
I change the code in client/src/index.js
and the fixed this issue.
const authLink = new ApolloLink((operation, forward) => {
operation.setContext(({ headers = {} }) => {
const token = localStorage.getItem('token')
return {
headers: {
...headers,
'x-token': token ? token : '',
},
}
});
Hope that can be help.
Oh, might be my bad implementation here. Thanks @Azrealy for figuring it out. Can you open a Pull Request for this project which fixes this? :)
@rwieruch Of course, and also I notice one more issue that happened at the following code snippet.
const errorLink = onError(({ graphQLErrors, networkError }) => {
if (graphQLErrors) {
graphQLErrors.forEach(({ message, locations, path }) => {
console.log('GraphQL error', message);
if (message === 'NOT_AUTHENTICATED') {
signOut(client);
}
});
}
here will cause a problem when the token expired. Because graphql server will throw the 'Your session expired. Sign in again.'
error message, and this won't involve the if (message === 'NOT_AUTHENTICATED')
statement, and I try to fix it through the following modification.
if (message) {
const token = localStorage.getItem('token')
if (token) {
signOut(client);
}
}
BTW, I create a new branch and fixed those issues but don't have permission to push it.
I think you have to go the official way of making a fork of the project and then opening up a Pull Request with it. Thanks for your help on this! 🚀
@Azrealy - Did you make a PR? The authLink creates a syntax error.
hi, after following the instructions in the readme I'm getting this:
The graphQL server is running and I can execute the queries as well, but somehow the client can not reach it. I tried it on 2 PCs already. Any ideas? thx in advance!