feat: check for token for editing
This commit is contained in:
@@ -1,13 +1,18 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
|
import { enhance } from '$app/forms';
|
||||||
import '../app.css';
|
import '../app.css';
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
children?: import('svelte').Snippet;
|
children?: import('svelte').Snippet;
|
||||||
}
|
}
|
||||||
export let children: any;
|
const { children }: Props = $props();
|
||||||
|
|
||||||
|
let editModalVisible = $state(false);
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<!-- outer container, sets background and text color -->
|
<div
|
||||||
<div class="min-h-screen bg-black text-white bg-center bg-[url('/moon.jpg')] bg-auto bg-no-repeat">
|
class="min-h-screen bg-black text-white bg-center bg-[url('/moon.jpg')] bg-auto bg-no-repeat flex flex-col"
|
||||||
|
>
|
||||||
<nav class="flex justify-between bg-gray-800 items-center px-4 py-2">
|
<nav class="flex justify-between bg-gray-800 items-center px-4 py-2">
|
||||||
<div class="m-2">
|
<div class="m-2">
|
||||||
<a href="/" class="font-bold text-xl sm:text-2xl">Stan Runge</a>
|
<a href="/" class="font-bold text-xl sm:text-2xl">Stan Runge</a>
|
||||||
@@ -16,7 +21,7 @@
|
|||||||
<a href="/progress" class="hover:underline">Progress</a>
|
<a href="/progress" class="hover:underline">Progress</a>
|
||||||
<span>|</span>
|
<span>|</span>
|
||||||
<div class="flex gap-2 items-center">
|
<div class="flex gap-2 items-center">
|
||||||
<a href="mailto:stan@stanrunge.dev" class="hover:text-gray-300">
|
<a href="mailto:stan@stanrunge.dev" class="hover:text-gray-300" aria-label="Mail">
|
||||||
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24">
|
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24">
|
||||||
<path
|
<path
|
||||||
fill="currentColor"
|
fill="currentColor"
|
||||||
@@ -24,7 +29,7 @@
|
|||||||
/>
|
/>
|
||||||
</svg>
|
</svg>
|
||||||
</a>
|
</a>
|
||||||
<a href="https://github.com/stanrunge" class="hover:text-gray-300">
|
<a href="https://github.com/stanrunge" class="hover:text-gray-300" aria-label="GitHub">
|
||||||
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24">
|
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24">
|
||||||
<path
|
<path
|
||||||
fill="currentColor"
|
fill="currentColor"
|
||||||
@@ -37,7 +42,7 @@
|
|||||||
/>
|
/>
|
||||||
</svg>
|
</svg>
|
||||||
</a>
|
</a>
|
||||||
<a href="https://x.com/stanrunge" class="hover:text-gray-300">
|
<a href="https://x.com/stanrunge" class="hover:text-gray-300" aria-label="X">
|
||||||
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24">
|
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24">
|
||||||
<path
|
<path
|
||||||
fill="currentColor"
|
fill="currentColor"
|
||||||
@@ -46,7 +51,11 @@
|
|||||||
/>
|
/>
|
||||||
</svg>
|
</svg>
|
||||||
</a>
|
</a>
|
||||||
<a href="https://linkedin.com/in/stanrunge" class="hover:text-gray-300">
|
<a
|
||||||
|
href="https://linkedin.com/in/stanrunge"
|
||||||
|
class="hover:text-gray-300"
|
||||||
|
aria-label="LinkedIn"
|
||||||
|
>
|
||||||
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24">
|
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24">
|
||||||
<path
|
<path
|
||||||
fill="currentColor"
|
fill="currentColor"
|
||||||
@@ -62,7 +71,34 @@
|
|||||||
</nav>
|
</nav>
|
||||||
|
|
||||||
<!-- page content goes here -->
|
<!-- page content goes here -->
|
||||||
<main class="mx-auto py-8 px-4 max-w-5xl">
|
<main class="mx-auto py-8 px-4 max-w-5xl flex-grow">
|
||||||
{@render children?.()}
|
{@render children?.()}
|
||||||
</main>
|
</main>
|
||||||
|
|
||||||
|
<div class="flex justify-end">
|
||||||
|
<button
|
||||||
|
class="p-3 rounded border border-white m-4"
|
||||||
|
onclick={() => (editModalVisible = !editModalVisible)}>Edit</button
|
||||||
|
>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
{#if editModalVisible}
|
||||||
|
<div
|
||||||
|
class="fixed inset-0 flex items-center justify-center bg-black bg-opacity-50"
|
||||||
|
onclick={() => (editModalVisible = false)}
|
||||||
|
>
|
||||||
|
<form
|
||||||
|
class="bg-white rounded-lg shadow-lg p-6 max-w-md w-full flex flex-col items-center"
|
||||||
|
onclick={(e) => e.stopPropagation()}
|
||||||
|
action="/?/authenticate"
|
||||||
|
method="post"
|
||||||
|
>
|
||||||
|
<h2 class="text-lg font-semibold m-4">WHO ARE YOU?!?!?!??!</h2>
|
||||||
|
<input type="text" class="border border-black rounded my-4" name="token" />
|
||||||
|
<button class="px-4 py-2 bg-gray-800 text-white rounded hover:bg-gray-700">
|
||||||
|
Authenticate
|
||||||
|
</button>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
{/if}
|
||||||
|
|||||||
@@ -1,9 +1,30 @@
|
|||||||
// import { myTable, db } from '$lib/db/schema';
|
import { AUTH_TOKEN } from '$env/static/private';
|
||||||
import type { PageServerLoad } from './$types';
|
|
||||||
|
|
||||||
export const load = (async () => {
|
export const actions = {
|
||||||
// const result = await db.select().from(myTable);
|
authenticate: async ({ request, cookies }) => {
|
||||||
|
const data = await request.formData();
|
||||||
|
|
||||||
|
const token = data.get('token');
|
||||||
|
if (!token) {
|
||||||
return {
|
return {
|
||||||
message: 'Hi :4888829383991292222244343434'
|
status: 400,
|
||||||
|
body: { error: 'Missing token' }
|
||||||
};
|
};
|
||||||
}) satisfies PageServerLoad;
|
}
|
||||||
|
|
||||||
|
if (token !== AUTH_TOKEN) {
|
||||||
|
return {
|
||||||
|
status: 401,
|
||||||
|
body: { error: 'Invalid token' }
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
cookies.set('token', token, {
|
||||||
|
path: '/'
|
||||||
|
});
|
||||||
|
|
||||||
|
return {
|
||||||
|
success: true
|
||||||
|
};
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|||||||
@@ -1,7 +1,8 @@
|
|||||||
import { db } from "$lib/db"
|
import { db } from '$lib/db';
|
||||||
|
|
||||||
export const load = async () => {
|
export const load = async ({ cookies }) => {
|
||||||
return {
|
return {
|
||||||
tasks: await db.query.tasks.findMany()
|
tasks: await db.query.tasks.findMany(),
|
||||||
}
|
editable: cookies.get('token')
|
||||||
}
|
};
|
||||||
|
};
|
||||||
|
|||||||
@@ -7,11 +7,13 @@
|
|||||||
<h1 class="font-bold text-2xl">
|
<h1 class="font-bold text-2xl">
|
||||||
Tasks ({data.tasks.length})
|
Tasks ({data.tasks.length})
|
||||||
</h1>
|
</h1>
|
||||||
|
{#if data.editable}
|
||||||
<a href="/progress/create">
|
<a href="/progress/create">
|
||||||
<button class="px-4 py-2 bg-green-500 text-white rounded hover:bg-green-600 transition">
|
<button class="px-4 py-2 bg-green-500 text-white rounded hover:bg-green-600 transition">
|
||||||
Create
|
Create
|
||||||
</button>
|
</button>
|
||||||
</a>
|
</a>
|
||||||
|
{/if}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{#if data.tasks.length > 0}
|
{#if data.tasks.length > 0}
|
||||||
|
|||||||
Reference in New Issue
Block a user