Global access token not used on client-side navigation
See original GitHub issueHello!
I’ve been experimenting with nuxt3 and directus using your module to call the graphql endpoint. I have set up the .env like so:
GQL_HOST="http://localhost:8055/graphql"
GQL_TOKEN="MY_TOKEN"
I then created my request files and asyncData fetching like in the docs:
// pages/posts/index.vue
const { data } = await useAsyncData('posts', () => GqlPosts())
This works great!
However, when doing the same thing inside a dynamic route page, it seems like the access token is no longer used. I get an error 400. Adding useGqlToken('MY_TOKEN')
resolves this but I guess it is not intended.
// pages/posts/[slug].vue
useGqlToken('MY_TOKEN')
const { data } = await useAsyncData('post-' + UID, () => GqlUniquePost({
slug: route.params.slug,
}))
Am I doing something wrong? Thanks a lot!
Issue Analytics
- State:
- Created a year ago
- Comments:5 (3 by maintainers)
Top Results From Across the Web
Using OAuth 2.0 for client-side web applications
This document explains how to implement OAuth 2.0 authorization to access the YouTube Data API from a JavaScript web application.
Read more >how to deal with access token and refresh token in client side
I am developing a service layer for both browser-based and non-browser clients. I plan to use JWT (JSON Web Token) to authenticate both....
Read more >The Ultimate Guide to handling JWTs on frontend clients ...
The Ultimate Guide to handling JWTs on frontend clients (GraphQL). JWTs (JSON Web Token, pronounced 'jot') are becoming a popular way of ...
Read more >Add a way to persist oAuth access token · Issue #39 - GitHub
This is because the oAuth2 access token is not currently persisted anywhere, it is just in memory. This document recommends against storing the...
Read more >How to Store Session Tokens in a Browser (and the impacts of ...
The simplest way to achieve this is to just use a top level global variable. This variable will be available to any of...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Not quite, manually adding the token to
runtimeConfig
is equivalent to using an env variable.Using
nuxt generate
would certainly get around this issue, though you’d still need to make client-side authenticated requests during development.I think there is merit in adding the
retainToken
flag as a bypass for the current behavior. If anything, we can always revise this at a later point.Oh I understand, this is sane behaviour. I just realized that it’s the same with non-dynamic routes actually. Is it supposed to be resolved by using the variables inside runtimeConfig? I tried this but nothing changed:
@Diizzayy, I think it would be favorable but I’m not entirely sure as I plan to use
nuxt generate
when fully supported. I would not want you to work on this ifnuxt generate
will not be supported!