Skip to content

Commit

Permalink
fix token refresh on window focus, deactivate webkit playwright tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Onatcer committed Jun 24, 2024
1 parent 237b383 commit a10d056
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 17 deletions.
8 changes: 4 additions & 4 deletions playwright.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,10 @@ export default defineConfig({
use: { ...devices['Desktop Firefox'] },
},

{
name: 'webkit',
use: { ...devices['Desktop Safari'] },
},
// {
// name: 'webkit',
// use: { ...devices['Desktop Safari'] },
// },

/* Test against mobile viewports. */
// {
Expand Down
10 changes: 7 additions & 3 deletions resources/js/Layouts/AppLayout.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,17 @@ import Banner from '@/Components/Banner.vue';
import OrganizationSwitcher from '@/Components/OrganizationSwitcher.vue';
import CurrentSidebarTimer from '@/Components/CurrentSidebarTimer.vue';
import {
Bars3Icon,
ChartBarIcon,
ClockIcon,
Cog6ToothIcon,
CreditCardIcon,
FolderIcon,
HomeIcon,
TagIcon,
UserCircleIcon,
UserGroupIcon,
Bars3Icon,
XMarkIcon,
CreditCardIcon,
} from '@heroicons/vue/20/solid';
import NavigationSidebarItem from '@/Components/NavigationSidebarItem.vue';
import UserSettingsIcon from '@/Components/UserSettingsIcon.vue';
Expand All @@ -32,6 +32,7 @@ import {
import { isBillingActivated } from '@/utils/billing';
import type { User } from '@/types/models';
import { ArrowsRightLeftIcon } from '@heroicons/vue/16/solid';
import { fetchToken, isTokenValid } from '@/utils/api';
defineProps({
title: String,
Expand All @@ -45,7 +46,10 @@ onMounted(async () => {
window.initialDataLoaded = true;
initializeStores();
}
window.onfocus = () => {
window.onfocus = async () => {
if (!isTokenValid()) {
await fetchToken();
}
refreshStores();
};
});
Expand Down
14 changes: 14 additions & 0 deletions resources/js/utils/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import type {
ZodiosQueryParamsByAlias,
} from '@zodios/core';
import { api } from '../../../openapi.json.client';
import { router } from '@inertiajs/vue3';

export type SolidTimeApi = ApiOf<typeof api>;

Expand Down Expand Up @@ -123,3 +124,16 @@ export type UpdateOrganizationBody = ZodiosBodyByAlias<
SolidTimeApi,
'updateOrganization'
>;

export async function fetchToken() {
return new Promise((resolve) => {
router.reload({
onFinish: () => {
resolve(null);
},
});
});
}
export function isTokenValid() {
return window.document.cookie.includes('solidtime_session');
}
11 changes: 1 addition & 10 deletions resources/js/utils/notification.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { defineStore } from 'pinia';
import { ref } from 'vue';
import axios from 'axios';
import { router } from '@inertiajs/vue3';
import { fetchToken } from '@/utils/api';

export type NotificationType = 'success' | 'error';

Expand Down Expand Up @@ -37,16 +38,6 @@ export const useNotificationsStore = defineStore('notifications', () => {
}
}

async function fetchToken() {
return new Promise((resolve) => {
router.reload({
onFinish: () => {
resolve(null);
},
});
});
}

async function handleApiRequestNotifications<T>(
apiRequest: () => Promise<T>,
successMessage?: string,
Expand Down

0 comments on commit a10d056

Please sign in to comment.