hide edit button if signed in

This commit is contained in:
2025-03-23 01:56:42 +01:00
parent 7402b548a3
commit 9211070ab2
5 changed files with 21 additions and 12 deletions

View File

@@ -1,8 +1,9 @@
import { env } from '$env/dynamic/private';
import * as schema from './schema';
import { drizzle } from 'drizzle-orm/postgres-js';
import postgres from 'postgres';
const client = postgres(process.env.DB_URL, { prepare: false });
const client = postgres(env.DB_URL, { prepare: false });
export const db = drizzle({
schema,
client

View File

@@ -0,0 +1,5 @@
export const load = async ({ cookies }) => {
return {
editable: cookies.get('token')
};
};

View File

@@ -6,7 +6,7 @@
interface Props {
children?: import('svelte').Snippet;
}
const { children }: Props = $props();
const { children, data }: Props = $props();
let editModalVisible = $state(false);
</script>
@@ -77,12 +77,14 @@
{@render children?.()}
</main>
{#if !data.editable}
<div class="flex justify-end">
<button
class="p-3 rounded border border-white m-4"
onclick={() => (editModalVisible = !editModalVisible)}>Edit</button
>
</div>
{/if}
</div>
{#if editModalVisible}

View File

@@ -1,3 +1,5 @@
import { env } from '$env/dynamic/private';
export const actions = {
authenticate: async ({ request, cookies }) => {
const data = await request.formData();
@@ -10,7 +12,7 @@ export const actions = {
};
}
if (token !== process.env.AUTH_TOKEN) {
if (token !== env.AUTH_TOKEN) {
return {
status: 401,
body: { error: 'Invalid token' }
@@ -19,7 +21,7 @@ export const actions = {
cookies.set('token', token, {
path: '/',
maxAge: 60 * 60 * 24 * 7,
maxAge: 60 * 60 * 24 * 7
});
return {

View File

@@ -13,7 +13,6 @@ export const load = async ({ cookies }) => {
}
},
orderBy: [desc(tasks.currentPoints)]
}),
editable: cookies.get('token')
})
};
};