From 3c3989eb1d37083414340f4e26aaf788f8f4699d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adel=20Rodr=C3=ADguez?= Date: Wed, 18 Feb 2026 23:28:50 -0400 Subject: [PATCH] refactor: move auth constants from utils to auth package --- apps/api/src/shared/auth.ts | 6 +- apps/mobile/src/shared/auth.ts | 3 - packages/auth/package.json | 9 +- packages/auth/src/constants.ts | 2 + packages/auth/src/expo/client.ts | 11 +- packages/auth/src/integrations/expo/client.ts | 1 + packages/auth/src/integrations/expo/server.ts | 1 + packages/auth/src/{ => integrations}/start.ts | 0 packages/auth/src/server/index.ts | 2 +- .../backend/src/functions/_generated/api.d.ts | 240 +++++++++--------- .../better-auth/_generated/component.ts | 240 +++++++++--------- .../better-auth/schema.generated.ts | 63 +++-- packages/backend/src/functions/shared/auth.ts | 6 +- packages/utils/package.json | 3 +- packages/utils/src/constants/app.ts | 2 - packages/utils/src/constants/index.ts | 1 - 16 files changed, 300 insertions(+), 290 deletions(-) create mode 100644 packages/auth/src/constants.ts create mode 100644 packages/auth/src/integrations/expo/client.ts create mode 100644 packages/auth/src/integrations/expo/server.ts rename packages/auth/src/{ => integrations}/start.ts (100%) delete mode 100644 packages/utils/src/constants/app.ts delete mode 100644 packages/utils/src/constants/index.ts diff --git a/apps/api/src/shared/auth.ts b/apps/api/src/shared/auth.ts index 316f3378..fd12644e 100644 --- a/apps/api/src/shared/auth.ts +++ b/apps/api/src/shared/auth.ts @@ -1,16 +1,16 @@ +import { AUTH_APP_NAME, AUTH_COOKIE_PREFIX } from "@init/auth/constants" import { createAuth, databaseAdapter } from "@init/auth/server" import { admin, organization } from "@init/auth/server/plugins" import { database } from "@init/db/client" -import { APP_ID, APP_NAME } from "@init/utils/constants" import { seconds } from "qte" import env from "#shared/env.ts" export const auth = createAuth({ advanced: { - cookiePrefix: APP_ID, + cookiePrefix: AUTH_COOKIE_PREFIX, database: { generateId: false }, }, - appName: APP_NAME, + appName: AUTH_APP_NAME, basePath: "/auth", baseURL: env.BASE_URL, database: databaseAdapter(database()), diff --git a/apps/mobile/src/shared/auth.ts b/apps/mobile/src/shared/auth.ts index add8aa1b..edc59f12 100644 --- a/apps/mobile/src/shared/auth.ts +++ b/apps/mobile/src/shared/auth.ts @@ -2,15 +2,12 @@ import { createAuthClient } from "@init/auth/client" import { adminClient, organizationClient } from "@init/auth/client/plugins" import { expoClient } from "@init/auth/expo/client" import { accessControl, adminRole, memberRole, ownerRole } from "@init/auth/permissions" -import { APP_ID } from "@init/utils/constants" import * as SecureStore from "expo-secure-store" import { buildApiUrl } from "#shared/utils.ts" export const auth = createAuthClient(buildApiUrl("/auth"), [ expoClient({ - scheme: APP_ID, storage: SecureStore, - storagePrefix: APP_ID, }), adminClient(), organizationClient({ diff --git a/packages/auth/package.json b/packages/auth/package.json index 3b35f212..2daeb17b 100644 --- a/packages/auth/package.json +++ b/packages/auth/package.json @@ -2,14 +2,19 @@ "name": "@init/auth", "private": true, "type": "module", + "imports": { + "#*": "./src/*" + }, "exports": { "./client": "./src/client/index.ts", "./client/plugins": "./src/client/plugins.ts", + "./constants": "./src/constants.ts", "./expo/*": "./src/expo/*.ts", + "./integrations/expo/*": "./src/integrations/expo/*.ts", + "./integrations/start": "./src/integrations/start.ts", "./permissions": "./src/permissions.ts", "./server": "./src/server/index.ts", - "./server/plugins": "./src/server/plugins.ts", - "./start": "./src/start.ts" + "./server/plugins": "./src/server/plugins.ts" }, "scripts": { "bump:deps": "bun update --interactive", diff --git a/packages/auth/src/constants.ts b/packages/auth/src/constants.ts new file mode 100644 index 00000000..ebf2fe2d --- /dev/null +++ b/packages/auth/src/constants.ts @@ -0,0 +1,2 @@ +export const AUTH_COOKIE_PREFIX = "init" +export const AUTH_APP_NAME = "Init" diff --git a/packages/auth/src/expo/client.ts b/packages/auth/src/expo/client.ts index 28d11c9f..a6572d74 100644 --- a/packages/auth/src/expo/client.ts +++ b/packages/auth/src/expo/client.ts @@ -1 +1,10 @@ -export { expoClient } from "@better-auth/expo/client" +import { expoClient as baseExpoClient } from "@better-auth/expo/client" +import { AUTH_COOKIE_PREFIX } from "#constants.ts" + +export function expoClient(opts: Parameters[0]) { + return baseExpoClient({ + scheme: AUTH_COOKIE_PREFIX, + storagePrefix: AUTH_COOKIE_PREFIX, + ...opts, + }) +} diff --git a/packages/auth/src/integrations/expo/client.ts b/packages/auth/src/integrations/expo/client.ts new file mode 100644 index 00000000..0c23a154 --- /dev/null +++ b/packages/auth/src/integrations/expo/client.ts @@ -0,0 +1 @@ +export { expoClient } from "#expo/client.ts" diff --git a/packages/auth/src/integrations/expo/server.ts b/packages/auth/src/integrations/expo/server.ts new file mode 100644 index 00000000..f1861422 --- /dev/null +++ b/packages/auth/src/integrations/expo/server.ts @@ -0,0 +1 @@ +export { expo } from "#expo/server.ts" diff --git a/packages/auth/src/start.ts b/packages/auth/src/integrations/start.ts similarity index 100% rename from packages/auth/src/start.ts rename to packages/auth/src/integrations/start.ts diff --git a/packages/auth/src/server/index.ts b/packages/auth/src/server/index.ts index b0a1bbe2..e625b80d 100644 --- a/packages/auth/src/server/index.ts +++ b/packages/auth/src/server/index.ts @@ -10,6 +10,6 @@ export function databaseAdapter(database: DB) { export { APIError as AuthError } from "better-auth/api" export { - betterAuth as createAuth, type BetterAuthOptions as AuthOptions, + betterAuth as createAuth, } from "better-auth/minimal" diff --git a/packages/backend/src/functions/_generated/api.d.ts b/packages/backend/src/functions/_generated/api.d.ts index dc4e887a..5f9cb8d6 100644 --- a/packages/backend/src/functions/_generated/api.d.ts +++ b/packages/backend/src/functions/_generated/api.d.ts @@ -189,18 +189,18 @@ export declare const components: { where?: Array<{ connector?: "AND" | "OR"; field: + | "accessToken" + | "accessTokenExpiresAt" | "accountId" + | "createdAt" + | "idToken" + | "password" | "providerId" - | "userId" - | "accessToken" | "refreshToken" - | "idToken" - | "accessTokenExpiresAt" | "refreshTokenExpiresAt" | "scope" - | "password" - | "createdAt" | "updatedAt" + | "userId" | "_id"; operator?: | "lt" @@ -228,13 +228,13 @@ export declare const components: { where?: Array<{ connector?: "AND" | "OR"; field: - | "organizationId" + | "createdAt" | "email" - | "role" - | "status" | "expiresAt" - | "createdAt" | "inviterId" + | "organizationId" + | "role" + | "status" | "_id"; operator?: | "lt" @@ -262,10 +262,10 @@ export declare const components: { where?: Array<{ connector?: "AND" | "OR"; field: - | "publicKey" - | "privateKey" | "createdAt" | "expiresAt" + | "privateKey" + | "publicKey" | "_id"; operator?: | "lt" @@ -293,10 +293,10 @@ export declare const components: { where?: Array<{ connector?: "AND" | "OR"; field: + | "createdAt" | "organizationId" - | "userId" | "role" - | "createdAt" + | "userId" | "_id"; operator?: | "lt" @@ -324,11 +324,11 @@ export declare const components: { where?: Array<{ connector?: "AND" | "OR"; field: - | "name" - | "slug" - | "logo" | "createdAt" + | "logo" | "metadata" + | "name" + | "slug" | "_id"; operator?: | "lt" @@ -356,15 +356,15 @@ export declare const components: { where?: Array<{ connector?: "AND" | "OR"; field: + | "activeOrganizationId" + | "createdAt" | "expiresAt" + | "impersonatedBy" + | "ipAddress" | "token" - | "createdAt" | "updatedAt" - | "ipAddress" | "userAgent" | "userId" - | "impersonatedBy" - | "activeOrganizationId" | "_id"; operator?: | "lt" @@ -392,17 +392,17 @@ export declare const components: { where?: Array<{ connector?: "AND" | "OR"; field: - | "name" + | "banExpires" + | "banReason" + | "banned" + | "createdAt" | "email" | "emailVerified" | "image" - | "createdAt" - | "updatedAt" | "isAnonymous" + | "name" | "role" - | "banned" - | "banReason" - | "banExpires" + | "updatedAt" | "userId" | "_id"; operator?: @@ -431,11 +431,11 @@ export declare const components: { where?: Array<{ connector?: "AND" | "OR"; field: - | "identifier" - | "value" - | "expiresAt" | "createdAt" + | "expiresAt" + | "identifier" | "updatedAt" + | "value" | "_id"; operator?: | "lt" @@ -480,18 +480,18 @@ export declare const components: { where?: Array<{ connector?: "AND" | "OR"; field: + | "accessToken" + | "accessTokenExpiresAt" | "accountId" + | "createdAt" + | "idToken" + | "password" | "providerId" - | "userId" - | "accessToken" | "refreshToken" - | "idToken" - | "accessTokenExpiresAt" | "refreshTokenExpiresAt" | "scope" - | "password" - | "createdAt" | "updatedAt" + | "userId" | "_id"; operator?: | "lt" @@ -519,13 +519,13 @@ export declare const components: { where?: Array<{ connector?: "AND" | "OR"; field: - | "organizationId" + | "createdAt" | "email" - | "role" - | "status" | "expiresAt" - | "createdAt" | "inviterId" + | "organizationId" + | "role" + | "status" | "_id"; operator?: | "lt" @@ -553,10 +553,10 @@ export declare const components: { where?: Array<{ connector?: "AND" | "OR"; field: - | "publicKey" - | "privateKey" | "createdAt" | "expiresAt" + | "privateKey" + | "publicKey" | "_id"; operator?: | "lt" @@ -584,10 +584,10 @@ export declare const components: { where?: Array<{ connector?: "AND" | "OR"; field: + | "createdAt" | "organizationId" - | "userId" | "role" - | "createdAt" + | "userId" | "_id"; operator?: | "lt" @@ -615,11 +615,11 @@ export declare const components: { where?: Array<{ connector?: "AND" | "OR"; field: - | "name" - | "slug" - | "logo" | "createdAt" + | "logo" | "metadata" + | "name" + | "slug" | "_id"; operator?: | "lt" @@ -647,15 +647,15 @@ export declare const components: { where?: Array<{ connector?: "AND" | "OR"; field: + | "activeOrganizationId" + | "createdAt" | "expiresAt" + | "impersonatedBy" + | "ipAddress" | "token" - | "createdAt" | "updatedAt" - | "ipAddress" | "userAgent" | "userId" - | "impersonatedBy" - | "activeOrganizationId" | "_id"; operator?: | "lt" @@ -683,17 +683,17 @@ export declare const components: { where?: Array<{ connector?: "AND" | "OR"; field: - | "name" + | "banExpires" + | "banReason" + | "banned" + | "createdAt" | "email" | "emailVerified" | "image" - | "createdAt" - | "updatedAt" | "isAnonymous" + | "name" | "role" - | "banned" - | "banReason" - | "banExpires" + | "updatedAt" | "userId" | "_id"; operator?: @@ -722,11 +722,11 @@ export declare const components: { where?: Array<{ connector?: "AND" | "OR"; field: - | "identifier" - | "value" - | "expiresAt" | "createdAt" + | "expiresAt" + | "identifier" | "updatedAt" + | "value" | "_id"; operator?: | "lt" @@ -869,18 +869,18 @@ export declare const components: { where?: Array<{ connector?: "AND" | "OR"; field: + | "accessToken" + | "accessTokenExpiresAt" | "accountId" + | "createdAt" + | "idToken" + | "password" | "providerId" - | "userId" - | "accessToken" | "refreshToken" - | "idToken" - | "accessTokenExpiresAt" | "refreshTokenExpiresAt" | "scope" - | "password" - | "createdAt" | "updatedAt" + | "userId" | "_id"; operator?: | "lt" @@ -917,13 +917,13 @@ export declare const components: { where?: Array<{ connector?: "AND" | "OR"; field: - | "organizationId" + | "createdAt" | "email" - | "role" - | "status" | "expiresAt" - | "createdAt" | "inviterId" + | "organizationId" + | "role" + | "status" | "_id"; operator?: | "lt" @@ -957,10 +957,10 @@ export declare const components: { where?: Array<{ connector?: "AND" | "OR"; field: - | "publicKey" - | "privateKey" | "createdAt" | "expiresAt" + | "privateKey" + | "publicKey" | "_id"; operator?: | "lt" @@ -994,10 +994,10 @@ export declare const components: { where?: Array<{ connector?: "AND" | "OR"; field: + | "createdAt" | "organizationId" - | "userId" | "role" - | "createdAt" + | "userId" | "_id"; operator?: | "lt" @@ -1032,11 +1032,11 @@ export declare const components: { where?: Array<{ connector?: "AND" | "OR"; field: - | "name" - | "slug" - | "logo" | "createdAt" + | "logo" | "metadata" + | "name" + | "slug" | "_id"; operator?: | "lt" @@ -1075,15 +1075,15 @@ export declare const components: { where?: Array<{ connector?: "AND" | "OR"; field: + | "activeOrganizationId" + | "createdAt" | "expiresAt" + | "impersonatedBy" + | "ipAddress" | "token" - | "createdAt" | "updatedAt" - | "ipAddress" | "userAgent" | "userId" - | "impersonatedBy" - | "activeOrganizationId" | "_id"; operator?: | "lt" @@ -1125,17 +1125,17 @@ export declare const components: { where?: Array<{ connector?: "AND" | "OR"; field: - | "name" + | "banExpires" + | "banReason" + | "banned" + | "createdAt" | "email" | "emailVerified" | "image" - | "createdAt" - | "updatedAt" | "isAnonymous" + | "name" | "role" - | "banned" - | "banReason" - | "banExpires" + | "updatedAt" | "userId" | "_id"; operator?: @@ -1171,11 +1171,11 @@ export declare const components: { where?: Array<{ connector?: "AND" | "OR"; field: - | "identifier" - | "value" - | "expiresAt" | "createdAt" + | "expiresAt" + | "identifier" | "updatedAt" + | "value" | "_id"; operator?: | "lt" @@ -1234,18 +1234,18 @@ export declare const components: { where?: Array<{ connector?: "AND" | "OR"; field: + | "accessToken" + | "accessTokenExpiresAt" | "accountId" + | "createdAt" + | "idToken" + | "password" | "providerId" - | "userId" - | "accessToken" | "refreshToken" - | "idToken" - | "accessTokenExpiresAt" | "refreshTokenExpiresAt" | "scope" - | "password" - | "createdAt" | "updatedAt" + | "userId" | "_id"; operator?: | "lt" @@ -1282,13 +1282,13 @@ export declare const components: { where?: Array<{ connector?: "AND" | "OR"; field: - | "organizationId" + | "createdAt" | "email" - | "role" - | "status" | "expiresAt" - | "createdAt" | "inviterId" + | "organizationId" + | "role" + | "status" | "_id"; operator?: | "lt" @@ -1322,10 +1322,10 @@ export declare const components: { where?: Array<{ connector?: "AND" | "OR"; field: - | "publicKey" - | "privateKey" | "createdAt" | "expiresAt" + | "privateKey" + | "publicKey" | "_id"; operator?: | "lt" @@ -1359,10 +1359,10 @@ export declare const components: { where?: Array<{ connector?: "AND" | "OR"; field: + | "createdAt" | "organizationId" - | "userId" | "role" - | "createdAt" + | "userId" | "_id"; operator?: | "lt" @@ -1397,11 +1397,11 @@ export declare const components: { where?: Array<{ connector?: "AND" | "OR"; field: - | "name" - | "slug" - | "logo" | "createdAt" + | "logo" | "metadata" + | "name" + | "slug" | "_id"; operator?: | "lt" @@ -1440,15 +1440,15 @@ export declare const components: { where?: Array<{ connector?: "AND" | "OR"; field: + | "activeOrganizationId" + | "createdAt" | "expiresAt" + | "impersonatedBy" + | "ipAddress" | "token" - | "createdAt" | "updatedAt" - | "ipAddress" | "userAgent" | "userId" - | "impersonatedBy" - | "activeOrganizationId" | "_id"; operator?: | "lt" @@ -1490,17 +1490,17 @@ export declare const components: { where?: Array<{ connector?: "AND" | "OR"; field: - | "name" + | "banExpires" + | "banReason" + | "banned" + | "createdAt" | "email" | "emailVerified" | "image" - | "createdAt" - | "updatedAt" | "isAnonymous" + | "name" | "role" - | "banned" - | "banReason" - | "banExpires" + | "updatedAt" | "userId" | "_id"; operator?: @@ -1536,11 +1536,11 @@ export declare const components: { where?: Array<{ connector?: "AND" | "OR"; field: - | "identifier" - | "value" - | "expiresAt" | "createdAt" + | "expiresAt" + | "identifier" | "updatedAt" + | "value" | "_id"; operator?: | "lt" diff --git a/packages/backend/src/functions/components/better-auth/_generated/component.ts b/packages/backend/src/functions/components/better-auth/_generated/component.ts index 4d095aea..3d6ba566 100644 --- a/packages/backend/src/functions/components/better-auth/_generated/component.ts +++ b/packages/backend/src/functions/components/better-auth/_generated/component.ts @@ -143,18 +143,18 @@ export type ComponentApi = where?: Array<{ connector?: "AND" | "OR"; field: + | "accessToken" + | "accessTokenExpiresAt" | "accountId" + | "createdAt" + | "idToken" + | "password" | "providerId" - | "userId" - | "accessToken" | "refreshToken" - | "idToken" - | "accessTokenExpiresAt" | "refreshTokenExpiresAt" | "scope" - | "password" - | "createdAt" | "updatedAt" + | "userId" | "_id"; operator?: | "lt" @@ -182,13 +182,13 @@ export type ComponentApi = where?: Array<{ connector?: "AND" | "OR"; field: - | "organizationId" + | "createdAt" | "email" - | "role" - | "status" | "expiresAt" - | "createdAt" | "inviterId" + | "organizationId" + | "role" + | "status" | "_id"; operator?: | "lt" @@ -216,10 +216,10 @@ export type ComponentApi = where?: Array<{ connector?: "AND" | "OR"; field: - | "publicKey" - | "privateKey" | "createdAt" | "expiresAt" + | "privateKey" + | "publicKey" | "_id"; operator?: | "lt" @@ -247,10 +247,10 @@ export type ComponentApi = where?: Array<{ connector?: "AND" | "OR"; field: + | "createdAt" | "organizationId" - | "userId" | "role" - | "createdAt" + | "userId" | "_id"; operator?: | "lt" @@ -278,11 +278,11 @@ export type ComponentApi = where?: Array<{ connector?: "AND" | "OR"; field: - | "name" - | "slug" - | "logo" | "createdAt" + | "logo" | "metadata" + | "name" + | "slug" | "_id"; operator?: | "lt" @@ -310,15 +310,15 @@ export type ComponentApi = where?: Array<{ connector?: "AND" | "OR"; field: + | "activeOrganizationId" + | "createdAt" | "expiresAt" + | "impersonatedBy" + | "ipAddress" | "token" - | "createdAt" | "updatedAt" - | "ipAddress" | "userAgent" | "userId" - | "impersonatedBy" - | "activeOrganizationId" | "_id"; operator?: | "lt" @@ -346,17 +346,17 @@ export type ComponentApi = where?: Array<{ connector?: "AND" | "OR"; field: - | "name" + | "banExpires" + | "banReason" + | "banned" + | "createdAt" | "email" | "emailVerified" | "image" - | "createdAt" - | "updatedAt" | "isAnonymous" + | "name" | "role" - | "banned" - | "banReason" - | "banExpires" + | "updatedAt" | "userId" | "_id"; operator?: @@ -385,11 +385,11 @@ export type ComponentApi = where?: Array<{ connector?: "AND" | "OR"; field: - | "identifier" - | "value" - | "expiresAt" | "createdAt" + | "expiresAt" + | "identifier" | "updatedAt" + | "value" | "_id"; operator?: | "lt" @@ -435,18 +435,18 @@ export type ComponentApi = where?: Array<{ connector?: "AND" | "OR"; field: + | "accessToken" + | "accessTokenExpiresAt" | "accountId" + | "createdAt" + | "idToken" + | "password" | "providerId" - | "userId" - | "accessToken" | "refreshToken" - | "idToken" - | "accessTokenExpiresAt" | "refreshTokenExpiresAt" | "scope" - | "password" - | "createdAt" | "updatedAt" + | "userId" | "_id"; operator?: | "lt" @@ -474,13 +474,13 @@ export type ComponentApi = where?: Array<{ connector?: "AND" | "OR"; field: - | "organizationId" + | "createdAt" | "email" - | "role" - | "status" | "expiresAt" - | "createdAt" | "inviterId" + | "organizationId" + | "role" + | "status" | "_id"; operator?: | "lt" @@ -508,10 +508,10 @@ export type ComponentApi = where?: Array<{ connector?: "AND" | "OR"; field: - | "publicKey" - | "privateKey" | "createdAt" | "expiresAt" + | "privateKey" + | "publicKey" | "_id"; operator?: | "lt" @@ -539,10 +539,10 @@ export type ComponentApi = where?: Array<{ connector?: "AND" | "OR"; field: + | "createdAt" | "organizationId" - | "userId" | "role" - | "createdAt" + | "userId" | "_id"; operator?: | "lt" @@ -570,11 +570,11 @@ export type ComponentApi = where?: Array<{ connector?: "AND" | "OR"; field: - | "name" - | "slug" - | "logo" | "createdAt" + | "logo" | "metadata" + | "name" + | "slug" | "_id"; operator?: | "lt" @@ -602,15 +602,15 @@ export type ComponentApi = where?: Array<{ connector?: "AND" | "OR"; field: + | "activeOrganizationId" + | "createdAt" | "expiresAt" + | "impersonatedBy" + | "ipAddress" | "token" - | "createdAt" | "updatedAt" - | "ipAddress" | "userAgent" | "userId" - | "impersonatedBy" - | "activeOrganizationId" | "_id"; operator?: | "lt" @@ -638,17 +638,17 @@ export type ComponentApi = where?: Array<{ connector?: "AND" | "OR"; field: - | "name" + | "banExpires" + | "banReason" + | "banned" + | "createdAt" | "email" | "emailVerified" | "image" - | "createdAt" - | "updatedAt" | "isAnonymous" + | "name" | "role" - | "banned" - | "banReason" - | "banExpires" + | "updatedAt" | "userId" | "_id"; operator?: @@ -677,11 +677,11 @@ export type ComponentApi = where?: Array<{ connector?: "AND" | "OR"; field: - | "identifier" - | "value" - | "expiresAt" | "createdAt" + | "expiresAt" + | "identifier" | "updatedAt" + | "value" | "_id"; operator?: | "lt" @@ -827,18 +827,18 @@ export type ComponentApi = where?: Array<{ connector?: "AND" | "OR"; field: + | "accessToken" + | "accessTokenExpiresAt" | "accountId" + | "createdAt" + | "idToken" + | "password" | "providerId" - | "userId" - | "accessToken" | "refreshToken" - | "idToken" - | "accessTokenExpiresAt" | "refreshTokenExpiresAt" | "scope" - | "password" - | "createdAt" | "updatedAt" + | "userId" | "_id"; operator?: | "lt" @@ -875,13 +875,13 @@ export type ComponentApi = where?: Array<{ connector?: "AND" | "OR"; field: - | "organizationId" + | "createdAt" | "email" - | "role" - | "status" | "expiresAt" - | "createdAt" | "inviterId" + | "organizationId" + | "role" + | "status" | "_id"; operator?: | "lt" @@ -915,10 +915,10 @@ export type ComponentApi = where?: Array<{ connector?: "AND" | "OR"; field: - | "publicKey" - | "privateKey" | "createdAt" | "expiresAt" + | "privateKey" + | "publicKey" | "_id"; operator?: | "lt" @@ -952,10 +952,10 @@ export type ComponentApi = where?: Array<{ connector?: "AND" | "OR"; field: + | "createdAt" | "organizationId" - | "userId" | "role" - | "createdAt" + | "userId" | "_id"; operator?: | "lt" @@ -990,11 +990,11 @@ export type ComponentApi = where?: Array<{ connector?: "AND" | "OR"; field: - | "name" - | "slug" - | "logo" | "createdAt" + | "logo" | "metadata" + | "name" + | "slug" | "_id"; operator?: | "lt" @@ -1033,15 +1033,15 @@ export type ComponentApi = where?: Array<{ connector?: "AND" | "OR"; field: + | "activeOrganizationId" + | "createdAt" | "expiresAt" + | "impersonatedBy" + | "ipAddress" | "token" - | "createdAt" | "updatedAt" - | "ipAddress" | "userAgent" | "userId" - | "impersonatedBy" - | "activeOrganizationId" | "_id"; operator?: | "lt" @@ -1083,17 +1083,17 @@ export type ComponentApi = where?: Array<{ connector?: "AND" | "OR"; field: - | "name" + | "banExpires" + | "banReason" + | "banned" + | "createdAt" | "email" | "emailVerified" | "image" - | "createdAt" - | "updatedAt" | "isAnonymous" + | "name" | "role" - | "banned" - | "banReason" - | "banExpires" + | "updatedAt" | "userId" | "_id"; operator?: @@ -1129,11 +1129,11 @@ export type ComponentApi = where?: Array<{ connector?: "AND" | "OR"; field: - | "identifier" - | "value" - | "expiresAt" | "createdAt" + | "expiresAt" + | "identifier" | "updatedAt" + | "value" | "_id"; operator?: | "lt" @@ -1193,18 +1193,18 @@ export type ComponentApi = where?: Array<{ connector?: "AND" | "OR"; field: + | "accessToken" + | "accessTokenExpiresAt" | "accountId" + | "createdAt" + | "idToken" + | "password" | "providerId" - | "userId" - | "accessToken" | "refreshToken" - | "idToken" - | "accessTokenExpiresAt" | "refreshTokenExpiresAt" | "scope" - | "password" - | "createdAt" | "updatedAt" + | "userId" | "_id"; operator?: | "lt" @@ -1241,13 +1241,13 @@ export type ComponentApi = where?: Array<{ connector?: "AND" | "OR"; field: - | "organizationId" + | "createdAt" | "email" - | "role" - | "status" | "expiresAt" - | "createdAt" | "inviterId" + | "organizationId" + | "role" + | "status" | "_id"; operator?: | "lt" @@ -1281,10 +1281,10 @@ export type ComponentApi = where?: Array<{ connector?: "AND" | "OR"; field: - | "publicKey" - | "privateKey" | "createdAt" | "expiresAt" + | "privateKey" + | "publicKey" | "_id"; operator?: | "lt" @@ -1318,10 +1318,10 @@ export type ComponentApi = where?: Array<{ connector?: "AND" | "OR"; field: + | "createdAt" | "organizationId" - | "userId" | "role" - | "createdAt" + | "userId" | "_id"; operator?: | "lt" @@ -1356,11 +1356,11 @@ export type ComponentApi = where?: Array<{ connector?: "AND" | "OR"; field: - | "name" - | "slug" - | "logo" | "createdAt" + | "logo" | "metadata" + | "name" + | "slug" | "_id"; operator?: | "lt" @@ -1399,15 +1399,15 @@ export type ComponentApi = where?: Array<{ connector?: "AND" | "OR"; field: + | "activeOrganizationId" + | "createdAt" | "expiresAt" + | "impersonatedBy" + | "ipAddress" | "token" - | "createdAt" | "updatedAt" - | "ipAddress" | "userAgent" | "userId" - | "impersonatedBy" - | "activeOrganizationId" | "_id"; operator?: | "lt" @@ -1449,17 +1449,17 @@ export type ComponentApi = where?: Array<{ connector?: "AND" | "OR"; field: - | "name" + | "banExpires" + | "banReason" + | "banned" + | "createdAt" | "email" | "emailVerified" | "image" - | "createdAt" - | "updatedAt" | "isAnonymous" + | "name" | "role" - | "banned" - | "banReason" - | "banExpires" + | "updatedAt" | "userId" | "_id"; operator?: @@ -1495,11 +1495,11 @@ export type ComponentApi = where?: Array<{ connector?: "AND" | "OR"; field: - | "identifier" - | "value" - | "expiresAt" | "createdAt" + | "expiresAt" + | "identifier" | "updatedAt" + | "value" | "_id"; operator?: | "lt" diff --git a/packages/backend/src/functions/components/better-auth/schema.generated.ts b/packages/backend/src/functions/components/better-auth/schema.generated.ts index 971250bb..3fd9b536 100644 --- a/packages/backend/src/functions/components/better-auth/schema.generated.ts +++ b/packages/backend/src/functions/components/better-auth/schema.generated.ts @@ -5,40 +5,39 @@ * * To customize the schema, generate to an alternate file and import * the table definitions to your schema file. See - * https://convex-better-auth.netlify.app/features/local-install#adding-custom-indexes. + * https://labs.convex.dev/better-auth/features/local-install#adding-custom-indexes. */ import { defineSchema, defineTable } from "convex/server" import { v } from "convex/values" -// eslint-disable sort-keys export const tables = { account: defineTable({ + accessToken: v.optional(v.union(v.null(), v.string())), + accessTokenExpiresAt: v.optional(v.union(v.null(), v.number())), accountId: v.string(), + createdAt: v.number(), + idToken: v.optional(v.union(v.null(), v.string())), + password: v.optional(v.union(v.null(), v.string())), providerId: v.string(), - userId: v.string(), - accessToken: v.optional(v.union(v.null(), v.string())), refreshToken: v.optional(v.union(v.null(), v.string())), - idToken: v.optional(v.union(v.null(), v.string())), - accessTokenExpiresAt: v.optional(v.union(v.null(), v.number())), refreshTokenExpiresAt: v.optional(v.union(v.null(), v.number())), scope: v.optional(v.union(v.null(), v.string())), - password: v.optional(v.union(v.null(), v.string())), - createdAt: v.number(), updatedAt: v.number(), + userId: v.string(), }) .index("accountId", ["accountId"]) .index("accountId_providerId", ["accountId", "providerId"]) .index("providerId_userId", ["providerId", "userId"]) .index("userId", ["userId"]), invitation: defineTable({ - organizationId: v.string(), + createdAt: v.number(), email: v.string(), - role: v.optional(v.union(v.null(), v.string())), - status: v.string(), expiresAt: v.number(), - createdAt: v.number(), inviterId: v.string(), + organizationId: v.string(), + role: v.optional(v.union(v.null(), v.string())), + status: v.string(), }) .index("organizationId", ["organizationId"]) .index("email", ["email"]) @@ -46,67 +45,67 @@ export const tables = { .index("status", ["status"]) .index("inviterId", ["inviterId"]), jwks: defineTable({ - publicKey: v.string(), - privateKey: v.string(), createdAt: v.number(), expiresAt: v.optional(v.union(v.null(), v.number())), + privateKey: v.string(), + publicKey: v.string(), }), member: defineTable({ + createdAt: v.number(), organizationId: v.string(), - userId: v.string(), role: v.string(), - createdAt: v.number(), + userId: v.string(), }) .index("organizationId", ["organizationId"]) .index("userId", ["userId"]) .index("role", ["role"]), organization: defineTable({ - name: v.string(), - slug: v.string(), - logo: v.optional(v.union(v.null(), v.string())), createdAt: v.number(), + logo: v.optional(v.union(v.null(), v.string())), metadata: v.optional(v.union(v.null(), v.string())), + name: v.string(), + slug: v.string(), }) .index("name", ["name"]) .index("slug", ["slug"]), session: defineTable({ + activeOrganizationId: v.optional(v.union(v.null(), v.string())), + createdAt: v.number(), expiresAt: v.number(), + impersonatedBy: v.optional(v.union(v.null(), v.string())), + ipAddress: v.optional(v.union(v.null(), v.string())), token: v.string(), - createdAt: v.number(), updatedAt: v.number(), - ipAddress: v.optional(v.union(v.null(), v.string())), userAgent: v.optional(v.union(v.null(), v.string())), userId: v.string(), - impersonatedBy: v.optional(v.union(v.null(), v.string())), - activeOrganizationId: v.optional(v.union(v.null(), v.string())), }) .index("expiresAt", ["expiresAt"]) .index("expiresAt_userId", ["expiresAt", "userId"]) .index("token", ["token"]) .index("userId", ["userId"]), user: defineTable({ - name: v.string(), + banExpires: v.optional(v.union(v.null(), v.number())), + banReason: v.optional(v.union(v.null(), v.string())), + banned: v.optional(v.union(v.null(), v.boolean())), + createdAt: v.number(), email: v.string(), emailVerified: v.boolean(), image: v.optional(v.union(v.null(), v.string())), - createdAt: v.number(), - updatedAt: v.number(), isAnonymous: v.optional(v.union(v.null(), v.boolean())), + name: v.string(), role: v.optional(v.union(v.null(), v.string())), - banned: v.optional(v.union(v.null(), v.boolean())), - banReason: v.optional(v.union(v.null(), v.string())), - banExpires: v.optional(v.union(v.null(), v.number())), + updatedAt: v.number(), userId: v.optional(v.union(v.null(), v.string())), }) .index("email_name", ["email", "name"]) .index("name", ["name"]) .index("userId", ["userId"]), verification: defineTable({ - identifier: v.string(), - value: v.string(), - expiresAt: v.number(), createdAt: v.number(), + expiresAt: v.number(), + identifier: v.string(), updatedAt: v.number(), + value: v.string(), }) .index("expiresAt", ["expiresAt"]) .index("identifier", ["identifier"]), diff --git a/packages/backend/src/functions/shared/auth.ts b/packages/backend/src/functions/shared/auth.ts index 65ca1d89..f6b790d4 100644 --- a/packages/backend/src/functions/shared/auth.ts +++ b/packages/backend/src/functions/shared/auth.ts @@ -2,8 +2,8 @@ import type { AuthFunctions, GenericCtx } from "@convex-dev/better-auth" import type { AuthOptions } from "@init/auth/server" import { createClient } from "@convex-dev/better-auth" import { convex } from "@convex-dev/better-auth/plugins" +import { AUTH_APP_NAME, AUTH_COOKIE_PREFIX } from "@init/auth/constants" import { admin, anonymous, organization } from "@init/auth/server/plugins" -import { APP_ID, APP_NAME } from "@init/utils/constants" import { seconds } from "qte" import type { DataModel } from "#functions/_generated/dataModel.js" import { components, internal } from "#functions/_generated/api.js" @@ -20,10 +20,10 @@ export const authComponent = createClient(componen export const createAuthOptions = (ctx: GenericCtx) => ({ advanced: { - cookiePrefix: APP_ID, + cookiePrefix: AUTH_COOKIE_PREFIX, database: { generateId: false }, }, - appName: APP_NAME, + appName: AUTH_APP_NAME, database: authComponent.adapter(ctx), emailAndPassword: { autoSignIn: true, diff --git a/packages/utils/package.json b/packages/utils/package.json index 10ef3fda..bd26dd35 100644 --- a/packages/utils/package.json +++ b/packages/utils/package.json @@ -7,8 +7,7 @@ "#*": "./src/*" }, "exports": { - "./*": "./src/*.ts", - "./constants": "./src/constants/index.ts" + "./*": "./src/*.ts" }, "scripts": { "clean": "git clean -xdf .cache .turbo dist node_modules", diff --git a/packages/utils/src/constants/app.ts b/packages/utils/src/constants/app.ts deleted file mode 100644 index 838f7ebd..00000000 --- a/packages/utils/src/constants/app.ts +++ /dev/null @@ -1,2 +0,0 @@ -export const APP_NAME = "Init" -export const APP_ID = "init" diff --git a/packages/utils/src/constants/index.ts b/packages/utils/src/constants/index.ts deleted file mode 100644 index c62b73c4..00000000 --- a/packages/utils/src/constants/index.ts +++ /dev/null @@ -1 +0,0 @@ -export * from "#constants/app.ts"