loads of nonsense

This commit is contained in:
2026-05-04 17:55:29 +01:00
parent a7caf77284
commit 3f6e8073e9
23 changed files with 390 additions and 188 deletions

View File

@@ -1,17 +0,0 @@
import type { Handle } from '@sveltejs/kit';
import { building } from '$app/environment';
import { auth } from '$lib/server/auth';
import { svelteKitHandler } from 'better-auth/svelte-kit';
const handleBetterAuth: Handle = async ({ event, resolve }) => {
const session = await auth.api.getSession({ headers: event.request.headers });
if (session) {
event.locals.session = session.session;
event.locals.user = session.user;
}
return svelteKitHandler({ event, resolve, auth, building });
};
export const handle: Handle = handleBetterAuth;

View File

@@ -1,16 +0,0 @@
import { betterAuth } from 'better-auth/minimal';
import { drizzleAdapter } from 'better-auth/adapters/drizzle';
import { sveltekitCookies } from 'better-auth/svelte-kit';
import { env } from '$env/dynamic/private';
import { getRequestEvent } from '$app/server';
import { db } from '$lib/server/db';
export const auth = betterAuth({
baseURL: env.ORIGIN,
secret: env.BETTER_AUTH_SECRET,
database: drizzleAdapter(db, { provider: 'sqlite' }),
emailAndPassword: { enabled: true },
plugins: [
sveltekitCookies(getRequestEvent) // make sure this is the last plugin in the array
]
});

View File

@@ -1 +0,0 @@
// If you see this file, you have not run the auth:schema script yet, but you should!

View File

@@ -1,9 +1,14 @@
import { integer, sqliteTable, text } from 'drizzle-orm/sqlite-core';
export const task = sqliteTable('task', {
id: text('id').primaryKey().$defaultFn(() => crypto.randomUUID()),
title: text('title').notNull(),
priority: integer('priority').notNull().default(1)
export const houses = sqliteTable('houses', {
id: integer('id').primaryKey({ autoIncrement: true }),
name: text('name').notNull(),
color: text('color').notNull().default('white'),
points: integer('points').notNull().default(0)
});
export * from './auth.schema';
export const consests = sqliteTable('contests', {
id: integer('id').primaryKey({ autoIncrement: true }),
event: text('event').notNull()
// house:dd make someting idk
});

View File

@@ -0,0 +1,21 @@
import { db } from '$lib/server/db';
import { houses } from '$lib/server/db/schema';
export class House {
name: string = '';
color: string = 'white';
points: number = $state(0);
}
export const load = async () => {
const allHouses = await db.select().from(houses);
console.log(allHouses);
return {
houses: allHouses.map((house) => ({
...house,
name: house.name,
color: house.color,
points: house.points
}))
};
};

View File

@@ -0,0 +1,46 @@
<script lang="ts">
import type { PageData } from './$types';
let { data }: { data: import('./$types').PageData } = $props();
// const housesArr: string[][] = [
// ['county', 'red'],
// ['east', 'pink'],
// ['laud', 'teal'],
// ['school', 'green'],
// ['west', 'yellow']
// ];
// let houses: House[] = [];
// housesArr.forEach((value: string[]) => {
// let newHouse = new House();
// newHouse.name = value[0];
// newHouse.color = `var(--ctp-mocha-${value[1]})`;
// houses.push(newHouse);
// });
let leaderboard = $derived([...data.houses].sort((a, b) => b.points - a.points));
</script>
<div
class="grid-cols-1 justify-center p-10 sm:grid sm:grid-cols-2 md:grid-cols-2 lg:flex lg:flex-row"
>
{#each leaderboard as house (house.name)}
<div
style="--theme-color: {house.color};"
class="--theme-color: m-5 border-solid {house.color} score-box aspect-1/1 rounded-2xl border-3 first:col-span-2 sm:first:aspect-2/1 lg:w-70"
>
<div class="text-center">{house.name}</div>
<div class="items-center justify-center text-center"><p>{house.points}</p></div>
</div>
{/each}
</div>
<style>
@import url('https://cdn.jsdelivr.net/npm/@catppuccin/palette/css/catppuccin.css');
.score-box {
color: var(--theme-color);
border-color: var(--theme-color);
background-color: color-mix(in srgb, var(--theme-color), transparent 90%);
}
</style>

View File

@@ -1,5 +0,0 @@
<script lang="ts">
import { resolve } from '$app/paths';
</script>
<a href={resolve('/demo/better-auth')}>better-auth</a>

View File

@@ -1,20 +0,0 @@
import { redirect } from '@sveltejs/kit';
import type { Actions } from './$types';
import type { PageServerLoad } from './$types';
import { auth } from '$lib/server/auth';
export const load: PageServerLoad = (event) => {
if (!event.locals.user) {
return redirect(302, '/demo/better-auth/login');
}
return { user: event.locals.user };
};
export const actions: Actions = {
signOut: async (event) => {
await auth.api.signOut({
headers: event.request.headers
});
return redirect(302, '/demo/better-auth/login');
}
};

View File

@@ -1,12 +0,0 @@
<script lang='ts'>
import { enhance } from '$app/forms';
import type { PageServerData } from './$types';
let { data }: { data: PageServerData } = $props();
</script>
<h1>Hi, {data.user.name}!</h1>
<p>Your user ID is {data.user.id}.</p>
<form method="post" action="?/signOut" use:enhance>
<button class="bg-blue-600 text-white px-4 py-2 rounded-md hover:bg-blue-700 transition">Sign out</button>
</form>

View File

@@ -1,61 +0,0 @@
import { fail, redirect } from '@sveltejs/kit';
import type { Actions } from './$types';
import type { PageServerLoad } from './$types';
import { auth } from '$lib/server/auth';
import { APIError } from 'better-auth/api';
export const load: PageServerLoad = (event) => {
if (event.locals.user) {
return redirect(302, '/demo/better-auth');
}
return {};
};
export const actions: Actions = {
signInEmail: async (event) => {
const formData = await event.request.formData();
const email = formData.get('email')?.toString() ?? '';
const password = formData.get('password')?.toString() ?? '';
try {
await auth.api.signInEmail({
body: {
email,
password,
callbackURL: '/auth/verification-success'
}
});
} catch (error) {
if (error instanceof APIError) {
return fail(400, { message: error.message || 'Signin failed' });
}
return fail(500, { message: 'Unexpected error' });
}
return redirect(302, '/demo/better-auth');
},
signUpEmail: async (event) => {
const formData = await event.request.formData();
const email = formData.get('email')?.toString() ?? '';
const password = formData.get('password')?.toString() ?? '';
const name = formData.get('name')?.toString() ?? '';
try {
await auth.api.signUpEmail({
body: {
email,
password,
name,
callbackURL: '/auth/verification-success'
}
});
} catch (error) {
if (error instanceof APIError) {
return fail(400, { message: error.message || 'Registration failed' });
}
return fail(500, { message: 'Unexpected error' });
}
return redirect(302, '/demo/better-auth');
},
};

View File

@@ -1,25 +0,0 @@
<script lang='ts'>
import { enhance } from '$app/forms';
import type { ActionData } from './$types';
let { form }: { form: ActionData } = $props();
</script>
<h1>Login</h1>
<form method="post" action="?/signInEmail" use:enhance>
<label>
Email
<input type="email" name="email" class="mt-1 px-3 py-2 bg-white border border-gray-300 rounded-md shadow-sm focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-blue-500" />
</label>
<label>
Password
<input type="password" name="password" class="mt-1 px-3 py-2 bg-white border border-gray-300 rounded-md shadow-sm focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-blue-500" />
</label>
<label>
Name (for registration)
<input name="name" class="mt-1 px-3 py-2 bg-white border border-gray-300 rounded-md shadow-sm focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-blue-500" />
</label>
<button class="bg-blue-600 text-white px-4 py-2 rounded-md hover:bg-blue-700 transition">Login</button>
<button formaction="?/signUpEmail" class="bg-blue-600 text-white px-4 py-2 rounded-md hover:bg-blue-700 transition">Register</button>
</form>
<p class="text-red-500">{form?.message ?? ''}</p>

View File

@@ -1,9 +1,5 @@
@import "tailwindcss";
@import url('https://cdn.jsdelivr.net/npm/@catppuccin/palette/css/catppuccin.css');
@import 'tailwindcss';
@import '@catppuccin/tailwindcss/mocha.css';
@plugin '@tailwindcss/forms';
@plugin '@tailwindcss/typography';
@import "@catppuccin/tailwindcss/mocha.css";
#svelte-body {
background-color: black;
}