New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Access token & refresh token setup #12
Comments
@TitusKirch Yes, support for access & refresh tokens are already in the pipeline.
Our implementation doesn't yet address this as, though it's a great feature and one that I'll definitely be adding to this module. Built-in support for different authentication error cases would greatly improve DX and make the module easier to adapt for newer developers. @TitusKirch Thank you for the feedback! |
@Diizzayy Thanks for the quick reply! That sounds fanatastic, I'm curious about the future. Good luck in advance. |
@Diizzayy Speaking about authentication, how do you set custom headers on the server side if you want to authentication to the graphql endpoint? We need this 'how to' example in the docs. Thanks. |
@dodanex Proper documentation is right around the corner.
useGqlToken("my_token") Using the function above, the header
useGqlHeaders({ 'X-Custom-Header': 'Custom Value' })
useGqlHeaders({
'X-Custom-Header': 'Custom Value'
}, 'my-client') calling either |
@Diizzayy great job. Thanks |
@dodanex Looking forward to hearing your feedback while we continue perfecting the module. |
So I cannot start Nuxt because Failed to load schema for "gql-sdk.ts", I suspect it fails because no authentication token header is there. I have added the useGqlHeaders in my app.vue, however that is of course after starting nuxt... Any way I can add the header before trying to load the schema? |
@larswww you can add the key |
Shopify Storefront API requires a custom header name for their auth token. |
@larswww <script lang="ts" setup>
useGqlToken('secret_token', { config: { name: 'X-CUSTOM-HEADER' } })
const { data } = await useAsyncData('starlink', () => GqlLaunches())
</script> In the latest version that I just released ( export default defineNuxtConfig({
modules: ['nuxt-graphql-client'],
publicRuntimeConfig: {
'graphql-client': {
clients: {
default: {
host: 'https://api.github.com/graphql', // process.env.GQL_HOST overrides this value
token: {
name: 'X-CUSTOM-AUTH' // process.env.GQL_TOKEN_NAME overrides this value
}
}
}
}
}
}) if you're using a single client, you can also set GQL_HOST="https://api.github.com/graphql"
GQL_TOKEN="YOUR_GITHUB_TOKEN" |
Any update of this issue ? |
Sounds good. Can't wait for it! |
Hey @Diizzayy, great work on this one! Just having few questions. Where is the token saved? Would usage of useGqlToken with empty string reset it? Where is the token saved? Would usage of useGqlToken with empty string reset it? ( thinking of saving it in a cookie and refreshing it if its lost after a session) Also would love if an enhancement can be added and the capitalized first letter can be optional when making requests |
@gkkirilov I replied from my phone and edited your comment by mistake
@gkkirilov The token is saved in memory, hence you do need to handle the storage and retrieval manually ( currently considering if it's worth integrating the token storage functionality ). As for your question, Yes, passing either |
It's possible to get a retry method inside the error in My use case is :
Thanks in advance |
This functionality has been possible for quite some time now via the
export default defineNuxtPlugin(() => {
useGqlError((err) => {
const tokenExpired = err.gqlErrors.some(err => err?.message.includes('<token_expiration>'))
if (tokenExpired) {
// Handle token expiration
}
})
}) |
As far as I'm aware, useGqlError doesn't retry the request or provide a way to do so in the function itself. A way to implement this could be to return a value in the error hook that tells the client to retry the query. |
@Diizzayy Before I open a new issue on this, is this really possible at the moment and is the documentation simply missing? I have now tried something, but have not come to a solution. How to say at "// Handle token expiration" after the token has been freshed that the query has been executed again? |
Same issue here. is there a way to recall the initial request? |
As far as I can tell, currently it is not. |
Is there an update for this issue? I'm really interested in a way to send a request to "refresh" the token if an error occurs, and then re-invoke the original request that first caused the error. In theory, it should be something like "forward" in apollo , but apollo is buggy and poorly documented crap |
I just found the project here and read #3. Now I have the following question/feature request:
Will the implementation of an access token and a refresh token setup be supported in the future? E.g. if an error message "token expired" comes back, you automatically call a defined query to generate a new access token with its refresh token (HTTP cookie) and then the original query is automatically executed again.
The text was updated successfully, but these errors were encountered: