summaryrefslogtreecommitdiff
path: root/apps/web/src/lib/auth
diff options
context:
space:
mode:
authorMaze <167211895+mazeincoding@users.noreply.github.com>2026-01-31 00:20:04 +0100
committerGitHub <noreply@github.com>2026-01-31 00:20:04 +0100
commit7bf0984698e43b9aa2dd879f65951318ed410390 (patch)
treeccf2cd590a47d550152afc07129cb55c71a9ec35 /apps/web/src/lib/auth
parent0173db99448d1c4c6415dcf15272e17551b48b04 (diff)
downloadopencut-7bf0984698e43b9aa2dd879f65951318ed410390.tar.gz
codebase overhaul (#697)
Diffstat (limited to 'apps/web/src/lib/auth')
-rw-r--r--apps/web/src/lib/auth/client.ts6
-rw-r--r--apps/web/src/lib/auth/server.ts43
2 files changed, 49 insertions, 0 deletions
diff --git a/apps/web/src/lib/auth/client.ts b/apps/web/src/lib/auth/client.ts
new file mode 100644
index 00000000..63b441f7
--- /dev/null
+++ b/apps/web/src/lib/auth/client.ts
@@ -0,0 +1,6 @@
+import { createAuthClient } from "better-auth/react";
+import { webEnv } from "@opencut/env/web";
+
+export const { signIn, signUp, useSession } = createAuthClient({
+ baseURL: webEnv.NEXT_PUBLIC_SITE_URL,
+});
diff --git a/apps/web/src/lib/auth/server.ts b/apps/web/src/lib/auth/server.ts
new file mode 100644
index 00000000..978d7383
--- /dev/null
+++ b/apps/web/src/lib/auth/server.ts
@@ -0,0 +1,43 @@
+import { betterAuth, type RateLimit } from "better-auth";
+import { drizzleAdapter } from "better-auth/adapters/drizzle";
+import { Redis } from "@upstash/redis";
+import { db } from "@/lib/db";
+import { webEnv } from "@opencut/env/web";
+
+const redis = new Redis({
+ url: webEnv.UPSTASH_REDIS_REST_URL,
+ token: webEnv.UPSTASH_REDIS_REST_TOKEN,
+});
+
+export const auth = betterAuth({
+ database: drizzleAdapter(db, {
+ provider: "pg",
+ usePlural: true,
+ }),
+ secret: webEnv.BETTER_AUTH_SECRET,
+ user: {
+ deleteUser: {
+ enabled: true,
+ },
+ },
+ emailAndPassword: {
+ enabled: true,
+ },
+ rateLimit: {
+ storage: "secondary-storage",
+ customStorage: {
+ get: async (key) => {
+ const value = await redis.get(key);
+ return value as RateLimit | undefined;
+ },
+ set: async (key, value) => {
+ await redis.set(key, value);
+ },
+ },
+ },
+ baseURL: webEnv.NEXT_PUBLIC_SITE_URL,
+ appName: "OpenCut",
+ trustedOrigins: [webEnv.NEXT_PUBLIC_SITE_URL],
+});
+
+export type Auth = typeof auth;