34 lines
980 B
TypeScript
34 lines
980 B
TypeScript
import { betterAuth } from 'better-auth';
|
|
import { organization } from 'better-auth/plugins';
|
|
import { passkey } from '@better-auth/passkey';
|
|
import { magicLink } from 'better-auth/plugins';
|
|
import { drizzleAdapter } from 'better-auth/adapters/drizzle';
|
|
import { db } from '@/db';
|
|
|
|
/**
|
|
* Better Auth instance for authentication and authorization
|
|
* Plugins: organization (for households), passkey (for passwordless auth), magicLink (fallback)
|
|
*/
|
|
export const auth = betterAuth({
|
|
database: drizzleAdapter(db, {
|
|
provider: 'pg',
|
|
}),
|
|
emailAndPassword: {
|
|
enabled: true,
|
|
},
|
|
plugins: [
|
|
organization(),
|
|
passkey(),
|
|
magicLink({
|
|
sendMagicLink: async ({ email, url }) => {
|
|
// TODO: implement email sending (e.g., Resend, SendGrid)
|
|
console.log(`Magic link for ${email}: ${url}`);
|
|
},
|
|
}),
|
|
],
|
|
trustedOrigins: [
|
|
'shoplist://',
|
|
'shoplist://*',
|
|
...(process.env.NODE_ENV === 'development' ? ['exp://**'] : []),
|
|
],
|
|
});
|