bagsy/apps/api/lib/auth.ts
bananabas a59c092172 Fix: Configure passkey RPID and origin
Set `rpID` and `rpName` for passkey authentication. This is crucial for
WebAuthn to correctly identify the relying party and establish secure
credentials. Additionally, set the `origin` to ensure consistent
communication between the client and server during passkey operations.
2026-04-13 18:38:46 +01:00

39 lines
941 B
TypeScript

import { betterAuth } from 'better-auth';
import { organization, magicLink } from 'better-auth/plugins';
import { passkey } from '@better-auth/passkey';
import { drizzleAdapter } from 'better-auth/adapters/drizzle';
import { db } from '@/db';
import * as schema from '@/db/schema';
const baseURL = process.env.BETTER_AUTH_URL || 'http://localhost:3001';
export const auth = betterAuth({
baseURL,
database: drizzleAdapter(db, {
provider: 'pg',
schema,
}),
emailAndPassword: {
enabled: true,
},
plugins: [
organization(),
passkey({
rpID: new URL(baseURL).hostname,
rpName: 'Bagsy',
origin: baseURL,
}),
magicLink({
sendMagicLink: async ({ email, url }) => {
console.log(`Magic link for ${email}: ${url}`);
},
}),
],
trustedOrigins: [
baseURL,
'bagsy://',
'bagsy://localhost',
'http://localhost:3001',
'http://192.168.*:3001',
],
});