feat: setup better-auth

This commit is contained in:
Henry
2025-05-02 23:40:34 +01:00
parent 5996ad19c3
commit 091fea6f38
23 changed files with 4696 additions and 30 deletions

52
packages/auth/src/auth.ts Normal file
View File

@@ -0,0 +1,52 @@
import { betterAuth } from "better-auth";
import { drizzleAdapter } from "better-auth/adapters/drizzle";
import { apiKey } from "better-auth/plugins";
import { magicLink } from "better-auth/plugins/magic-link";
import { createDrizzleClient } from "@kan/db/client";
import * as schema from "@kan/db/schema";
const db = createDrizzleClient();
console.log("GOOGLE_CLIENT_ID", process.env.GOOGLE_CLIENT_ID);
console.log("GOOGLE_CLIENT_SECRET", process.env.GOOGLE_CLIENT_SECRET);
export const auth = betterAuth({
database: drizzleAdapter(db, {
provider: "pg",
schema: {
...schema,
user: schema.users,
},
}),
socialProviders: {
google: {
clientId: process.env.GOOGLE_CLIENT_ID!,
clientSecret: process.env.GOOGLE_CLIENT_SECRET!,
},
},
user: {
additionalFields: {
stripeCustomerId: {
type: "string",
required: false,
defaultValue: null,
input: false,
},
},
},
plugins: [
apiKey(),
magicLink({
sendMagicLink: async ({ email, token, url }, request) => {
// send email to user
},
}),
],
advanced: {
cookiePrefix: "kan",
database: {
generateId: false,
},
},
});

View File

@@ -0,0 +1,3 @@
import { createAuthClient } from "better-auth/react";
export const authClient = createAuthClient();

View File

@@ -0,0 +1,6 @@
import { auth } from "./auth";
import { authClient } from "./clients";
export const name = "auth";
export { auth, authClient };