You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi!
Im quite new to Vue and Nuxt. So far I like the framework until...I got stuck with user authentication. ^^
I made different JWT authentications with React and Next.js in the past and never had bigger problems. Now that I'm using Nuxt with the auth-module I'm kind of frustrated and dont know what to do anymore. The documentation (especially about custom schemes) seems to be incomplete. At least I just couldnt find how to properly refresh tokens.
But Im still optmtistic, that's why I made this post.
For the backend Im using the following:
Wordpress
WP GraphQL Plugin
WPGraphQL JWT Authentication Plugin
Due to GraphQL the frontend cannot use Axios but Apollo instead to make GraphQL Queries/Mutations (right?). After some research I found out how to create a custom scheme and was able to make a login which is redirecting to '/dashboard'. That's cool and I thought my Job was done here. But it wasn't. 5 Minutes (or 300 seconds) after logging in, the token was probably expired and I was redirected back to the login page. For any reason this.check().valid was still true and Idk why.
Anyway this must be the point where I need to refresh the token but I just dont get it working. So Im hoping anyone can help me here. To be honest I dont even know where to trigger the refresh function exactly. In my code I try to refresh the token when user details cannot be loaded which leads to a GraphQL internal server error and I think it's not even the correct way to trigger the token refresh. 🙈 Please forgive me my messy code. I'm still learning.
Thanks in advance if there is anybody out there who can help 💐
Wow, thanks for asking this question and providing code for refresh token strategy. Exactly what I needed. When it comes to refreshing tokens, it's pretty easy with Axios and how this modules handles it - intercept every request and check if token is valid, if it is, do nothing, if it's not, refresh it and only then continue with the request. This can't be achieved with apollo as far as I know. You have to let every query/mutation pass and only when it fails due to the token being expired you can refresh it and try again. This can be achieved with forward(operation) in apollo global error handler. If backend returns Network Error 401 instead of GraphQLError, forward(operation) is not possible, so in that case you can at least log user out.
Hi!
Im quite new to Vue and Nuxt. So far I like the framework until...I got stuck with user authentication. ^^
I made different JWT authentications with React and Next.js in the past and never had bigger problems. Now that I'm using Nuxt with the auth-module I'm kind of frustrated and dont know what to do anymore. The documentation (especially about custom schemes) seems to be incomplete. At least I just couldnt find how to properly refresh tokens.
But Im still optmtistic, that's why I made this post.
For the backend Im using the following:
Due to GraphQL the frontend cannot use Axios but Apollo instead to make GraphQL Queries/Mutations (right?). After some research I found out how to create a custom scheme and was able to make a login which is redirecting to '/dashboard'. That's cool and I thought my Job was done here. But it wasn't. 5 Minutes (or 300 seconds) after logging in, the token was probably expired and I was redirected back to the login page. For any reason
this.check().valid
was stilltrue
and Idk why.Anyway this must be the point where I need to refresh the token but I just dont get it working. So Im hoping anyone can help me here. To be honest I dont even know where to trigger the refresh function exactly. In my code I try to refresh the token when user details cannot be loaded which leads to a
GraphQL internal server error
and I think it's not even the correct way to trigger the token refresh. 🙈 Please forgive me my messy code. I'm still learning.Thanks in advance if there is anybody out there who can help 💐
This is the code used for the authentication:
nuxt.config.js
graphqlScheme.js
The text was updated successfully, but these errors were encountered: