@shivaedev/identity 0.23.0 → 0.23.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.23.1 - 2026-11-04
4
+
5
+ ### Changed
6
+
7
+ - Support externally migrated Better Auth tables as a transition to identity's frozen auth migrations. Run `assertBetterAuthSchema` before `betterAuthMount` at startup to refuse schema drift with typed diagnostics naming missing tables or columns.
8
+
3
9
  ## 0.23.0 - 2026-11-04
4
10
 
5
11
  ### Added
package/README.md CHANGED
@@ -148,7 +148,7 @@ const authentication = Effect.gen(function* () {
148
148
  });
149
149
  ```
150
150
 
151
- `betterAuthDatabase()` reads the application’s `SqlClient` and reserves connections from its PostgreSQL pool. Build it inside `appHost`’s `application` Effect, or provide sql’s `postgresLayer` for a standalone process. Set `maxConnections` and `applicationName` on the application SQL Layer. Generate frozen numbered auth migrations as described below. The application SQL Layer owns shutdown.
151
+ `betterAuthDatabase()` reads the application’s `SqlClient` and reserves connections from its PostgreSQL pool. Build it inside `appHost`’s `application` Effect, or provide sql’s `postgresLayer` for a standalone process. Set `maxConnections` and `applicationName` on the application SQL Layer. The mount does not run migrations or require identity's migration history. Use frozen numbered auth migrations as described below, or keep an existing migrator during the transition described in [Auth tables owned by another migrator](#auth-tables-owned-by-another-migrator). The application SQL Layer owns shutdown.
152
152
 
153
153
  The adapter captures the SQL transaction at creation. An adapter created at startup does not join a later `transact` around an `auth.api` call: its auth writes commit independently and survive the application's rollback. For a shared boundary, create the adapter inside `transact`, and use it only within that transaction. Create the mount there too when its Effect hooks must share the application transaction:
154
154
 
@@ -579,6 +579,35 @@ The failure's `_tag` remains `AuthFailure`; its `code` union includes the declar
579
579
 
580
580
  React's `authAction`, `authQuery` and `authSession` consume these Effects to create atoms. See [React's Better Auth usage](https://github.com/ShivaeDev/platform/blob/main/packages/react/README.md#better-auth-actions).
581
581
 
582
+ ### Auth tables owned by another migrator
583
+
584
+ An application moving from Prisma can keep Prisma in charge of its auth tables while adopting identity's mount. Apply the existing migrator first, then run `assertBetterAuthSchema` as a startup guard before `betterAuthMount`. Both use the same application `SqlClient`; keep Better Auth's table and field mappings aligned with the existing schema.
585
+
586
+ ```ts
587
+ import { Effect } from "effect";
588
+ import { assertBetterAuthSchema } from "@shivaedev/identity/server/better-auth/adapters/assertSchema.ts";
589
+ import { betterAuthDatabase } from "@shivaedev/identity/server/better-auth/adapters/database.ts";
590
+ import { betterAuthMount } from "@shivaedev/identity/server/better-auth/adapters/mount.ts";
591
+
592
+ const authOptions = {
593
+ account: { modelName: "Account" },
594
+ emailAndPassword: { enabled: true },
595
+ session: { modelName: "Session" },
596
+ user: { modelName: "User" },
597
+ verification: { modelName: "Verification" },
598
+ };
599
+
600
+ const authentication = Effect.gen(function* () {
601
+ yield* assertBetterAuthSchema(authOptions);
602
+ const database = yield* betterAuthDatabase();
603
+ return yield* betterAuthMount({ ...authOptions, database });
604
+ });
605
+ ```
606
+
607
+ Provide the SQL Layer and `memoryStore`, and supply the secret as for any mount. The guard fails in the Effect error channel with `BetterAuthSchemaDrift` from the assertion module; its `missing` array names missing tables and columns, such as `column User.emailVerified`. This failure stops acquisition before the mount starts, preserving the actionable schema diagnostic instead of the provider's generic `AuthUnavailable`. Extra application columns can stay in the auth tables. The mount reads existing sessions without changing the schema or taking over its migrations.
608
+
609
+ This is a migration step towards identity's frozen auth migrations. While Prisma owns the tables, make schema corrections in Prisma. When ownership moves, preserve the existing schema baseline in the application's migration history and use the frozen workflow below for subsequent auth changes. Generate each addition against a disposable database with the previously shipped schema applied, and register it with the application's numbered SQL migrations. Keep one migrator responsible for each auth schema change.
610
+
582
611
  ### Frozen auth migrations
583
612
 
584
613
  Generate each auth migration once, review its SQL and commit the generated module. `generateBetterAuthMigration(options, roleOptions?)` reads the current PostgreSQL schema through `SqlClient` and returns a TypeScript migration module. It does not apply the migration. The module imports only native Effect and executes fixed SQL on the migrator's transaction connection. Later auth option changes and Better Auth upgrades cannot change its SQL.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@shivaedev/identity",
3
- "version": "0.23.0",
3
+ "version": "0.23.1",
4
4
  "description": "Request identity, sessions, transport trust and permission enforcement for Effect RPC servers",
5
5
  "keywords": [
6
6
  "effect"
@@ -47,7 +47,7 @@
47
47
  "dependencies": {
48
48
  "@shivaedev/access": "0.4.2",
49
49
  "@shivaedev/changes": "0.9.0",
50
- "@shivaedev/contract": "0.34.0",
50
+ "@shivaedev/contract": "0.35.0",
51
51
  "@shivaedev/errors": "0.8.0",
52
52
  "@shivaedev/rate-limit": "0.3.3",
53
53
  "@shivaedev/sql": "0.36.1"
@@ -56,12 +56,12 @@
56
56
  "@better-auth/oauth-provider": "1.7.14",
57
57
  "@effect/platform-node": "4.0.6",
58
58
  "@effect/sql-pg": "4.0.6",
59
- "@shivaedev/admin": "0.19.4",
60
- "@shivaedev/quality": "0.58.0",
61
- "@shivaedev/server": "0.22.0",
62
- "@shivaedev/test-kits": "0.2.1",
63
- "@shivaedev/test-sql": "0.18.2",
64
- "@shivaedev/test-story": "0.37.0",
59
+ "@shivaedev/admin": "0.19.5",
60
+ "@shivaedev/quality": "0.59.0",
61
+ "@shivaedev/server": "0.23.0",
62
+ "@shivaedev/test-kits": "0.2.2",
63
+ "@shivaedev/test-sql": "0.19.0",
64
+ "@shivaedev/test-story": "0.37.1",
65
65
  "@types/node": "24.19.2",
66
66
  "better-auth": "1.7.14",
67
67
  "effect": "4.0.6",