feat: setup better-auth
This commit is contained in:
52
packages/auth/src/auth.ts
Normal file
52
packages/auth/src/auth.ts
Normal 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,
|
||||
},
|
||||
},
|
||||
});
|
||||
3
packages/auth/src/clients.ts
Normal file
3
packages/auth/src/clients.ts
Normal file
@@ -0,0 +1,3 @@
|
||||
import { createAuthClient } from "better-auth/react";
|
||||
|
||||
export const authClient = createAuthClient();
|
||||
6
packages/auth/src/index.ts
Normal file
6
packages/auth/src/index.ts
Normal file
@@ -0,0 +1,6 @@
|
||||
import { auth } from "./auth";
|
||||
import { authClient } from "./clients";
|
||||
|
||||
export const name = "auth";
|
||||
|
||||
export { auth, authClient };
|
||||
Reference in New Issue
Block a user