Skip to content
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

Method fired at accessToken expired like useGqlTokenExpired or is using useGqlToken in middleware a good solution? #485

Open
toknT opened this issue May 9, 2024 · 0 comments
Labels
enhancement New feature or request

Comments

@toknT
Copy link

toknT commented May 9, 2024

Your use case

I am using accessToken and refreshToken.This package only has useGqlToken so I create a middleware like this

import { AuthService } from "~/services/AuthService";

export default defineNuxtRouteMiddleware(async (to, from) => {
  if (import.meta.server) return;
  try {
    const accessToken = await AuthService.accessToken();
    useGqlToken(accessToken);
  } catch (error) {
    console.error("token error", error);
    return navigateTo("/login");
  }
});

and check if accessToken is expired or refresh a new accessToken with refreshToken in AuthService.accessToken

I am not use if it is a good way.

The solution you'd like

add some method can fired when token (access token) is expired.

Possible alternatives

No response

Additional information

No response

@toknT toknT added the enhancement New feature or request label May 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant