Anyone have experience integrating Nuxt Apollo with Fauna? Cant seem to get the connection. Have no problems accessing data from public test graphql endpoints, but cant seem to get connection to fauna. Documentation on the Nuxt Apollo site is just insufficient for me to figure this out. Any help or just a link to an article is greatly appreciated.
Hi @gametb and welcome!
Make sure that
- You use the right endpoint. See our docs to make sure you pick the right endpoint depending on what Region Group your database is in.
- You send a bearer token with your secret in the request headers.
Fauna uses bearer tokens, so your auth headers should be set to something like:
"Bearer YOUR_SECRET"
In general, a lot can depend on where the GraphQL client is running (server or client) or if you need to handle user Tokens with ABAC Roles with Fauna. You may be able to set a default config to do everything on the server, or you may need to provide a User token on the fly for requests from the browser.
It looks like NuxtApollo has some special auth helpers that you can use. There are also configuration options for what kind of auth token you have and whether your token gets stored in a cookie or local storage.
You can also set headers directly, which is something I am more familiar with in other GraphQL clients.
httpLinkOptions
can be used to configure default headers. I am honestly not sure if Nuxt will try to override that, though.
httpLinkOptions: {
headers:{
'Authorization': 'Bearer MY_SECRET'
}
}
You can also set headers per query setting the context
option
const { result } = useQuery(
query,
variables,
{
context: {
headers: {
'Authorization': 'Bearer MY_USER_TOKEN'
}
}
}
)
This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.