Route resolver returns 401

I am trying to use the new routes resolver by adding this in my nuxt.config.js:

prismic: {
  endpoint: process.env.PRISMIC_URL,
  apiOptions: {
    accessToken: process.env.PRISMIC_API_KEY,
    routes: [
      {
        type: 'page',
        path: '/:lang/:uid'
      }
    ]
  },
  disableGenerator: false
}

It doesn't seem to work well though since I keep getting error 401 (Unexpected status code [401] on URL ... and Failed to init Prismic API, preventing app fatal error.).

How do I fix this?

Hi Julian,

Since this is a 401 and is related to authorisation, I'm guessing it's because the access token field isn't defined liked it is here:

It should be

access_token

not

accessToken

Though I could be wrong. So please try this out.

Thanks.

That was my thought as well, but I'm still getting 401

Also is this a Slicemachine project? Because you will need to have Slicemachine activated on your repo to have access to the route resolver.

Yes and it is activated on the repo

The error says Invalid access token, but it works when I remove the routes array.

What happens if you make your repo access public?

Edit: It works again if I remove the routes array and change it back to accessToken without the _.

I get 400/404 when making it public, but that could just be me not setting it up properly. No 401 though.

I'm not sure in that case. Are you using Graphquery anywhere in this project?

Did you define the page document like so? ~/pages/_lang/_uid.vue like we do in the multi-language example:

You don't really need the route resolver for the above URL structure anyway. You could just use the link resolver like we do in that project.

Yep, im using a copy of that project.

I do need the route resolver though, since I need to make deeper nested routes eventually.

My best guess is that the routes array doesn't seem happy about having siblings in the apiOptions. Which basically means you can't have a private repo if you want to use the slice machine.

I do not use Graphquery anywhere.

OK, So it seems your thought about not being able to have these 2 apiOptions at the same time is correct. I talked with the team and it's an issue in that we don't pass the parameters correctly in the prismic-javacript library so it causes this error.

I've talked with the team and apparently they have been working on a fix for this already. We are going to discuss this further tomorrow as to how we can get the fix out there.

It won't be available right away, so for now you won't be able to have a private repo with the routes features. If/when I have any update on this I'll let you know here.

1 Like

The fix for this is being reviewed and tested. Once it's shipped we'll update you here.

Hey @juliandreas,

The fix was published for this a long time ago apparently, are your dependencies up to date?

My bad on the communication.

This fix is here:

Maybe the nuxt kit isn't using this version. I'm confirming with the team.

The nuxt kit should be using the apparently, trying update you nuxt/prismic module.