Auth0 not returning user

I have apollo code that I’ve been using for a few months - suddenly I’m not getting a user returned. I can retrieve my list of accounts, so I know the jwt is working. Did the encapsulation of the user change, or did the request change? I am not seeing it in the response that used to contain it.

if it helps, my apollo server implementation is below. user is always null.

const server = new ApolloServer({
gateway,
subscriptions: false,
context: ({ req }) => {
console.log(req)
const user = req.user || null;
console.log(req.user)
return { user };
}
})

Hi @lastneutrino,

In order to look into this a bit more, would you mind providing a few more details about the implementation?

How is the ApolloClient setting context?

For example from the Apollo/React example tutorial:

...
import auth from './Auth';
...
const client = new ApolloClient({
  uri: "http://localhost:4000/graphql",
  request: operation => {
    operation.setContext(context => ({
      headers: {
        ...context.headers,
        authorization: auth.getIdToken(),
      },
    }));
  },
});
...

Also, what technologies are you using (framework, Auth0 SDK, etc.)

Thanks,

Stephanie

1 Like

This look ok?

const gateway = new ApolloGateway({
serviceList: [
{
name: “accounts”, url: process.env.ACCOUNTS_SERVICE_URL
}
],
buildService({ url }) {
return new RemoteGraphQLDataSource({
url,
willSendRequest({ request, context }) {
console.log(“User” + context.user)
request.http.headers.set(
“user”,
context.user ? JSON.stringify(context.user) : null
);
}
});
}
});

Hm, it looks like the user is being set to the request headers, but the ApolloServer is expecting it as a property of the request. Maybe if the ApolloServer used req.headers.user it would not be null. It is hard to determine without the full context, though.

i agree. i’ll find a better debugger.

1 Like

This topic was automatically closed 15 days after the last reply. New replies are no longer allowed.