AuthenticatedItem returns null when I query from the frontend. Works as expected in the graphQL playground

99 Views Asked by At

So, I'm learning web development and this is my first project, I'm trying to break out of tutorial hell.

I'm building a website for my family's small business, and I more or less know what I'm doing. I am using Next.js for the front end and Keystone CMS for the back end. Everything works fine in terms of adding stuff to the database and fetching and displaying the data, but I obviously want to put this behind a login. I'm using the built-in Keystone authentication. The query to get the currently logged-in user works perfectly if I run it in the graphQL playground.

GraphQL playground

However, every time I run it from the front end, it returns an authenticatedItem with a value of null. There are no errors or anything, because it's returning something for the query, just the thing has a value of null for some reason.

authenticatedItem: null

I am definitely signed in, my sign in mutation works and if I console log the return value I get a successful sign in.

sign in mutation working

Github repo here: https://github.com/mzsigler/express-next

Or I can post any code anyone thinks might be related.

I was expecting to be able to sign in with my sign-in mutation then query the active user to either display information or not. Instead it will never return an active user because the return value is always null.

I've literally been stuck on this for a month, so I've tried everything. I originally had it set up importing the query as a hook, but just to rule out an issue with that I just wrote the query directly in the component. I'm using ApolloClient for queries. Everything except this one seems to work.

0

There are 0 best solutions below