Skip to content

Commit

Permalink
fix: tests
Browse files Browse the repository at this point in the history
  • Loading branch information
joshuagraber committed Nov 12, 2024
1 parent aa16c30 commit 4213c4e
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
7 changes: 4 additions & 3 deletions client/src/components/AuthWrapper.vue
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { useUserStore } from '@/stores/user';
const route = useRoute();
const { refreshAccessToken, setRedirectTo, logout, tokens, isAuthenticated } =
useAuthStore();
const { id: userId } = useUserStore();
const user = useUserStore();
// Debounce func for performance
const refreshAuth = debounce(handleAuthRefresh, 350, { leading: true });
Expand All @@ -36,20 +36,21 @@ function handleAuthRefresh() {
const differenceFromAccess = tokens.accessToken.expires - now;
const isExpiredAccess = differenceFromAccess <= 0;
const shouldRefresh = differenceFromAccess <= 60 * 1000 && isAuthenticated();
const shouldLogout = isExpiredAccess;
const shouldLogout = isExpiredAccess && !!user.id;
console.debug({
differenceFromAccess,
isExpiredAccess,
shouldRefresh,
isAuthenticated: isAuthenticated(),
shouldLogout,
});
// User's token is about to expire, so we refresh it.g
if (shouldRefresh) {
return refreshAccessToken();
// User's tokens are all expired, log out.
} else if (shouldLogout && userId) {
} else if (shouldLogout) {
setRedirectTo(route);
return logout();
} else return;
Expand Down
1 change: 1 addition & 0 deletions client/src/components/__tests__/authWrapper.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ describe('AuthWrapper', () => {
it('logs user out when access token is expired on all expected events', async () => {
const auth = useAuthStore();
const user = useUserStore();

auth.$patch({
tokens: {
accessToken: {
Expand Down

0 comments on commit 4213c4e

Please sign in to comment.