hide edit button if signed in
This commit is contained in:
@@ -1,8 +1,9 @@
|
|||||||
|
import { env } from '$env/dynamic/private';
|
||||||
import * as schema from './schema';
|
import * as schema from './schema';
|
||||||
import { drizzle } from 'drizzle-orm/postgres-js';
|
import { drizzle } from 'drizzle-orm/postgres-js';
|
||||||
import postgres from 'postgres';
|
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({
|
export const db = drizzle({
|
||||||
schema,
|
schema,
|
||||||
client
|
client
|
||||||
|
|||||||
5
packages/web/src/routes/+layout.server.ts
Normal file
5
packages/web/src/routes/+layout.server.ts
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
export const load = async ({ cookies }) => {
|
||||||
|
return {
|
||||||
|
editable: cookies.get('token')
|
||||||
|
};
|
||||||
|
};
|
||||||
@@ -6,7 +6,7 @@
|
|||||||
interface Props {
|
interface Props {
|
||||||
children?: import('svelte').Snippet;
|
children?: import('svelte').Snippet;
|
||||||
}
|
}
|
||||||
const { children }: Props = $props();
|
const { children, data }: Props = $props();
|
||||||
|
|
||||||
let editModalVisible = $state(false);
|
let editModalVisible = $state(false);
|
||||||
</script>
|
</script>
|
||||||
@@ -77,12 +77,14 @@
|
|||||||
{@render children?.()}
|
{@render children?.()}
|
||||||
</main>
|
</main>
|
||||||
|
|
||||||
<div class="flex justify-end">
|
{#if !data.editable}
|
||||||
<button
|
<div class="flex justify-end">
|
||||||
class="p-3 rounded border border-white m-4"
|
<button
|
||||||
onclick={() => (editModalVisible = !editModalVisible)}>Edit</button
|
class="p-3 rounded border border-white m-4"
|
||||||
>
|
onclick={() => (editModalVisible = !editModalVisible)}>Edit</button
|
||||||
</div>
|
>
|
||||||
|
</div>
|
||||||
|
{/if}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{#if editModalVisible}
|
{#if editModalVisible}
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
import { env } from '$env/dynamic/private';
|
||||||
|
|
||||||
export const actions = {
|
export const actions = {
|
||||||
authenticate: async ({ request, cookies }) => {
|
authenticate: async ({ request, cookies }) => {
|
||||||
const data = await request.formData();
|
const data = await request.formData();
|
||||||
@@ -10,7 +12,7 @@ export const actions = {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
if (token !== process.env.AUTH_TOKEN) {
|
if (token !== env.AUTH_TOKEN) {
|
||||||
return {
|
return {
|
||||||
status: 401,
|
status: 401,
|
||||||
body: { error: 'Invalid token' }
|
body: { error: 'Invalid token' }
|
||||||
@@ -19,7 +21,7 @@ export const actions = {
|
|||||||
|
|
||||||
cookies.set('token', token, {
|
cookies.set('token', token, {
|
||||||
path: '/',
|
path: '/',
|
||||||
maxAge: 60 * 60 * 24 * 7,
|
maxAge: 60 * 60 * 24 * 7
|
||||||
});
|
});
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
|||||||
@@ -13,7 +13,6 @@ export const load = async ({ cookies }) => {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
orderBy: [desc(tasks.currentPoints)]
|
orderBy: [desc(tasks.currentPoints)]
|
||||||
}),
|
})
|
||||||
editable: cookies.get('token')
|
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user