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 { 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
|
||||
|
||||
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 {
|
||||
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}
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -13,7 +13,6 @@ export const load = async ({ cookies }) => {
|
||||
}
|
||||
},
|
||||
orderBy: [desc(tasks.currentPoints)]
|
||||
}),
|
||||
editable: cookies.get('token')
|
||||
})
|
||||
};
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user