Closed cpreston321 closed 1 year ago
@Diizzayy Temporary solution:
nuxtApp.hook('gql:auth:init', async ({ token }) => {
const ssrEvent = nuxtApp.ssrContext?.event
if (ssrEvent) {
token.value = ssrEvent.context.auth.token
}
else {
const cookieToken = await $fetch('/api/get-cookie')
token.value = `${cookieToken}`
}
})
@cpreston321 The gql:auth:init
hook is meant to declare custom logic for retrieving and applying an auth token when needed. This module provides a default mechanism for handling cookie auth that meets the needs of most applications.
you get any 404 page then go back the hook doesn't re-inject the token and have to do a manual refresh.
The gql:auth:init
hook is triggered anytime a request made.
It sounds like the issue you encountered here is solely due to your cookie being inaccessible by the browser ( hence why you've created the /api/get-cookie
route I assume )
That is correct, the cookie is a server side cookie with I set within context of the router. I still need a way to grab the token so I created a API endpoint for the client side of the app.
I also don't want to create another token with the same value -- I want to leverage what I already have to save from duplication.
That is correct, the cookie is a server side cookie with I set within context of the router. I still need a way to grab the token so I created a API endpoint for the client side of the app.
@cpreston321 Okay I understand, I'd suggest using a server plugin to check for the cookie's existence and pass along the token to your app. That would negate the need for the additional request to the get-cookie
route.
You'd then be able to access the extracted cookie value within the gql:auth:init
hook, If I understand your use case correctly. I'd also suggest disabling tokenStorage
Feel free to reach out to me on discord, I'd be happy to have a closer look and help you find the best resolution here.
@Diizzayy what is your discord tag?
@cpreston321 you can reach me at Diizzayy#1964
@Diizzayy sent as officialcpzz
Environment
Linux
v16.14.2
3.0.0
1.0.0
npm@7.17.0
vite
modules
,runtimeConfig
nuxt-graphql-client@0.2.20
-
Describe the bug
When you have a plugin defined that injects the
authToken
tonuxt-grapqhl-client
and you get any 404 page then go back the hook doesn't re-inject the token and have to do a manual refresh.Example Hook:
Expected behaviour
When you get an error it should redirect back home and inject the token correctly using the
hook
properly.Reproduction
No response
Additional context
I need to find a graphql endpoint that has auth to setup the reproduction for this as I don't know any of the top of my head.
Logs
No response