improvement: notification feature polished. feature tabs following the same notification socket emmited data to be updated.
This commit is contained in:
11
frontend/src/lib/auth/accessTokenEvents.ts
Normal file
11
frontend/src/lib/auth/accessTokenEvents.ts
Normal file
@@ -0,0 +1,11 @@
|
||||
/** Dispatched after a successful access-token refresh so realtime can reconnect with the new cookie. */
|
||||
export const ACCESS_TOKEN_REFRESHED_EVENT = 'dyolink:access-token-refreshed';
|
||||
|
||||
export function notifyAccessTokenRefreshed() {
|
||||
if (typeof window === 'undefined') return;
|
||||
window.dispatchEvent(new Event(ACCESS_TOKEN_REFRESHED_EVENT));
|
||||
}
|
||||
|
||||
export function accessTokenRefreshedEventName() {
|
||||
return ACCESS_TOKEN_REFRESHED_EVENT;
|
||||
}
|
||||
@@ -1,4 +1,5 @@
|
||||
import { authApi } from '@/lib/api/auth';
|
||||
import { notifyAccessTokenRefreshed } from '@/lib/auth/accessTokenEvents';
|
||||
|
||||
const STORAGE_KEY = 'dyolink.accessTokenExpiresAt';
|
||||
/** Refresh this long before the access JWT expires. */
|
||||
@@ -91,6 +92,7 @@ async function refreshAccessTokenWithOrg(): Promise<string | undefined> {
|
||||
}
|
||||
|
||||
lastRefreshAt = Date.now();
|
||||
notifyAccessTokenRefreshed();
|
||||
return expiresAt;
|
||||
} finally {
|
||||
refreshInFlight = null;
|
||||
|
||||
Reference in New Issue
Block a user