πŸ‘€ Our most exciting product launch yet πŸš€ Join us May 8th for Sanity Connect

Troubleshooting login error when starting a new Sanity project

48 replies
Last updated: Feb 26, 2023
any ideas why a in studio vision would follow the reference correctly while from the webapp, the reference doesn't get followed instead returns null?
Feb 26, 2023, 1:58 AM
Are you on the same dataset in vision and in your webapp?
Feb 26, 2023, 1:59 AM
yes!
Feb 26, 2023, 2:00 AM
Can you show me how you're trying to resolve the reference in your webapp?
Feb 26, 2023, 2:01 AM
you might be omitting
._ref
from the object chain
Feb 26, 2023, 2:01 AM
  *[_type == "home"][0]{
    _id,
    footer,
    name,
    showcaseExhibitions[]->,
    title,
    overview,
    header,
    subheader
  }
Feb 26, 2023, 2:02 AM
when i output the fetch() it just returns an array of null
Feb 26, 2023, 2:02 AM
So no documents are matching to
"home"
?
Feb 26, 2023, 2:03 AM
{
  _id: '2afb8db4-b79e-4056-b779-7b3f4c44fd98',
  footer: null,
  header: 'HEADER',
  name: null,
  overview: 'DESCRIPTION',
  showcaseExhibitions: [ null ],
  subheader: [
    {
      _key: '072703d67f11',
      _type: 'block',
      children: [Array],
      markDefs: [],
      style: 'normal'
    }
  ],
  title: 'Home'
}
Feb 26, 2023, 2:04 AM
if i get rid of the
->
it returns the reference object
Feb 26, 2023, 2:04 AM
try
showcaseExhibitions._ref
Feb 26, 2023, 2:05 AM
no nvm that will jsut be the reference id
Feb 26, 2023, 2:05 AM
I think you're misusing the
->
there. Here's an example of how im using it
Feb 26, 2023, 2:06 AM
if its not pointing to something then it makes sense that you're getting null
Feb 26, 2023, 2:06 AM
but it works vision
Feb 26, 2023, 2:07 AM
and returns a result
Feb 26, 2023, 2:07 AM
vision uses GQL for queries no?
Feb 26, 2023, 2:07 AM
GROQ is different
Feb 26, 2023, 2:07 AM
don't think so..i paste in the same query into vision and it gives me the result i expect
Feb 26, 2023, 2:09 AM
that's odd. there must be some context vision has that the Sanity client doesnt
Feb 26, 2023, 2:10 AM
maybe try specifying the fields you want to pull from
showcaseExhibitions
Feb 26, 2023, 2:10 AM
yeah..i start being super specific and then pulled back
Feb 26, 2023, 2:11 AM
wonder if there's some web setting..or if there's a way to turn on debugging so that i can diagnose what URL it's trying to hit
Feb 26, 2023, 2:12 AM
you can check your network tab in the devtools on the webapp
Feb 26, 2023, 2:12 AM
and see where the request is heading
Feb 26, 2023, 2:12 AM
yeah unfortunately Next.js is doing is server side
Feb 26, 2023, 2:15 AM
i guess try making the request from client side
Feb 26, 2023, 2:17 AM
ugh my head hurts..looks like it is using the right URL. And when i copy and paste the URL it actually is the correct data.
Feb 26, 2023, 2:31 AM
but it seems that after fetching it it is disregarding it? do you know if fetch() is actually looking at any types?
Feb 26, 2023, 2:33 AM
actually the same URL when copy and pasted into the browser returns a result..but from executed from the app it doesn't
Feb 26, 2023, 2:37 AM
one query is 9ms the other one is 14ms
Feb 26, 2023, 2:37 AM
very weird, sounds like a bug
Feb 26, 2023, 2:39 AM
wondering it's something to do with CORS
Feb 26, 2023, 2:42 AM
that would be the only thing that is different
Feb 26, 2023, 2:42 AM
If CORS were an issue would you not be getting an error in your console about it?
Feb 26, 2023, 2:43 AM
yeah that's valid..something is happening on the sanity level it seems
Feb 26, 2023, 2:44 AM
Oof thats annoying
Feb 26, 2023, 2:45 AM
you should open an issue on github
Feb 26, 2023, 2:45 AM
okay...so in incognito mode i am getting the reference not being followed
Feb 26, 2023, 3:01 AM
so b/c i have logged in via studio..it's following them when i hit it directly
Feb 26, 2023, 3:01 AM
so its an auth issue?
Feb 26, 2023, 3:02 AM
so basically it seems like references don't get followed unless you are logged in? or use an auth token
Feb 26, 2023, 3:02 AM
yeah..will force a token in and see
Feb 26, 2023, 3:02 AM
i guess that makes sense
Feb 26, 2023, 3:02 AM
πŸ€¦β€β™‚οΈ yeah..when i force a token in it works..
Feb 26, 2023, 3:04 AM
i think this template i am using doesn't force the token unless in preview mode
Feb 26, 2023, 3:04 AM
well shit good job figuring it out!
Feb 26, 2023, 3:04 AM
ha..thanks for the suggestions and moral support
Feb 26, 2023, 3:09 AM
anytime πŸ™‚
Feb 26, 2023, 3:10 AM

Sanity– build remarkable experiences at scale

Sanity is a modern headless CMS that treats content as data to power your digital business. Free to get started, and pay-as-you-go on all plans.

Was this answer helpful?