Skip to content

Commit

Permalink
Rename
Browse files Browse the repository at this point in the history
  • Loading branch information
zobweyt committed Sep 8, 2024
1 parent f5983e1 commit 665bfa2
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 17 deletions.
4 changes: 2 additions & 2 deletions frontend/src/app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Router } from "@solidjs/router";
import { FileRoutes } from "@solidjs/start/router";
import { Suspense } from "solid-js";
import { Toaster } from "solid-sonner";
import { SessionExpirationMonitor } from "~/components";
import { SessionExpirationObserver } from "~/components";
import { I18nProvider } from "~/lib/i18n";
import { PreferencesProvider } from "~/lib/preferences";
import { ThemeProvider } from "~/lib/theme";
Expand All @@ -20,7 +20,7 @@ export default function App() {
<Suspense>{props.children}</Suspense>

<Toaster />
<SessionExpirationMonitor />
<SessionExpirationObserver />
</ThemeProvider>
</I18nProvider>
</PreferencesProvider>
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/components/index.tsx
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
export * from "./ui";
export * from "./session-expiration-monitor";
export * from "./session-expiration-observer";
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { getCurrentUser } from "~/lib/api/users/me";
import { getIsLoggedIn, getSessionExpirationDate } from "~/lib/http";
import { useI18n } from "~/lib/i18n";

export const SessionExpirationMonitor: ParentComponent = (props) => {
export const SessionExpirationObserver: ParentComponent = (props) => {
const sync = new BroadcastChannel("auth_sync");

const i18n = useI18n();
Expand Down Expand Up @@ -53,19 +53,6 @@ export const SessionExpirationMonitor: ParentComponent = (props) => {
};
});

createEffect(
on(sessionExpirationDate, () => {
const expirationDate = sessionExpirationDate();
if (!expirationDate) return;

const expiresAfterMs = expirationDate - Date.now();
if (expiresAfterMs <= 0) return;

const timeout = setTimeout(invalidateSession, expiresAfterMs);
rewriteRevalidateTimeout(timeout);
}),
);

createEffect(
on(isLoggedIn, () => {
sync.postMessage(true);
Expand All @@ -79,6 +66,19 @@ export const SessionExpirationMonitor: ParentComponent = (props) => {
}),
);

createEffect(
on(sessionExpirationDate, () => {
const expirationDate = sessionExpirationDate();
if (!expirationDate) return;

const expiresAfterMs = expirationDate - Date.now();
if (expiresAfterMs <= 0) return;

const timeout = setTimeout(invalidateSession, expiresAfterMs);
rewriteRevalidateTimeout(timeout);
}),
);

onCleanup(() => {
sync.close();
});
Expand Down

0 comments on commit 665bfa2

Please sign in to comment.