feat: check for token for editing

This commit is contained in:
2025-01-19 21:27:27 +01:00
parent fcfabe4a8e
commit 710fd16088
4 changed files with 86 additions and 26 deletions

View File

@@ -1,9 +1,30 @@
// import { myTable, db } from '$lib/db/schema';
import type { PageServerLoad } from './$types';
import { AUTH_TOKEN } from '$env/static/private';
export const load = (async () => {
// const result = await db.select().from(myTable);
return {
message: 'Hi :4888829383991292222244343434'
};
}) satisfies PageServerLoad;
export const actions = {
authenticate: async ({ request, cookies }) => {
const data = await request.formData();
const token = data.get('token');
if (!token) {
return {
status: 400,
body: { error: 'Missing token' }
};
}
if (token !== AUTH_TOKEN) {
return {
status: 401,
body: { error: 'Invalid token' }
};
}
cookies.set('token', token, {
path: '/'
});
return {
success: true
};
}
};