added auth

This commit is contained in:
2025-07-27 12:12:22 -04:00
parent 1d2e90a183
commit 82dbefa565
36 changed files with 729 additions and 95 deletions

7
src/lib/auth-client.ts Normal file
View File

@ -0,0 +1,7 @@
import { createAuthClient } from "better-auth/svelte"
export const authClient = createAuthClient({
/** The base URL of the server (optional if you're using the same domain) */
baseURL: "http://localhost:5173",
})
export const { signIn, signUp, useSession } = authClient;

17
src/lib/auth.ts Normal file
View File

@ -0,0 +1,17 @@
import { betterAuth } from "better-auth";
import { Pool } from "pg";
import { sveltekitCookies } from "better-auth/svelte-kit";
import { getRequestEvent } from "$app/server";
export const auth = betterAuth({
database: new Pool({
connectionString: 'postgresql://budget:budget@sql.caseytimm.com:5432/budget',
}),
account: {
modelName: 'auth_accounts',
},
emailAndPassword: {
enabled: true,
},
plugins: [sveltekitCookies(getRequestEvent)],
})

26
src/lib/login.svelte Normal file
View File

@ -0,0 +1,26 @@
<script>
import { signIn, signUp } from '$lib/auth-client';
let email = $state('');
let password = $state('');
async function handleLogin() {
let res = await signIn.email({ email, password });
console.log('Login response:', res);
}
</script>
<form>
<div class="flex justify-center items-center h-screen">
<fieldset class="fieldset bg-base-200 border-base-300 rounded-box w-xs border p-4">
<legend class="fieldset-legend">Login</legend>
<label class="label">Username</label>
<input type="email" class="input" placeholder="Username" bind:value={email} />
<label class="label">Password</label>
<input type="password" class="input" placeholder="Password" bind:value={password} />
<button class="btn btn-neutral mt-4" onclick={() => handleLogin()}>Login</button>
</fieldset>
</div>
</form>