Skip to content

Commit

Permalink
feat: add computed values for token expiration.
Browse files Browse the repository at this point in the history
  • Loading branch information
codiam committed Apr 27, 2023
1 parent 43e896e commit 4195895
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/runtime/composables/useDirectusToken.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,5 +59,16 @@ export const useDirectusToken = () => {
}
}

return { token: token(), refreshToken: refreshToken(), refreshTokens, expires: expires() }
const token_expires_in = computed(() => Math.max(0, (expires().value ?? 0) - new Date().getTime()));

const token_expired = computed(() => !token().value || token_expires_in.value == 0);

return {
token: token(),
refreshToken: refreshToken(),
expires: expires(),
token_expires_in,
token_expired,
refreshTokens
}
}

0 comments on commit 4195895

Please sign in to comment.