Skip to content

Commit

Permalink
Only load content after session is validated
Browse files Browse the repository at this point in the history
  • Loading branch information
daniellrgn committed Mar 30, 2024
1 parent 4f6e6e8 commit f8209c6
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 19 deletions.
17 changes: 13 additions & 4 deletions src/lib/SessionStatus.svelte
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
<script>
import { onMount, getContext } from "svelte";
<script lang="ts">
import { createEventDispatcher, onMount, getContext } from "svelte";
import { OIDC_BASE, CHECK_SESSION_IFRAME } from "./config";
import { goto } from "$app/navigation";
import type { SOFClient } from "./sofClient";
let sofClient = getContext('sofClient');
let sofClient: SOFClient = getContext('sofClient');
const validSessionDispatch = createEventDispatcher<{'valid-session': Boolean}>();
// Poll the OP iframe periodically
let checkSession = setInterval(checkSessionStatus, 5000); // Adjust interval as needed
let first = true;
onMount(() => {
// Listen for messages from OP iframe
Expand All @@ -22,7 +27,7 @@
opIframe?.contentWindow.postMessage(message, OIDC_BASE);
}
function processStatus(event) {
function processStatus(event: any) {
if (event.origin === OIDC_BASE) {
var data = event.data;
if (data === 'changed') {
Expand All @@ -36,6 +41,10 @@
} else if (data === 'error') {
goto('/logout');
}
if (first) {
first = false;
validSessionDispatch('valid-session', true);
}
}
}
</script>
Expand Down
37 changes: 22 additions & 15 deletions src/routes/+layout.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
let sofClient: SOFClient = new SOFClient(SOF_HOSTS[0]);
setContext('sofClient', sofClient);
let initialized = false;
let validSession = false;
let inactivityTimer: NodeJS.Timeout | undefined;
function resetInactivityTimer() {
Expand Down Expand Up @@ -107,20 +108,26 @@
</Collapse>
</Navbar>
{#if initialized}
<SessionStatus/>
<Row class="main-row">
<Col>
<slot />
</Col>
</Row>
<Row>
<Col style="margin-top: 20px; padding-top: 20px; border-top: 1px solid rgb(204, 204, 204);" >
<footer>
<Row class="justify-content-center">
<p><center>If you have any questions or problems using the system, please get in touch at <a href="mailto:[email protected]">[email protected]</a> for assistance.</center></p>
</Row>
</footer>
</Col>
</Row>
<SessionStatus on:valid-session={({ detail }) => {
if (detail) {
validSession = true;
}
}}/>
{#if validSession}
<Row class="main-row">
<Col>
<slot />
</Col>
</Row>
<Row>
<Col style="margin-top: 20px; padding-top: 20px; border-top: 1px solid rgb(204, 204, 204);" >
<footer>
<Row class="justify-content-center">
<p><center>If you have any questions or problems using the system, please get in touch at <a href="mailto:[email protected]">[email protected]</a> for assistance.</center></p>
</Row>
</footer>
</Col>
</Row>
{/if}
{/if}
</Container>

0 comments on commit f8209c6

Please sign in to comment.