Skip to content

Commit

Permalink
fix: change watch handler on refresh session in N time
Browse files Browse the repository at this point in the history
  • Loading branch information
LorexIQ committed Nov 22, 2023
1 parent dcbb9c3 commit 339d954
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/runtime/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { getContext } from './helpers';
import auth from "./middleware/auth";

export default defineNuxtPlugin(async () => {
const { options, state: { token } } = await getContext();
const { options, state: { token, meta } } = await getContext();
const { getMe } = useLocalAuth();
let pendingInterval: NodeJS.Timeout;

Expand All @@ -13,11 +13,11 @@ export default defineNuxtPlugin(async () => {
} catch (e) {}

if (options.sessions.refreshEvery) {
watch(token, value => {
watch(meta, value => {
clearInterval(pendingInterval);
if (value) {
pendingInterval = setInterval(async () => {
if (token.value) await getMe();
if (meta.value.token) await getMe();
else clearInterval(pendingInterval);
}, options.sessions.refreshEvery);
}
Expand Down

0 comments on commit 339d954

Please sign in to comment.