Skip to content

Commit 2e6cf56

Browse files
author
wec
committed
feat: Check valid ORIGIN
1 parent a8e5e10 commit 2e6cf56

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

src/routes/+layout.server.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,13 @@
11
import type { LayoutServerLoad } from './$types';
2+
import { env } from '$env/dynamic/private';
23

3-
export const load: LayoutServerLoad = async ({ locals }) => {
4+
export const load: LayoutServerLoad = async ({ locals, url }) => {
5+
const origin = env.ORIGIN ?? '';
46
return {
7+
originWarning: {
8+
currentOrigin: url.origin,
9+
isWarning: origin !== url.origin
10+
},
511
userAuthenticated: locals.userAuthenticated
612
};
713
};

src/routes/+layout.svelte

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,20 @@
11
<script lang="ts">
22
import { Toaster } from 'svelte-5-french-toast';
33
import '../app.css';
4-
let { children } = $props();
4+
let { children, data } = $props();
55
</script>
66

77
<Toaster />
8+
{#if data.originWarning.isWarning}
9+
<div class="w-full bg-red-600 p-2 text-center text-white">
10+
<p>
11+
Invalid origin found. Please specify ORIGIN={data.originWarning.currentOrigin}. Check
12+
<a
13+
target="_blank"
14+
class="underline"
15+
href="https://dashlit.cwec.dev/guide/getting-started.html">Docs</a
16+
>.
17+
</p>
18+
</div>
19+
{/if}
820
{@render children()}

0 commit comments

Comments
 (0)