Init repo
This commit is contained in:
14
src/lib/server/auth.ts
Normal file
14
src/lib/server/auth.ts
Normal file
@@ -0,0 +1,14 @@
|
||||
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
|
||||
});
|
||||
1
src/lib/server/db/auth.schema.ts
Normal file
1
src/lib/server/db/auth.schema.ts
Normal file
@@ -0,0 +1 @@
|
||||
// If you see this file, you have not run the auth:schema script yet, but you should!
|
||||
10
src/lib/server/db/index.ts
Normal file
10
src/lib/server/db/index.ts
Normal file
@@ -0,0 +1,10 @@
|
||||
import { drizzle } from 'drizzle-orm/libsql';
|
||||
import { createClient } from '@libsql/client';
|
||||
import * as schema from './schema';
|
||||
import { env } from '$env/dynamic/private';
|
||||
|
||||
if (!env.DATABASE_URL) throw new Error('DATABASE_URL is not set');
|
||||
|
||||
const client = createClient({ url: env.DATABASE_URL });
|
||||
|
||||
export const db = drizzle(client, { schema });
|
||||
11
src/lib/server/db/schema.ts
Normal file
11
src/lib/server/db/schema.ts
Normal file
@@ -0,0 +1,11 @@
|
||||
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 * from './auth.schema';
|
||||
Reference in New Issue
Block a user