feat: bearer auth, auto-sync events, test seed

- Add bearer plugin to BetterAuth for mobile auth
- Auto-sync birthday/anniversary events on client create/update
- Add /api/events/sync-all endpoint for bulk sync
- Add test user seed (test@test.com / test)
- Expose set-auth-token header in CORS
This commit is contained in:
2026-01-27 22:12:33 +00:00
parent f9643235be
commit 7bd506463e
8 changed files with 206 additions and 4 deletions

59
src/db/seed.ts Normal file
View File

@@ -0,0 +1,59 @@
import { db } from './index';
import { users, accounts } from './schema';
import { eq } from 'drizzle-orm';
// Hash password using the same method as BetterAuth (bcrypt via Bun)
async function hashPassword(password: string): Promise<string> {
return await Bun.password.hash(password, {
algorithm: 'bcrypt',
cost: 10,
});
}
async function seed() {
const testEmail = 'test@test.com';
// Check if test user already exists
const [existing] = await db.select()
.from(users)
.where(eq(users.email, testEmail))
.limit(1);
if (existing) {
console.log('✓ Test user already exists');
return;
}
// Create test user
const userId = crypto.randomUUID();
const hashedPassword = await hashPassword('test');
await db.insert(users).values({
id: userId,
email: testEmail,
name: 'Test User',
emailVerified: true,
createdAt: new Date(),
updatedAt: new Date(),
});
// Create credential account (for email/password login)
await db.insert(accounts).values({
id: crypto.randomUUID(),
userId: userId,
accountId: userId,
providerId: 'credential',
password: hashedPassword,
createdAt: new Date(),
updatedAt: new Date(),
});
console.log('✓ Created test user: test@test.com / test');
}
seed()
.then(() => process.exit(0))
.catch((err) => {
console.error('Seed failed:', err);
process.exit(1);
});