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.

refactor(auth): type the admin-promotion hook's user via UserWithAnonymous

Andrej4bf548bedf39
diff --git a/apps/api/src/auth.ts b/apps/api/src/auth.ts
index b3678b2a7..3bd936466 100644
--- a/apps/api/src/auth.ts
+++ b/apps/api/src/auth.ts
@@ -21,6 +21,7 @@ import {
openAPI,
organization,
} from "better-auth/plugins";
+import type { UserWithAnonymous } from "better-auth/plugins/anonymous";
import { config } from "dotenv-mono";
import { count, eq, sql } from "drizzle-orm";
import db, { schema } from "./database";
@@ -380,8 +381,11 @@ export const auth = betterAuth({
after: async (user) => {
// The anonymous() plugin creates ephemeral users for guest
// access; never promote one to instance admin even if no
- // real admin exists yet.
- if ((user as { isAnonymous?: boolean }).isAnonymous) {
+ // real admin exists yet. `isAnonymous` is contributed by the
+ // anonymous plugin's `additionalFields` and isn't part of the
+ // base User type, so we narrow through `UserWithAnonymous`.
+ const userWithAnonymous = user as Partial<UserWithAnonymous>;
+ if (userWithAnonymous.isAnonymous) {
return;
}