Skip to content

armgit / kaneo

Public Imported from GitHub
0

⚡ Project management that doesn't become the project. Boards, Gantt charts, and GitHub integration. Self-host it or use Kaneo Cloud.

chore(deps): update better auth

Andrej Acevskia2d0a3db374e
diff --git a/apps/api/package.json b/apps/api/package.json
index ec3ec2a4b..6d10dccb6 100644
--- a/apps/api/package.json
+++ b/apps/api/package.json
@@ -27,10 +27,10 @@
"@paralleldrive/cuid2": "^3.0.4",
"@valibot/to-json-schema": "^1.5.0",
"bcrypt": "^6.0.0",
- "better-auth": "^1.4.2",
+ "better-auth": "^1.4.7",
"croner": "^9.1.0",
"drizzle-kit": "^0.31.8",
- "drizzle-orm": "^0.45.1",
+ "drizzle-orm": "^0.41.0",
"hono": "^4.11.1",
"hono-openapi": "^1.1.2",
"octokit": "^5.0.5",
diff --git a/apps/api/src/auth.ts b/apps/api/src/auth.ts
index 5581e2154..cfd774993 100644
--- a/apps/api/src/auth.ts
+++ b/apps/api/src/auth.ts
@@ -114,7 +114,7 @@ export const auth = betterAuth({
? [
anonymous({
generateName: async () => generateDemoName(),
- emailDomainName: "kaneo.com",
+ emailDomainName: "kaneo.app",
}),
]
: []),
diff --git a/apps/api/src/index.ts b/apps/api/src/index.ts
index bfa27e7e7..e9c8ca694 100644
--- a/apps/api/src/index.ts
+++ b/apps/api/src/index.ts
@@ -20,6 +20,7 @@ import task from "./task";
import timeEntry from "./time-entry";
import { migrateSessionColumn } from "./utils/migrate-session-column";
import { migrateWorkspaceUserEmail } from "./utils/migrate-workspace-user-email";
+import { verifyApiKey } from "./utils/verify-api-key";
type ApiKey = {
id: string;
@@ -126,15 +127,17 @@ api.use("*", async (c, next) => {
const apiKey = authHeader.substring(7);
try {
- const result = await auth.api.verifyApiKey({
- body: { key: apiKey },
- });
+ const result = await verifyApiKey(apiKey);
- if (result.valid && result.key) {
+ if (result?.valid && result.key) {
c.set("userId", result.key.userId);
c.set("user", null);
c.set("session", null);
- c.set("apiKey", result.key);
+ c.set("apiKey", {
+ id: result.key.id,
+ userId: result.key.userId,
+ enabled: result.key.enabled,
+ });
return next();
}
diff --git a/apps/api/src/utils/verify-api-key.ts b/apps/api/src/utils/verify-api-key.ts
new file mode 100644
index 000000000..dc2e74c51
--- /dev/null
+++ b/apps/api/src/utils/verify-api-key.ts
@@ -0,0 +1,63 @@
+import { createHash } from "node:crypto";
+import { and, eq, gt, isNull, or } from "drizzle-orm";
+import db, { schema } from "../database";
+
+async function hashApiKey(key: string): Promise<string> {
+ const hash = createHash("sha256").update(key).digest();
+ return hash
+ .toString("base64")
+ .replace(/\+/g, "-")
+ .replace(/\//g, "_")
+ .replace(/=/g, "");
+}
+
+export async function verifyApiKey(key: string) {
+ const hashedKey = await hashApiKey(key);
+
+ const [apiKey] = await db
+ .select()
+ .from(schema.apikeyTable)
+ .where(
+ and(
+ eq(schema.apikeyTable.key, hashedKey),
+ eq(schema.apikeyTable.enabled, true),
+ or(
+ isNull(schema.apikeyTable.expiresAt),
+ gt(schema.apikeyTable.expiresAt, new Date()),
+ ),
+ ),
+ )
+ .limit(1);
+
+ if (!apiKey) {
+ return null;
+ }
+
+ return {
+ valid: true,
+ key: {
+ id: apiKey.id,
+ userId: apiKey.userId,
+ name: apiKey.name,
+ prefix: apiKey.prefix,
+ start: apiKey.start,
+ enabled: apiKey.enabled ?? false,
+ expiresAt: apiKey.expiresAt,
+ permissions: apiKey.permissions
+ ? (JSON.parse(apiKey.permissions) as Record<string, string[]>)
+ : null,
+ refillInterval: apiKey.refillInterval,
+ refillAmount: apiKey.refillAmount,
+ lastRefillAt: apiKey.lastRefillAt,
+ rateLimitEnabled: apiKey.rateLimitEnabled,
+ rateLimitTimeWindow: apiKey.rateLimitTimeWindow,
+ rateLimitMax: apiKey.rateLimitMax,
+ requestCount: apiKey.requestCount,
+ remaining: apiKey.remaining,
+ lastRequest: apiKey.lastRequest,
+ metadata: apiKey.metadata
+ ? (JSON.parse(apiKey.metadata) as Record<string, unknown>)
+ : null,
+ },
+ };
+}
diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml
index 77d197c03..6487c1b8e 100644
--- a/pnpm-lock.yaml
+++ b/pnpm-lock.yaml
@@ -70,8 +70,8 @@ importers:
specifier: ^6.0.0
version: 6.0.0
better-auth:
- specifier: ^1.4.2
+ specifier: ^1.4.7
croner:
specifier: ^9.1.0
version: 9.1.0
@@ -79,8 +79,8 @@ importers:
specifier: ^0.31.8
version: 0.31.8
drizzle-orm:
- specifier: ^0.45.1
+ specifier: ^0.41.0
hono:
specifier: ^4.11.1
version: 4.11.1
@@ -313,7 +313,7 @@ importers:
version: 19.0.0-beta-ebf51a3-20250411
better-auth:
specifier: ^1.4.5
class-variance-authority:
specifier: ^0.7.1
version: 0.7.1
@@ -3972,8 +3972,8 @@ packages:
resolution: {integrity: sha512-O9EC/miwdnRDY10qRxM8P3Pg8hXe3LyU4ZipReKOgTwn4OqANmftj8XJz1UPUAS6NMHf0E2htjsbQujUTkncCg==}
hasBin: true
- resolution: {integrity: sha512-Te0FOdKIistGNPMq2jscdqngBRfBpC8uMFVwqjf6gtTVJHIQ/dosgV/CLBU2N4ZJBsXL5savCba9b0YJskKdcA==}
+ resolution: {integrity: sha512-7A4ZxhHk9gdlXmTdPj/lREtP+3u8KvZ4yEN6MYVxBzZGex5Wtdc+CWSbu7btgF6TB0N+MNPrvW7RKBbxJchs/Q==}
peerDependencies:
'@aws-sdk/client-rds-data': '>=3'
'@cloudflare/workers-types': '>=4'
@@ -3983,13 +3983,12 @@ packages:
'@neondatabase/serverless': '>=0.10.0'
'@op-engineering/op-sqlite': '>=2'
'@opentelemetry/api': ^1.4.1
- '@planetscale/database': '>=1.13'
+ '@planetscale/database': '>=1'
'@prisma/client': '*'
'@tidbcloud/serverless': '*'
'@types/better-sqlite3': '*'
'@types/pg': '*'
'@types/sql.js': '*'
- '@upstash/redis': '>=1.34.7'
'@vercel/postgres': '>=0.8.0'
'@xata.io/client': '*'
better-sqlite3: '>=7'
@@ -4033,8 +4032,6 @@ packages:
optional: true
'@types/sql.js':
optional: true
- '@upstash/redis':
- optional: true
'@vercel/postgres':
optional: true
'@xata.io/client':
@@ -9686,7 +9683,7 @@ snapshots:
dependencies:
@@ -9702,7 +9699,7 @@ snapshots:
zod: 4.2.0
optionalDependencies:
drizzle-kit: 0.31.8
pg: 8.16.3
react: 19.2.3
@@ -9993,7 +9990,7 @@ snapshots:
transitivePeerDependencies:
- supports-color
optionalDependencies:
'@types/pg': 8.16.0
kysely: 0.28.9