feat: setup better-auth
This commit is contained in:
9
packages/auth/eslint.config.js
Normal file
9
packages/auth/eslint.config.js
Normal file
@@ -0,0 +1,9 @@
|
||||
import baseConfig from "@kan/eslint-config/base";
|
||||
|
||||
/** @type {import('typescript-eslint').Config} */
|
||||
export default [
|
||||
{
|
||||
ignores: [],
|
||||
},
|
||||
...baseConfig,
|
||||
];
|
||||
32
packages/auth/package.json
Normal file
32
packages/auth/package.json
Normal file
@@ -0,0 +1,32 @@
|
||||
{
|
||||
"name": "@kan/auth",
|
||||
"private": true,
|
||||
"version": "0.1.0",
|
||||
"type": "module",
|
||||
"exports": {
|
||||
".": "./src/index.ts"
|
||||
},
|
||||
"license": "MIT",
|
||||
"scripts": {
|
||||
"build": "tsc",
|
||||
"clean": "git clean -xdf .cache .turbo dist node_modules",
|
||||
"dev": "tsc",
|
||||
"format": "prettier --check . --ignore-path ../../.gitignore",
|
||||
"lint": "eslint",
|
||||
"typecheck": "tsc --noEmit --emitDeclarationOnly false"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@kan/db": "workspace:*",
|
||||
"@kan/eslint-config": "workspace:*",
|
||||
"@kan/prettier-config": "workspace:*",
|
||||
"@kan/shared": "workspace:*",
|
||||
"@kan/tsconfig": "workspace:*",
|
||||
"eslint": "catalog:",
|
||||
"prettier": "catalog:",
|
||||
"typescript": "catalog:"
|
||||
},
|
||||
"prettier": "@kan/prettier-config",
|
||||
"dependencies": {
|
||||
"better-auth": "^1.2.7"
|
||||
}
|
||||
}
|
||||
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 };
|
||||
6
packages/auth/tsconfig.json
Normal file
6
packages/auth/tsconfig.json
Normal file
@@ -0,0 +1,6 @@
|
||||
{
|
||||
"extends": "@kan/tsconfig/internal-package.json",
|
||||
"compilerOptions": {},
|
||||
"include": ["*.ts", "src"],
|
||||
"exclude": ["node_modules"]
|
||||
}
|
||||
Reference in New Issue
Block a user