@shivaedev/identity 0.41.0 → 0.42.0
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 +10 -0
- package/README.md +36 -1
- package/dist/Account.d.ts +17 -0
- package/dist/Account.d.ts.map +1 -0
- package/dist/Account.js +19 -0
- package/dist/Account.js.map +1 -0
- package/dist/generated/Account.d.ts +26 -0
- package/dist/generated/Account.d.ts.map +1 -0
- package/dist/generated/Account.js +18 -0
- package/dist/generated/Account.js.map +1 -0
- package/dist/server/AccountDeletion.d.ts +11 -0
- package/dist/server/AccountDeletion.d.ts.map +1 -0
- package/dist/server/AccountDeletion.js +5 -0
- package/dist/server/AccountDeletion.js.map +1 -0
- package/dist/server/better-auth/AccountDeletionPolicy.d.ts +10 -0
- package/dist/server/better-auth/AccountDeletionPolicy.d.ts.map +1 -0
- package/dist/server/better-auth/AccountDeletionPolicy.js +4 -0
- package/dist/server/better-auth/AccountDeletionPolicy.js.map +1 -0
- package/dist/server/better-auth/accountDeletion.d.ts +13 -0
- package/dist/server/better-auth/accountDeletion.d.ts.map +1 -0
- package/dist/server/better-auth/accountDeletion.js +22 -0
- package/dist/server/better-auth/accountDeletion.js.map +1 -0
- package/dist/server/better-auth/adapters/passwordMatches.d.ts +4 -0
- package/dist/server/better-auth/adapters/passwordMatches.d.ts.map +1 -0
- package/dist/server/better-auth/adapters/passwordMatches.js +9 -0
- package/dist/server/better-auth/adapters/passwordMatches.js.map +1 -0
- package/dist/server/better-auth/closeAccountDeletion.d.ts +3 -0
- package/dist/server/better-auth/closeAccountDeletion.d.ts.map +1 -0
- package/dist/server/better-auth/closeAccountDeletion.js +5 -0
- package/dist/server/better-auth/closeAccountDeletion.js.map +1 -0
- package/dist/server/better-auth/confirmPassword.d.ts +7 -0
- package/dist/server/better-auth/confirmPassword.d.ts.map +1 -0
- package/dist/server/better-auth/confirmPassword.js +34 -0
- package/dist/server/better-auth/confirmPassword.js.map +1 -0
- package/dist/server/better-auth/deleteAccount.d.ts +5 -0
- package/dist/server/better-auth/deleteAccount.d.ts.map +1 -0
- package/dist/server/better-auth/deleteAccount.js +25 -0
- package/dist/server/better-auth/deleteAccount.js.map +1 -0
- package/dist/server/better-auth/deleteUserRows.d.ts +6 -0
- package/dist/server/better-auth/deleteUserRows.d.ts.map +1 -0
- package/dist/server/better-auth/deleteUserRows.js +20 -0
- package/dist/server/better-auth/deleteUserRows.js.map +1 -0
- package/dist/server/better-auth/mount.d.ts.map +1 -1
- package/dist/server/better-auth/mount.js +3 -1
- package/dist/server/better-auth/mount.js.map +1 -1
- package/package.json +5 -5
- package/src/Account.ts +20 -0
- package/src/generated/Account.ts +23 -0
- package/src/server/AccountDeletion.ts +14 -0
- package/src/server/better-auth/AccountDeletionPolicy.ts +10 -0
- package/src/server/better-auth/accountDeletion.ts +41 -0
- package/src/server/better-auth/adapters/passwordMatches.ts +10 -0
- package/src/server/better-auth/closeAccountDeletion.ts +6 -0
- package/src/server/better-auth/confirmPassword.ts +37 -0
- package/src/server/better-auth/deleteAccount.ts +25 -0
- package/src/server/better-auth/deleteUserRows.ts +21 -0
- package/src/server/better-auth/mount.ts +3 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,15 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.42.0 - 2026-11-21
|
|
4
|
+
|
|
5
|
+
### Added
|
|
6
|
+
|
|
7
|
+
- `Account` from `@shivaedev/identity/Account.ts` deletes the signed-in person's account through its `identity.account.delete({ password })` command. It confirms the current password with the declaration's configured verifier, then runs the application's hand-over, erases the person's owned rows and deletes their auth rows in one transaction, so a failure anywhere leaves them able to sign in with every row in place. Register it as `module: Account` with `services: accountDeletion(AppAuth)` from `@shivaedev/identity/server/better-auth/accountDeletion.ts`; an application that hands rows over to other people passes its hand-over service, written with `defineService` and providing `handOver(userId)`, as `accountDeletion(AppAuth, { handOver: HandOver })` and provides `HandOver.layer`. Browser code imports the client contract from `@shivaedev/identity/generated/Account.ts`.
|
|
8
|
+
|
|
9
|
+
### Breaking
|
|
10
|
+
|
|
11
|
+
- The mount closes Better Auth's `/delete-user` and `/delete-user/callback`, even when the options enable `user.deleteUser`, and the admin plugin's `/admin/remove-user`. An application that deleted accounts through `/delete-user` with a `user.delete.before` hook moves the hook's body into a hand-over service's `handOver(userId)` operation, passes that service to `accountDeletion`, registers the `Account` module and calls `identity.account.delete({ password })` from its client instead of Better Auth's `deleteUser`. An application that removed users through `/admin/remove-user` has no HTTP route for it any more; the person deletes their own account with the command.
|
|
12
|
+
|
|
3
13
|
## 0.41.0 - 2026-11-21
|
|
4
14
|
|
|
5
15
|
### Breaking
|
package/README.md
CHANGED
|
@@ -1081,7 +1081,7 @@ const eraseOwnedRows = data.eraseOwnedRows;
|
|
|
1081
1081
|
|
|
1082
1082
|
`exportAccount(userId)` returns `{ account, owned }`. `account` holds the person's profile fields, linked-account identifiers and session metadata from Better Auth's tables, with timestamps as native Effect UTC values; passwords, access tokens, refresh tokens and session tokens are left out by explicit field selection. `owned` holds one `{ table, rows }` entry per owned model, ordered by table, with every row whose owner field holds the user id, encoded through the model's `json` variant. A field without a JSON variant, such as a `serverOnly` field, is never read, so it cannot reach the export. A table with none of the person's rows keeps its empty entry. Identity's own account preferences are an owned model too.
|
|
1083
1083
|
|
|
1084
|
-
`eraseOwnedRows(userId)` deletes every owned row of the person. It reads PostgreSQL's foreign keys between the owned tables and deletes the rows that reference a table before the rows they reference, so `RESTRICT` and `NO ACTION` keys between owned tables need no hand-kept order. It opens no transaction of its own: run it inside the caller's `transact` from `@shivaedev/sql/transact.ts`, and a failure anywhere in that transaction leaves every row in place. When `RESTRICT` or `NO ACTION` keys between owned tables form a cycle, it fails with `OwnedTableCycle` from `server/account-data/OwnedTableCycle.ts`, naming the tables as `schema.table`, before it deletes anything. It erases owned rows only; the auth user and Better Auth's own tables stay for the account deletion that runs after it.
|
|
1084
|
+
`eraseOwnedRows(userId)` deletes every owned row of the person. It reads PostgreSQL's foreign keys between the owned tables and deletes the rows that reference a table before the rows they reference, so `RESTRICT` and `NO ACTION` keys between owned tables need no hand-kept order. It opens no transaction of its own: run it inside the caller's `transact` from `@shivaedev/sql/transact.ts`, and a failure anywhere in that transaction leaves every row in place. When `RESTRICT` or `NO ACTION` keys between owned tables form a cycle, it fails with `OwnedTableCycle` from `server/account-data/OwnedTableCycle.ts`, naming the tables as `schema.table`, before it deletes anything. It erases owned rows only; the auth user and Better Auth's own tables stay for the [account deletion](#delete-an-account) that runs after it.
|
|
1085
1085
|
|
|
1086
1086
|
`check` fails with `UncoveredUserColumns` from `server/account-data/UncoveredUserColumns.ts` when a column refers to the person but nothing covers it. A column refers to the person when its foreign key points at the auth user's id or at an owned model's owner column. It is covered when it is an owned model's owner column, when its foreign key is `ON DELETE SET NULL` (such a row, an authored-by row for example, is not the person's: it stays without them and is not in their export), or when it belongs to one of Better Auth's tables. The error's `columns` names each `{ schema, table, column }` once, from every schema. `exportAccount` and `eraseOwnedRows` run the check first, so a new column whose foreign key points directly at the person, or at an owned model's owner column, fails them until an owner mark or a `SET NULL` key covers it. Run `check` against the migrated database in a startup check or a PostgreSQL story too, after the application's repositories are built under `collectRepositoryModels` from `@shivaedev/sql/RepositoryModels.ts`; `appHost` provides that collector, so an operation it serves sees every owned model.
|
|
1087
1087
|
|
|
@@ -1095,6 +1095,38 @@ Outside a host, a job or script must provide `collectRepositoryModels` itself an
|
|
|
1095
1095
|
|
|
1096
1096
|
PostgreSQL sees only foreign keys, so a table whose owner column has none is covered by its owner mark alone, and a table the application reaches only through raw SQL needs a repository on a model with an owner mark to be exported and erased. The user reference is the auth declaration's user table, so a customized `user.modelName` needs nothing more, and its `id` column in the `public` schema; when the user's id lives elsewhere, pass that `{ schema, table, column }` as the second argument to `accountData`. The account handler supplies the authorized user's id; these server APIs do not authenticate callers.
|
|
1097
1097
|
|
|
1098
|
+
### Delete an account
|
|
1099
|
+
|
|
1100
|
+
`Account` from `@shivaedev/identity/Account.ts` is a defined module, which is server code: register it as `module: Account` with `services: accountDeletion(AppAuth)`, using `accountDeletion` from `@shivaedev/identity/server/better-auth/accountDeletion.ts`. Its `identity.account.delete({ password })` command deletes the signed-in person's account; it needs the `AuthenticatedUser` middleware, the application's `SqlClient` and `Reactivity`, which `appHost` provides, and the owned models the host collects. Browser code imports the client contract under the same name from `@shivaedev/identity/generated/Account.ts`; give the command to a form hook such as React's `useCreate`, so a refused password shows on the password field.
|
|
1101
|
+
|
|
1102
|
+
The command runs these steps in order:
|
|
1103
|
+
|
|
1104
|
+
1. It checks the person's current password with the verifier the declaration's options configure, Better Auth's own unless `emailAndPassword.password.verify` replaces it. A missing, overlong or wrong password is refused with `BadRequest` on the `password` field, and an account without a credential password with `PreconditionFailed`; nothing is deleted.
|
|
1105
|
+
2. One `transact` runs the application's hand-over, then [`eraseOwnedRows`](#export-and-erase-a-persons-data), then deletes the person's auth rows: the user row, whose `ON DELETE CASCADE` keys remove their sessions and sign-in accounts, and the verification rows Better Auth writes for them. Those are the rows whose value is their id, such as a password-reset token, the `email-verification`, `sign-in` and `forget-password` codes of their exact address, and the change-email and two-factor codes that start with their id.
|
|
1106
|
+
3. On commit it announces `userKeys` and `sessionKeys`, so live readers refresh. The person's next session check answers signed out, which makes a remembered session forget itself, and their next protected request is refused with `Unauthorized`.
|
|
1107
|
+
|
|
1108
|
+
The hand-over is the application's policy for rows that other people keep, such as a shared household that passes to another member. It is an application service written with `defineService` whose `handOver(userId)` operation yields its own dependencies; pass its tag to `accountDeletion` and provide its Layer, and leave both out when nothing is handed over. The deletion calls it inside its transaction, so its writes commit or roll back with the rest:
|
|
1109
|
+
|
|
1110
|
+
```ts
|
|
1111
|
+
import { Layer } from "effect";
|
|
1112
|
+
import { Account } from "@shivaedev/identity/Account.ts";
|
|
1113
|
+
import { accountDeletion } from "@shivaedev/identity/server/better-auth/accountDeletion.ts";
|
|
1114
|
+
import type { AppModule } from "@shivaedev/server/AppModule.ts";
|
|
1115
|
+
import { AppAuth } from "#server/AppAuth.ts";
|
|
1116
|
+
import { HouseholdHandOver } from "#server/households/handOver/service.ts";
|
|
1117
|
+
|
|
1118
|
+
export const accountRegistration = {
|
|
1119
|
+
module: Account,
|
|
1120
|
+
services: accountDeletion(AppAuth, { handOver: HouseholdHandOver }).pipe(Layer.provide(HouseholdHandOver.layer)),
|
|
1121
|
+
} satisfies AppModule;
|
|
1122
|
+
```
|
|
1123
|
+
|
|
1124
|
+
A failing hand-over, a failing erase or a failing auth delete rolls everything back: the person keeps every row and still signs in with the same password. The command answers `InternalServerError` and the host reports the cause, because these failures are the application's to fix rather than the person's.
|
|
1125
|
+
|
|
1126
|
+
The mount closes Better Auth's `/delete-user` and `/delete-user/callback`, even when the options enable `user.deleteUser`, and the admin plugin's `/admin/remove-user`, so this command is the one HTTP route that deletes an account. Better Auth deletes outside any transaction and erases no owned rows, and its `user.delete.before` hooks do not run here: move such a hook's body into the hand-over. Server code that calls Better Auth's `auth.api` directly is not covered by the closed routes.
|
|
1127
|
+
|
|
1128
|
+
The deletion reads and writes Better Auth's tables through the application's SQL client. It removes database sessions only; sessions kept in a cookie cache or secondary storage stay valid until they expire. Accounts that sign in only through a provider have no password to confirm with and are refused.
|
|
1129
|
+
|
|
1098
1130
|
### Signed-in story preconditions
|
|
1099
1131
|
|
|
1100
1132
|
A feature story starts signed in with `mintUser` from `@shivaedev/test-kits/identity/adapters/betterAuth.ts`. It reads the application's auth declaration, so the minted user lives under the same options and roles as production:
|
|
@@ -1234,6 +1266,9 @@ Import the module that defines the name; there is no package-root entry. Paths b
|
|
|
1234
1266
|
| `server/better-auth/adapters/revokeUnadmitted.ts` | `RevokedSessions`: the `{ users, sessions }` counts of a revocation. |
|
|
1235
1267
|
| `server/better-auth/userProfiles.ts` | Public profile lookups for other users. |
|
|
1236
1268
|
| `server/better-auth/sweepExpiredSessions.ts` | `sweepExpiredSessions`: delete expired sessions through the application's SQL client and return the number removed. |
|
|
1269
|
+
| `Account.ts` | `Account`: the defined module whose `delete` command deletes the signed-in person's account after confirming their password. |
|
|
1270
|
+
| `server/AccountDeletion.ts` | `AccountDeletion`: the port the account module's `delete` command calls. |
|
|
1271
|
+
| `server/better-auth/accountDeletion.ts` | `accountDeletion(declaration, { handOver? })`, `AccountHandOver`: the Better Auth `AccountDeletion` Layer and the shape of the application's hand-over service. |
|
|
1237
1272
|
| `server/better-auth/accountData.ts` | `accountData(declaration, reference?)`, returning `{ check, exportAccount, eraseOwnedRows }`: a person's account export, owned-row erasure and the coverage check, from the owned models the host reports. |
|
|
1238
1273
|
| `server/account-data/UncoveredUserColumns.ts` | `UncoveredUserColumns`: the coverage failure naming each column that refers to a person without an owned model to cover it. |
|
|
1239
1274
|
| `server/account-data/OwnedModelsUncollected.ts` | `OwnedModelsUncollected`: the failure of export, erase and check when no collector records the owned models. |
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { Schema } from "effect";
|
|
2
|
+
import { AuthenticatedUser } from "#middleware.ts";
|
|
3
|
+
import { AccountDeletion } from "#server/AccountDeletion.ts";
|
|
4
|
+
export declare const Account: import("@shivaedev/contract/defineModule.ts").Module<"identity.account", readonly [import("@shivaedev/contract/servedOperation.ts").ServedCommand<"delete", Schema.Struct<{
|
|
5
|
+
password: Schema.String;
|
|
6
|
+
}>, Schema.Void, {
|
|
7
|
+
readonly InternalServerError: typeof import("@shivaedev/errors/taxonomy.ts").InternalServerError;
|
|
8
|
+
readonly ServiceUnavailable: typeof import("@shivaedev/errors/taxonomy.ts").ServiceUnavailable;
|
|
9
|
+
readonly AuthUnavailable: typeof import("@shivaedev/errors/taxonomy.ts").AuthUnavailable;
|
|
10
|
+
readonly BadRequest: typeof import("@shivaedev/errors/taxonomy.ts").BadRequest;
|
|
11
|
+
readonly PreconditionFailed: typeof import("@shivaedev/errors/taxonomy.ts").PreconditionFailed;
|
|
12
|
+
}, import("effect/Effect").Effect<void, import("@shivaedev/errors/taxonomy.ts").AuthUnavailable | import("@shivaedev/errors/taxonomy.ts").BadRequest | import("@shivaedev/errors/taxonomy.ts").PreconditionFailed | Schema.SchemaError | import("effect/sql/SqlError").SqlError, AccountDeletion | import("./identity.ts").SessionUser>>] & readonly import("@shivaedev/contract/defineModule.ts").ModuleOperation[], import("@shivaedev/contract/moduleProof.ts").ModuleRequirements<readonly [import("@shivaedev/contract/servedOperation.ts").ServedCommandOf<"delete", {
|
|
13
|
+
password: Schema.String;
|
|
14
|
+
}, import("effect/Effect").Effect<void, import("@shivaedev/errors/taxonomy.ts").AuthUnavailable | import("@shivaedev/errors/taxonomy.ts").BadRequest | import("@shivaedev/errors/taxonomy.ts").PreconditionFailed | Schema.SchemaError | import("effect/sql/SqlError").SqlError, import("./identity.ts").SessionUser> | import("effect/Effect").Effect<{
|
|
15
|
+
readonly delete: (password: string) => import("effect/Effect").Effect<void, import("@shivaedev/errors/taxonomy.ts").AuthUnavailable | import("@shivaedev/errors/taxonomy.ts").BadRequest | import("@shivaedev/errors/taxonomy.ts").PreconditionFailed | Schema.SchemaError | import("effect/sql/SqlError").SqlError, import("./identity.ts").SessionUser>;
|
|
16
|
+
}, never, AccountDeletion>, void>], typeof AuthenticatedUser, undefined>, typeof AuthenticatedUser, undefined, undefined>;
|
|
17
|
+
//# sourceMappingURL=Account.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Account.d.ts","sourceRoot":"","sources":["../src/Account.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAIhC,OAAO,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AACnD,OAAO,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAC;AAS7D,eAAO,MAAM,OAAO;;;;;;;;;;;;yHAKlB,CAAC"}
|
package/dist/Account.js
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { Schema } from "effect";
|
|
2
|
+
import { defineModule } from "@shivaedev/contract/defineModule.ts";
|
|
3
|
+
import { command } from "@shivaedev/contract/operation.ts";
|
|
4
|
+
import { identityAccountWire } from "#generated/Account.ts";
|
|
5
|
+
import { AuthenticatedUser } from "#middleware.ts";
|
|
6
|
+
import { AccountDeletion } from "#server/AccountDeletion.ts";
|
|
7
|
+
const DeleteAccount = command("delete", {
|
|
8
|
+
payload: { password: Schema.String },
|
|
9
|
+
*run({ password }) {
|
|
10
|
+
yield* (yield* AccountDeletion).delete(password);
|
|
11
|
+
},
|
|
12
|
+
});
|
|
13
|
+
export const Account = defineModule({
|
|
14
|
+
middleware: AuthenticatedUser,
|
|
15
|
+
name: "identity.account",
|
|
16
|
+
operations: [DeleteAccount],
|
|
17
|
+
wire: identityAccountWire,
|
|
18
|
+
});
|
|
19
|
+
//# sourceMappingURL=Account.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Account.js","sourceRoot":"","sources":["../src/Account.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAChC,OAAO,EAAE,YAAY,EAAE,MAAM,qCAAqC,CAAC;AACnE,OAAO,EAAE,OAAO,EAAE,MAAM,kCAAkC,CAAC;AAC3D,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAC5D,OAAO,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AACnD,OAAO,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAC;AAE7D,MAAM,aAAa,GAAG,OAAO,CAAC,QAAQ,EAAE;IACvC,OAAO,EAAE,EAAE,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE;IACpC,CAAC,GAAG,CAAC,EAAE,QAAQ,EAAE;QAChB,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,eAAe,CAAC,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;IAClD,CAAC;CACD,CAAC,CAAC;AAEH,MAAM,CAAC,MAAM,OAAO,GAAG,YAAY,CAAC;IACnC,UAAU,EAAE,iBAAiB;IAC7B,IAAI,EAAE,kBAAkB;IACxB,UAAU,EAAE,CAAC,aAAa,CAAC;IAC3B,IAAI,EAAE,mBAAmB;CACzB,CAAC,CAAC"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { Account as AccountModule } from "#Account.ts";
|
|
2
|
+
import { AuthenticatedUser } from "#middleware.ts";
|
|
3
|
+
import type { ClientMatchesModule } from "@shivaedev/contract/clientMatchesModule.ts";
|
|
4
|
+
import { AuthUnavailable, BadRequest, PreconditionFailed } from "@shivaedev/errors/taxonomy.ts";
|
|
5
|
+
import { Schema } from "effect";
|
|
6
|
+
export declare const identityAccountWire: {
|
|
7
|
+
readonly delete: {
|
|
8
|
+
readonly rejections: {
|
|
9
|
+
readonly AuthUnavailable: typeof AuthUnavailable;
|
|
10
|
+
readonly BadRequest: typeof BadRequest;
|
|
11
|
+
readonly PreconditionFailed: typeof PreconditionFailed;
|
|
12
|
+
};
|
|
13
|
+
readonly success: Schema.Void;
|
|
14
|
+
};
|
|
15
|
+
};
|
|
16
|
+
export declare const Account: import("@shivaedev/contract/defineModule.ts").ModuleContract<"identity.account", readonly import("@shivaedev/contract/operation.ts").Command<"delete", Schema.Struct<{
|
|
17
|
+
readonly password: Schema.String;
|
|
18
|
+
}>, Schema.Void, {
|
|
19
|
+
readonly InternalServerError: typeof import("@shivaedev/errors/taxonomy.ts").InternalServerError;
|
|
20
|
+
readonly ServiceUnavailable: typeof import("@shivaedev/errors/taxonomy.ts").ServiceUnavailable;
|
|
21
|
+
readonly AuthUnavailable: typeof AuthUnavailable;
|
|
22
|
+
readonly BadRequest: typeof BadRequest;
|
|
23
|
+
readonly PreconditionFailed: typeof PreconditionFailed;
|
|
24
|
+
}>[], typeof AuthenticatedUser, undefined, undefined>;
|
|
25
|
+
export declare const identityAccountMatchModule: ClientMatchesModule<typeof Account, typeof AccountModule>;
|
|
26
|
+
//# sourceMappingURL=Account.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Account.d.ts","sourceRoot":"","sources":["../../src/generated/Account.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,OAAO,IAAI,aAAa,EAAE,MAAM,aAAa,CAAC;AAC5D,OAAO,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AAEnD,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,4CAA4C,CAAC;AACtF,OAAO,EAAE,eAAe,EAAE,UAAU,EAAE,kBAAkB,EAAE,MAAM,+BAA+B,CAAC;AAChG,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAEhC,eAAO,MAAM,mBAAmB;;;;;;;;;CAEtB,CAAC;AAEX,eAAO,MAAM,OAAO;;;;;;;;qDAQlB,CAAC;AAEH,eAAO,MAAM,0BAA0B,EAAE,mBAAmB,CAAC,OAAO,OAAO,EAAE,OAAO,aAAa,CAAQ,CAAC"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { AuthenticatedUser } from "#middleware.ts";
|
|
2
|
+
import { clientContract } from "@shivaedev/contract/clientContract.ts";
|
|
3
|
+
import { AuthUnavailable, BadRequest, PreconditionFailed } from "@shivaedev/errors/taxonomy.ts";
|
|
4
|
+
import { Schema } from "effect";
|
|
5
|
+
export const identityAccountWire = {
|
|
6
|
+
delete: { rejections: { AuthUnavailable, BadRequest, PreconditionFailed }, success: Schema.Void },
|
|
7
|
+
};
|
|
8
|
+
export const Account = clientContract({
|
|
9
|
+
commands: ["delete"],
|
|
10
|
+
middleware: AuthenticatedUser,
|
|
11
|
+
name: "identity.account",
|
|
12
|
+
payloads: {
|
|
13
|
+
delete: { password: Schema.String },
|
|
14
|
+
},
|
|
15
|
+
wire: identityAccountWire,
|
|
16
|
+
});
|
|
17
|
+
export const identityAccountMatchModule = true;
|
|
18
|
+
//# sourceMappingURL=Account.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Account.js","sourceRoot":"","sources":["../../src/generated/Account.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AACnD,OAAO,EAAE,cAAc,EAAE,MAAM,uCAAuC,CAAC;AAEvE,OAAO,EAAE,eAAe,EAAE,UAAU,EAAE,kBAAkB,EAAE,MAAM,+BAA+B,CAAC;AAChG,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAEhC,MAAM,CAAC,MAAM,mBAAmB,GAAG;IAClC,MAAM,EAAE,EAAE,UAAU,EAAE,EAAE,eAAe,EAAE,UAAU,EAAE,kBAAkB,EAAE,EAAE,OAAO,EAAE,MAAM,CAAC,IAAI,EAAE;CACxF,CAAC;AAEX,MAAM,CAAC,MAAM,OAAO,GAAG,cAAc,CAAC;IACrC,QAAQ,EAAE,CAAC,QAAQ,CAAC;IACpB,UAAU,EAAE,iBAAiB;IAC7B,IAAI,EAAE,kBAAkB;IACxB,QAAQ,EAAE;QACT,MAAM,EAAE,EAAE,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE;KACnC;IACD,IAAI,EAAE,mBAAmB;CACzB,CAAC,CAAC;AAEH,MAAM,CAAC,MAAM,0BAA0B,GAA8D,IAAI,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { Context, type Effect, type Schema } from "effect";
|
|
2
|
+
import type { SqlError } from "effect/sql/SqlError";
|
|
3
|
+
import type { AuthUnavailable, BadRequest, PreconditionFailed } from "@shivaedev/errors/taxonomy.ts";
|
|
4
|
+
import type { SessionUser } from "#identity.ts";
|
|
5
|
+
declare const AccountDeletion_base: Context.ServiceClass<AccountDeletion, "@shivaedev/identity/AccountDeletion", {
|
|
6
|
+
readonly delete: (password: string) => Effect.Effect<void, AuthUnavailable | BadRequest | PreconditionFailed | Schema.SchemaError | SqlError, SessionUser>;
|
|
7
|
+
}>;
|
|
8
|
+
export declare class AccountDeletion extends AccountDeletion_base {
|
|
9
|
+
}
|
|
10
|
+
export {};
|
|
11
|
+
//# sourceMappingURL=AccountDeletion.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AccountDeletion.d.ts","sourceRoot":"","sources":["../../src/server/AccountDeletion.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,KAAK,MAAM,EAAE,KAAK,MAAM,EAAE,MAAM,QAAQ,CAAC;AAC3D,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AACpD,OAAO,KAAK,EAAE,eAAe,EAAE,UAAU,EAAE,kBAAkB,EAAE,MAAM,+BAA+B,CAAC;AACrG,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;;qBAM7B,CAChB,QAAQ,EAAE,MAAM,KACZ,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,eAAe,GAAG,UAAU,GAAG,kBAAkB,GAAG,MAAM,CAAC,WAAW,GAAG,QAAQ,EAAE,WAAW,CAAC;;AAL1H,qBAAa,eAAgB,SAAQ,oBAOK;CAAG"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { Context } from "effect";
|
|
2
|
+
// The account module's port, so the module stays free of the provider that implements the deletion.
|
|
3
|
+
export class AccountDeletion extends Context.Service()("@shivaedev/identity/AccountDeletion") {
|
|
4
|
+
}
|
|
5
|
+
//# sourceMappingURL=AccountDeletion.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AccountDeletion.js","sourceRoot":"","sources":["../../src/server/AccountDeletion.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAA4B,MAAM,QAAQ,CAAC;AAK3D,oGAAoG;AACpG,MAAM,OAAO,eAAgB,SAAQ,OAAO,CAAC,OAAO,EAOjD,CAAC,qCAAqC,CAAC;CAAG"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { Context, type Effect } from "effect";
|
|
2
|
+
import type { AuthSchemaDeclaration } from "#server/better-auth/define.ts";
|
|
3
|
+
declare const AccountDeletionPolicy_base: Context.ServiceClass<AccountDeletionPolicy, "@shivaedev/identity/AccountDeletionPolicy", {
|
|
4
|
+
readonly auth: Pick<AuthSchemaDeclaration, "options">;
|
|
5
|
+
readonly handOver: (userId: string) => Effect.Effect<void>;
|
|
6
|
+
}>;
|
|
7
|
+
export declare class AccountDeletionPolicy extends AccountDeletionPolicy_base {
|
|
8
|
+
}
|
|
9
|
+
export {};
|
|
10
|
+
//# sourceMappingURL=AccountDeletionPolicy.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AccountDeletionPolicy.d.ts","sourceRoot":"","sources":["../../../src/server/better-auth/AccountDeletionPolicy.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,KAAK,MAAM,EAAE,MAAM,QAAQ,CAAC;AAC9C,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,+BAA+B,CAAC;;mBAK1D,IAAI,CAAC,qBAAqB,EAAE,SAAS,CAAC;uBAClC,CAAC,MAAM,EAAE,MAAM,KAAK,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC;;AAJ5D,qBAAa,qBAAsB,SAAQ,0BAMK;CAAG"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AccountDeletionPolicy.js","sourceRoot":"","sources":["../../../src/server/better-auth/AccountDeletionPolicy.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAe,MAAM,QAAQ,CAAC;AAG9C,MAAM,OAAO,qBAAsB,SAAQ,OAAO,CAAC,OAAO,EAMvD,CAAC,2CAA2C,CAAC;CAAG"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { type Context, Effect, Layer } from "effect";
|
|
2
|
+
import * as Reactivity from "effect/reactivity/Reactivity";
|
|
3
|
+
import { SqlClient } from "effect/sql";
|
|
4
|
+
import { AccountDeletion } from "#server/AccountDeletion.ts";
|
|
5
|
+
import type { AuthSchemaDeclaration } from "#server/better-auth/define.ts";
|
|
6
|
+
export interface AccountHandOver<E> {
|
|
7
|
+
readonly handOver: (userId: string) => Effect.Effect<void, E>;
|
|
8
|
+
}
|
|
9
|
+
export interface AccountDeletionOptions<TIdentifier, E> {
|
|
10
|
+
readonly handOver?: Context.Service<TIdentifier, AccountHandOver<E>> | undefined;
|
|
11
|
+
}
|
|
12
|
+
export declare function accountDeletion<TIdentifier = never, E = never>(auth: Pick<AuthSchemaDeclaration, "options">, options?: AccountDeletionOptions<TIdentifier, E>): Layer.Layer<AccountDeletion, never, Reactivity.Reactivity | SqlClient.SqlClient | Exclude<TIdentifier, import("effect/Scope").Scope>>;
|
|
13
|
+
//# sourceMappingURL=accountDeletion.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"accountDeletion.d.ts","sourceRoot":"","sources":["../../../src/server/better-auth/accountDeletion.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,QAAQ,CAAC;AACrD,OAAO,KAAK,UAAU,MAAM,8BAA8B,CAAC;AAC3D,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AACvC,OAAO,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAC;AAE7D,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,+BAA+B,CAAC;AAG3E,MAAM,WAAW,eAAe,CAAC,CAAC;IACjC,QAAQ,CAAC,QAAQ,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC;CAC9D;AAED,MAAM,WAAW,sBAAsB,CAAC,WAAW,EAAE,CAAC;IACrD,QAAQ,CAAC,QAAQ,CAAC,EAAE,OAAO,CAAC,OAAO,CAAC,WAAW,EAAE,eAAe,CAAC,CAAC,CAAC,CAAC,GAAG,SAAS,CAAC;CACjF;AAGD,wBAAgB,eAAe,CAAC,WAAW,GAAG,KAAK,EAAE,CAAC,GAAG,KAAK,EAC7D,IAAI,EAAE,IAAI,CAAC,qBAAqB,EAAE,SAAS,CAAC,EAC5C,OAAO,GAAE,sBAAsB,CAAC,WAAW,EAAE,CAAC,CAAM,yIAqBpD"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { Effect, Layer } from "effect";
|
|
2
|
+
import * as Reactivity from "effect/reactivity/Reactivity";
|
|
3
|
+
import { SqlClient } from "effect/sql";
|
|
4
|
+
import { AccountDeletion } from "#server/AccountDeletion.ts";
|
|
5
|
+
import { AccountDeletionPolicy } from "#server/better-auth/AccountDeletionPolicy.ts";
|
|
6
|
+
import { deleteAccount } from "#server/better-auth/deleteAccount.ts";
|
|
7
|
+
// A hand-over's failure is the application's to fix, so it is reported rather than answered to the person.
|
|
8
|
+
export function accountDeletion(auth, options = {}) {
|
|
9
|
+
return Layer.effect(AccountDeletion)(Effect.gen(function* () {
|
|
10
|
+
const sql = yield* SqlClient.SqlClient;
|
|
11
|
+
const reactivity = yield* Reactivity.Reactivity;
|
|
12
|
+
const service = options.handOver === undefined ? undefined : yield* options.handOver;
|
|
13
|
+
const policy = {
|
|
14
|
+
auth,
|
|
15
|
+
handOver: (userId) => (service === undefined ? Effect.void : Effect.orDie(service.handOver(userId))),
|
|
16
|
+
};
|
|
17
|
+
return AccountDeletion.of({
|
|
18
|
+
delete: (password) => deleteAccount(password).pipe(Effect.provideService(AccountDeletionPolicy, policy), Effect.provideService(SqlClient.SqlClient, sql), Effect.provideService(Reactivity.Reactivity, reactivity)),
|
|
19
|
+
});
|
|
20
|
+
}));
|
|
21
|
+
}
|
|
22
|
+
//# sourceMappingURL=accountDeletion.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"accountDeletion.js","sourceRoot":"","sources":["../../../src/server/better-auth/accountDeletion.ts"],"names":[],"mappings":"AAAA,OAAO,EAAgB,MAAM,EAAE,KAAK,EAAE,MAAM,QAAQ,CAAC;AACrD,OAAO,KAAK,UAAU,MAAM,8BAA8B,CAAC;AAC3D,OAAO,EAAE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AAC,CACF,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { BetterAuthOptions } from "better-auth";
|
|
2
|
+
import { Effect } from "effect";
|
|
3
|
+
export declare function passwordMatches(options: BetterAuthOptions, hash: string, password: string): Effect.Effect<boolean, import("@shivaedev/errors/taxonomy.ts").AuthUnavailable, never>;
|
|
4
|
+
//# sourceMappingURL=passwordMatches.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"passwordMatches.d.ts","sourceRoot":"","sources":["../../../../src/server/better-auth/adapters/passwordMatches.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAErD,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAIhC,wBAAgB,eAAe,CAAC,OAAO,EAAE,iBAAiB,EAAE,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,0FAGzF"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { verifyPassword } from "better-auth/crypto";
|
|
2
|
+
import { Effect } from "effect";
|
|
3
|
+
import { providerFailure } from "#server/providerFailure.ts";
|
|
4
|
+
// Better Auth's context resolves the verifier the same way, so a custom hash in the options is checked by its own verify.
|
|
5
|
+
export function passwordMatches(options, hash, password) {
|
|
6
|
+
const verify = options.emailAndPassword?.password?.verify ?? verifyPassword;
|
|
7
|
+
return Effect.tryPromise(() => verify({ hash, password })).pipe(Effect.catch(providerFailure));
|
|
8
|
+
}
|
|
9
|
+
//# sourceMappingURL=passwordMatches.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"passwordMatches.js","sourceRoot":"","sources":["../../../../src/server/better-auth/adapters/passwordMatches.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AACpD,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAChC,OAAO,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAC;AAE7D,0HAA0H;AAC1H,MAAM,UAAU,eAAe,CAAC,OAA0B,EAAE,IAAY,EAAE,QAAgB;IACzF,MAAM,MAAM,GAAG,OAAO,CAAC,gBAAgB,EAAE,QAAQ,EAAE,MAAM,IAAI,cAAc,CAAC;IAC5E,OAAO,MAAM,CAAC,UAAU,CAAC,GAAG,EAAE,CAAC,MAAM,CAAC,EAAE,IAAI,EAAE,QAAQ,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,eAAe,CAAC,CAAC,CAAC;AAChG,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"closeAccountDeletion.d.ts","sourceRoot":"","sources":["../../../src/server/better-auth/closeAccountDeletion.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAGrD,wBAAgB,oBAAoB,CAAC,QAAQ,SAAS,iBAAiB,EAAE,OAAO,EAAE,QAAQ,GAAG,QAAQ,CAEpG"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
// Identity's account module is the one way to delete an account, because Better Auth's deletion runs outside any transaction.
|
|
2
|
+
export function closeAccountDeletion(options) {
|
|
3
|
+
return { ...options, disabledPaths: [...(options.disabledPaths ?? []), "/delete-user", "/delete-user/callback", "/admin/remove-user"] };
|
|
4
|
+
}
|
|
5
|
+
//# sourceMappingURL=closeAccountDeletion.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"closeAccountDeletion.js","sourceRoot":"","sources":["../../../src/server/better-auth/closeAccountDeletion.ts"],"names":[],"mappings":"AAEA,8HAA8H;AAC9H,MAAM,UAAU,oBAAoB,CAAqC,OAAiB;IACzF,OAAO,EAAE,GAAG,OAAO,EAAE,aAAa,EAAE,CAAC,GAAG,CAAC,OAAO,CAAC,aAAa,IAAI,EAAE,CAAC,EAAE,cAAc,EAAE,uBAAuB,EAAE,oBAAoB,CAAC,EAAE,CAAC;AACzI,CAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { BetterAuthOptions } from "better-auth";
|
|
2
|
+
import { Effect, Schema } from "effect";
|
|
3
|
+
import { SqlClient } from "effect/sql";
|
|
4
|
+
import { BadRequest, PreconditionFailed } from "@shivaedev/errors/taxonomy.ts";
|
|
5
|
+
import { SessionUser } from "#identity.ts";
|
|
6
|
+
export declare const confirmPassword: (options: BetterAuthOptions, password: string) => Effect.Effect<undefined, import("@shivaedev/errors/taxonomy.ts").AuthUnavailable | BadRequest | PreconditionFailed | Schema.SchemaError | import("effect/sql/SqlError").SqlError, SessionUser | SqlClient.SqlClient>;
|
|
7
|
+
//# sourceMappingURL=confirmPassword.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"confirmPassword.d.ts","sourceRoot":"","sources":["../../../src/server/better-auth/confirmPassword.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAErD,OAAO,EAAE,MAAM,EAAU,MAAM,EAAE,MAAM,QAAQ,CAAC;AAChD,OAAO,EAAE,SAAS,EAAa,MAAM,YAAY,CAAC;AAClD,OAAO,EAAE,UAAU,EAAE,kBAAkB,EAAE,MAAM,+BAA+B,CAAC;AAC/E,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAQ3C,eAAO,MAAM,eAAe,wQAuB1B,CAAC"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { getAuthTables } from "better-auth/db";
|
|
2
|
+
import { Effect, Option, Schema } from "effect";
|
|
3
|
+
import { SqlClient, SqlSchema } from "effect/sql";
|
|
4
|
+
import { BadRequest, PreconditionFailed } from "@shivaedev/errors/taxonomy.ts";
|
|
5
|
+
import { SessionUser } from "#identity.ts";
|
|
6
|
+
import { passwordMatches } from "#server/better-auth/adapters/passwordMatches.ts";
|
|
7
|
+
// Better Auth's own limit when the options set none; a longer input is refused before it reaches the hash.
|
|
8
|
+
const MAX_PASSWORD_LENGTH = 128;
|
|
9
|
+
const Credential = Schema.Struct({ password: Schema.String });
|
|
10
|
+
export const confirmPassword = Effect.fn("Identity.confirmPassword")(function* (options, password) {
|
|
11
|
+
const { id: userId } = yield* SessionUser;
|
|
12
|
+
const { account } = getAuthTables(options);
|
|
13
|
+
const sql = (yield* SqlClient.SqlClient).withoutTransforms();
|
|
14
|
+
function column(field) {
|
|
15
|
+
return sql(account?.fields[field]?.fieldName ?? field);
|
|
16
|
+
}
|
|
17
|
+
const credential = yield* SqlSchema.findOneOption({
|
|
18
|
+
execute: (id) => sql `select ${column("password")} as password from ${sql(account?.modelName ?? "account")}
|
|
19
|
+
where ${column("userId")} = ${id} and ${column("providerId")} = 'credential' and ${column("password")} is not null`,
|
|
20
|
+
Request: Schema.String,
|
|
21
|
+
Result: Credential,
|
|
22
|
+
})(userId);
|
|
23
|
+
if (Option.isNone(credential)) {
|
|
24
|
+
return yield* new PreconditionFailed({ message: "This account has no password to confirm its deletion with." });
|
|
25
|
+
}
|
|
26
|
+
const maximum = options.emailAndPassword?.maxPasswordLength ?? MAX_PASSWORD_LENGTH;
|
|
27
|
+
if (password.length === 0 || password.length > maximum) {
|
|
28
|
+
return yield* new BadRequest({ field: "password", message: "Enter your current password." });
|
|
29
|
+
}
|
|
30
|
+
if (!(yield* passwordMatches(options, credential.value.password, password))) {
|
|
31
|
+
return yield* new BadRequest({ field: "password", message: "The password is incorrect." });
|
|
32
|
+
}
|
|
33
|
+
});
|
|
34
|
+
//# sourceMappingURL=confirmPassword.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"confirmPassword.js","sourceRoot":"","sources":["../../../src/server/better-auth/confirmPassword.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAC/C,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,QAA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pH,OAAO,EAAE,MAAM,CAAC,MAAM;QACtB,MAAM,EAAE,UAAU;KAClB,CAAC,CAAC,MAAM,CAAC,CAAC;IACX,IAAI,MAAM,CAAC,MAAM,CAAC,UAAU,CAAC,EAAE,CAAC;QAC/B,OAAO,KAAK,CAAC,CAAC,IAAI,kBAAkB,CAAC,EAAE,OAAO,EAAE,4DAA4D,EAAE,CAAC,CAAC;IACjH,CAAC;IACD,MAAM,OAAO,GAAG,OAAO,CAAC,gBAAgB,EAAE,iBAAiB,IAAI,mBAAmB,CAAC;IACnF,IAAI,QAAQ,CAAC,MAAM,KAAK,CAAC,IAAI,QAAQ,CAAC,MAAM,GAAG,OAAO,EAAE,CAAC;QACxD,OAAO,KAAK,CAAC,CAAC,IAAI,UAAU,CAAC,EAAE,KAAK,EAAE,UAAU,EAAE,OAAO,EAAE,8BAA8B,EAAE,CAAC,CAAC;IAC9F,CAAC;IACD,IAAI,CAAC,CAAC,KAAK,CAAC,CAAC,eAAe,CAAC,OAAO,EAAE,UAAU,CAAC,KAAK,CAAC,QAAQ,EAAE,QAAQ,CAAC,CAAC,EAAE,CAAC;QAC7E,OAAO,KAAK,CAAC,CAAC,IAAI,UAAU,CAAC,EAAE,KAAK,EAAE,UAAU,EAAE,OAAO,EAAE,4BAA4B,EAAE,CAAC,CAAC;IAC5F,CAAC;AACF,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { Effect } from "effect";
|
|
2
|
+
import { SessionUser } from "#identity.ts";
|
|
3
|
+
import { AccountDeletionPolicy } from "#server/better-auth/AccountDeletionPolicy.ts";
|
|
4
|
+
export declare const deleteAccount: (password: string) => Effect.Effect<void, import("@shivaedev/errors/taxonomy.ts").AuthUnavailable | import("@shivaedev/errors/taxonomy.ts").BadRequest | import("@shivaedev/errors/taxonomy.ts").PreconditionFailed | import("effect/Schema").SchemaError | import("effect/sql/SqlError").SqlError, AccountDeletionPolicy | SessionUser | (import("effect/reactivity/Reactivity").Reactivity | import("effect/sql/SqlClient").SqlClient)>;
|
|
5
|
+
//# sourceMappingURL=deleteAccount.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"deleteAccount.d.ts","sourceRoot":"","sources":["../../../src/server/better-auth/deleteAccount.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAGhC,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAC3C,OAAO,EAAE,qBAAqB,EAAE,MAAM,8CAA8C,CAAC;AAQrF,eAAO,MAAM,aAAa,2aAYxB,CAAC"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { Effect } from "effect";
|
|
2
|
+
import { invalidationKeys } from "@shivaedev/changes/keys.ts";
|
|
3
|
+
import { invalidateOnCommit, transact } from "@shivaedev/sql/transact.ts";
|
|
4
|
+
import { SessionUser } from "#identity.ts";
|
|
5
|
+
import { AccountDeletionPolicy } from "#server/better-auth/AccountDeletionPolicy.ts";
|
|
6
|
+
import { accountData } from "#server/better-auth/accountData.ts";
|
|
7
|
+
import { confirmPassword } from "#server/better-auth/confirmPassword.ts";
|
|
8
|
+
import { deleteUserRows } from "#server/better-auth/deleteUserRows.ts";
|
|
9
|
+
import { sessionKeys } from "#signedInSessions.ts";
|
|
10
|
+
import { userKeys } from "#users.ts";
|
|
11
|
+
// An erase that cannot run is the operator's to fix, so its failure is reported with its tables rather than answered to the person.
|
|
12
|
+
export const deleteAccount = Effect.fn("Identity.deleteAccount")(function* (password) {
|
|
13
|
+
const { id } = yield* SessionUser;
|
|
14
|
+
const { auth, handOver } = yield* AccountDeletionPolicy;
|
|
15
|
+
yield* confirmPassword(auth.options, password);
|
|
16
|
+
yield* Effect.gen(function* () {
|
|
17
|
+
yield* handOver(id);
|
|
18
|
+
yield* accountData(auth)
|
|
19
|
+
.eraseOwnedRows(id)
|
|
20
|
+
.pipe(Effect.catchTags({ OwnedModelsUncollected: Effect.die, OwnedTableCycle: Effect.die, UncoveredUserColumns: Effect.die }));
|
|
21
|
+
yield* deleteUserRows(auth.options);
|
|
22
|
+
yield* invalidateOnCommit(invalidationKeys([userKeys.item(id), sessionKeys.list]));
|
|
23
|
+
}).pipe(transact());
|
|
24
|
+
});
|
|
25
|
+
//# sourceMappingURL=deleteAccount.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"deleteAccount.js","sourceRoot":"","sources":["../../../src/server/better-auth/deleteAccount.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAChC,OAAO,EAAE,gBAAgB,EAAE,MAAM,4BAA4B,CAAC;AAC9D,OAAO,EAAE,kBAAkB,EAAE,QAAQ,EAAE,MAAM,4BAA4B,CAAC;AAC1E,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAC3C,OAAO,EAAE,qBAAqB,EAAE,MAAM,8CAA8C,CAAC;AACrF,OAAO,EAAE,WAAW,EAAE,MAAM,oCAAoC,CAAC;AACjE,OAAO,EAAE,eAAe,EAAE,MAAM,wCAAwC,CAAC;AACzE,OAAO,EAAE,cAAc,EAAE,MAAM,uCAAuC,CAAC;AACvE,OAAO,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AACnD,OAAO,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AAErC,oIAAoI;AACpI,MAAM,CAAC,MAAM,aAAa,GAAG,MAAM,CAAC,EAAE,CAAC,wBAAwB,CAAC,CAAC,QAAQ,CAAC,EAAE,QAAgB;IAC3F,MAAM,EAAE,EAAE,EAAE,GAAG,KAAK,CAAC,CAAC,WAAW,CAAC;IAClC,MAAM,EAAE,IAAI,EAAE,QAAQ,EAAE,GAAG,KAAK,CAAC,CAAC,qBAAqB,CAAC;IACxD,KAAK,CAAC,CAAC,eAAe,CAAC,IAAI,CAAC,OAAO,EAAE,QAAQ,CAAC,CAAC;IAC/C,KAAK,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,QAAQ,CAAC;QAC1B,KAAK,CAAC,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC;QACpB,KAAK,CAAC,CAAC,WAAW,CAAC,IAAI,CAAC;aACtB,cAAc,CAAC,EAAE,CAAC;aAClB,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,EAAE,sBAAsB,EAAE,MAAM,CAAC,GAAG,EAAE,eAAe,EAAE,MAAM,CAAC,GAAG,EAAE,oBAAoB,EAAE,MAAM,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC;QAChI,KAAK,CAAC,CAAC,cAAc,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;QACpC,KAAK,CAAC,CAAC,kBAAkB,CAAC,gBAAgB,CAAC,CAAC,QAAQ,CAAC,IAAI,CAAC,EAAE,CAAC,EAAE,WAAW,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IACpF,CAAC,CAAC,CAAC,IAAI,CAAC,QAAQ,EAAE,CAAC,CAAC;AACrB,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { BetterAuthOptions } from "better-auth";
|
|
2
|
+
import { Effect } from "effect";
|
|
3
|
+
import { SqlClient } from "effect/sql";
|
|
4
|
+
import { SessionUser } from "#identity.ts";
|
|
5
|
+
export declare const deleteUserRows: (options: BetterAuthOptions) => Effect.Effect<void, import("effect/sql/SqlError").SqlError, SessionUser | SqlClient.SqlClient>;
|
|
6
|
+
//# sourceMappingURL=deleteUserRows.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"deleteUserRows.d.ts","sourceRoot":"","sources":["../../../src/server/better-auth/deleteUserRows.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAErD,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAChC,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AACvC,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAM3C,eAAO,MAAM,cAAc,gIAUzB,CAAC"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { getAuthTables } from "better-auth/db";
|
|
2
|
+
import { Effect } from "effect";
|
|
3
|
+
import { SqlClient } from "effect/sql";
|
|
4
|
+
import { SessionUser } from "#identity.ts";
|
|
5
|
+
// Better Auth's session and account tables cascade from the user row, so one delete removes the person's sign-ins with it.
|
|
6
|
+
// Verification rows carry no key to the user, so these are the exact identifiers Better Auth 1.7 writes for one person: the user id
|
|
7
|
+
// as a reset or deletion token's value, the address in an email code's identifier, and the id leading a change-email or two-factor code's.
|
|
8
|
+
const ADDRESS_CODES = ["email-verification", "sign-in", "forget-password"];
|
|
9
|
+
export const deleteUserRows = Effect.fn("Identity.deleteUserRows")(function* (options) {
|
|
10
|
+
const { email, id } = yield* SessionUser;
|
|
11
|
+
const { user, verification } = getAuthTables(options);
|
|
12
|
+
const sql = (yield* SqlClient.SqlClient).withoutTransforms();
|
|
13
|
+
const identifier = sql(verification?.fields.identifier?.fieldName ?? "identifier");
|
|
14
|
+
const value = sql(verification?.fields.value?.fieldName ?? "value");
|
|
15
|
+
const codes = ADDRESS_CODES.map((type) => `${type}-otp-${email}`);
|
|
16
|
+
yield* sql `delete from ${sql(verification?.modelName ?? "verification")} where ${value} = ${id} or ${identifier} in ${sql.in(codes)}
|
|
17
|
+
or starts_with(${identifier}, ${`change-email-otp-${id}:`}) or starts_with(${identifier}, ${`2fa-otp-${id}!`})`;
|
|
18
|
+
yield* sql `delete from ${sql(user?.modelName ?? "user")} where id = ${id}`;
|
|
19
|
+
});
|
|
20
|
+
//# sourceMappingURL=deleteUserRows.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"deleteUserRows.js","sourceRoot":"","sources":["../../../src/server/better-auth/deleteUserRows.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AA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AC,CAAC,GAAG,CAAA,eAAe,GAAG,CAAC,IAAI,EAAE,SAAS,IAAI,MAAM,CAAC,eAAe,EAAE,EAAE,CAAC;AAC5E,CAAC,CAAC,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mount.d.ts","sourceRoot":"","sources":["../../../src/server/better-auth/mount.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AACrD,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,KAAK,KAAK,EAAE,MAAM,QAAQ,CAAC;AACnD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAC5C,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,gCAAgC,CAAC;AAG5D,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,iDAAiD,CAAC;AAOvF,OAAO,EAAE,KAAK,0BAA0B,EAAiB,MAAM,2CAA2C,CAAC;AAQ3G,OAAO,EAAmC,KAAK,YAAY,EAAc,MAAM,4CAA4C,CAAC;
|
|
1
|
+
{"version":3,"file":"mount.d.ts","sourceRoot":"","sources":["../../../src/server/better-auth/mount.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AACrD,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,KAAK,KAAK,EAAE,MAAM,QAAQ,CAAC;AACnD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAC5C,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,gCAAgC,CAAC;AAG5D,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,iDAAiD,CAAC;AAOvF,OAAO,EAAE,KAAK,0BAA0B,EAAiB,MAAM,2CAA2C,CAAC;AAQ3G,OAAO,EAAmC,KAAK,YAAY,EAAc,MAAM,4CAA4C,CAAC;AAK5H,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,sCAAsC,CA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,GAAG,KAAK,EAC7F,IAAI,EAAE,eAAe,CAAC,QAAQ,CAAC,EAC/B,KAAK,EAAE,sBAAsB,CAAC,CAAC,EAAE,CAAC,CAAC,GACjC,OAAO,CAAC,QAAQ,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC"}
|
|
@@ -18,6 +18,7 @@ import { roleSeedOptions } from "#server/better-auth/adapters/roleSeedOptions.ts
|
|
|
18
18
|
import { fromStorage, signInGate } from "#server/better-auth/adapters/signInGate.ts";
|
|
19
19
|
import { signInPolicyOptions } from "#server/better-auth/adapters/signInPolicyOptions.ts";
|
|
20
20
|
import { changeHooks } from "#server/better-auth/changeHooks.ts";
|
|
21
|
+
import { closeAccountDeletion } from "#server/better-auth/closeAccountDeletion.ts";
|
|
21
22
|
import { closeRoleEndpoints } from "#server/better-auth/closeRoleEndpoints.ts";
|
|
22
23
|
import { AuthRouteHandler, mountRoutes } from "#server/better-auth/mountRoutes.ts";
|
|
23
24
|
import { mountSettings } from "#server/better-auth/mountSettings.ts";
|
|
@@ -44,7 +45,8 @@ const mountAuth = Effect.fn("Identity.mountAuth")(function* (declaration, mount
|
|
|
44
45
|
const reset = passwordResetOptions(preferences, mount.onPasswordReset, runtime);
|
|
45
46
|
const announced = effectHookOptions(yield* emailOptions(reset, mount.emails, runtime), changeHooks, runtime);
|
|
46
47
|
const hooked = effectHookOptions(announced, mount.databaseHooks, runtime);
|
|
47
|
-
const
|
|
48
|
+
const closed = closeAccountDeletion(hooked);
|
|
49
|
+
const configured = declaration.roles === undefined ? closed : storedRoleOptions(closeRoleEndpoints(closed), declaration);
|
|
48
50
|
const gated = yield* signInPolicyOptions(configured, gate, () => auth.$context);
|
|
49
51
|
const seed = mount.roleSeed === undefined ? undefined : yield* mount.roleSeed;
|
|
50
52
|
const seeded = roleSeedOptions(gate.active ? { ...configured, ...gated } : configured, seed);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mount.js","sourceRoot":"","sources":["../../../src/server/better-auth/mount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
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.42.0",
|
|
4
4
|
"description": "Request identity, sessions, transport trust and permission enforcement for Effect RPC servers",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"effect"
|
|
@@ -58,11 +58,11 @@
|
|
|
58
58
|
"@better-auth/oauth-provider": "1.7.23",
|
|
59
59
|
"@effect/platform-node": "4.1.4",
|
|
60
60
|
"@effect/sql-pg": "4.1.4",
|
|
61
|
-
"@shivaedev/admin": "0.29.
|
|
62
|
-
"@shivaedev/build": "0.8.
|
|
61
|
+
"@shivaedev/admin": "0.29.4",
|
|
62
|
+
"@shivaedev/build": "0.8.1",
|
|
63
63
|
"@shivaedev/quality": "0.84.0",
|
|
64
|
-
"@shivaedev/server": "0.44.
|
|
65
|
-
"@shivaedev/test-kits": "0.16.
|
|
64
|
+
"@shivaedev/server": "0.44.2",
|
|
65
|
+
"@shivaedev/test-kits": "0.16.8",
|
|
66
66
|
"@shivaedev/test-sql": "0.26.1",
|
|
67
67
|
"@shivaedev/test-story": "0.52.5",
|
|
68
68
|
"@types/node": "24.19.2",
|
package/src/Account.ts
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { Schema } from "effect";
|
|
2
|
+
import { defineModule } from "@shivaedev/contract/defineModule.ts";
|
|
3
|
+
import { command } from "@shivaedev/contract/operation.ts";
|
|
4
|
+
import { identityAccountWire } from "#generated/Account.ts";
|
|
5
|
+
import { AuthenticatedUser } from "#middleware.ts";
|
|
6
|
+
import { AccountDeletion } from "#server/AccountDeletion.ts";
|
|
7
|
+
|
|
8
|
+
const DeleteAccount = command("delete", {
|
|
9
|
+
payload: { password: Schema.String },
|
|
10
|
+
*run({ password }) {
|
|
11
|
+
yield* (yield* AccountDeletion).delete(password);
|
|
12
|
+
},
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
export const Account = defineModule({
|
|
16
|
+
middleware: AuthenticatedUser,
|
|
17
|
+
name: "identity.account",
|
|
18
|
+
operations: [DeleteAccount],
|
|
19
|
+
wire: identityAccountWire,
|
|
20
|
+
});
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
// Generated by @shivaedev/build from src/Account.ts. Do not edit or commit this file; run `pnpm generate` to write it again.
|
|
2
|
+
import type { Account as AccountModule } from "#Account.ts";
|
|
3
|
+
import { AuthenticatedUser } from "#middleware.ts";
|
|
4
|
+
import { clientContract } from "@shivaedev/contract/clientContract.ts";
|
|
5
|
+
import type { ClientMatchesModule } from "@shivaedev/contract/clientMatchesModule.ts";
|
|
6
|
+
import { AuthUnavailable, BadRequest, PreconditionFailed } from "@shivaedev/errors/taxonomy.ts";
|
|
7
|
+
import { Schema } from "effect";
|
|
8
|
+
|
|
9
|
+
export const identityAccountWire = {
|
|
10
|
+
delete: { rejections: { AuthUnavailable, BadRequest, PreconditionFailed }, success: Schema.Void },
|
|
11
|
+
} as const;
|
|
12
|
+
|
|
13
|
+
export const Account = clientContract({
|
|
14
|
+
commands: ["delete"],
|
|
15
|
+
middleware: AuthenticatedUser,
|
|
16
|
+
name: "identity.account",
|
|
17
|
+
payloads: {
|
|
18
|
+
delete: { password: Schema.String },
|
|
19
|
+
},
|
|
20
|
+
wire: identityAccountWire,
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
export const identityAccountMatchModule: ClientMatchesModule<typeof Account, typeof AccountModule> = true;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { Context, type Effect, type Schema } from "effect";
|
|
2
|
+
import type { SqlError } from "effect/sql/SqlError";
|
|
3
|
+
import type { AuthUnavailable, BadRequest, PreconditionFailed } from "@shivaedev/errors/taxonomy.ts";
|
|
4
|
+
import type { SessionUser } from "#identity.ts";
|
|
5
|
+
|
|
6
|
+
// The account module's port, so the module stays free of the provider that implements the deletion.
|
|
7
|
+
export class AccountDeletion extends Context.Service<
|
|
8
|
+
AccountDeletion,
|
|
9
|
+
{
|
|
10
|
+
readonly delete: (
|
|
11
|
+
password: string,
|
|
12
|
+
) => Effect.Effect<void, AuthUnavailable | BadRequest | PreconditionFailed | Schema.SchemaError | SqlError, SessionUser>;
|
|
13
|
+
}
|
|
14
|
+
>()("@shivaedev/identity/AccountDeletion") {}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { Context, type Effect } from "effect";
|
|
2
|
+
import type { AuthSchemaDeclaration } from "#server/better-auth/define.ts";
|
|
3
|
+
|
|
4
|
+
export class AccountDeletionPolicy extends Context.Service<
|
|
5
|
+
AccountDeletionPolicy,
|
|
6
|
+
{
|
|
7
|
+
readonly auth: Pick<AuthSchemaDeclaration, "options">;
|
|
8
|
+
readonly handOver: (userId: string) => Effect.Effect<void>;
|
|
9
|
+
}
|
|
10
|
+
>()("@shivaedev/identity/AccountDeletionPolicy") {}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { type Context, Effect, Layer } from "effect";
|
|
2
|
+
import * as Reactivity from "effect/reactivity/Reactivity";
|
|
3
|
+
import { SqlClient } from "effect/sql";
|
|
4
|
+
import { AccountDeletion } from "#server/AccountDeletion.ts";
|
|
5
|
+
import { AccountDeletionPolicy } from "#server/better-auth/AccountDeletionPolicy.ts";
|
|
6
|
+
import type { AuthSchemaDeclaration } from "#server/better-auth/define.ts";
|
|
7
|
+
import { deleteAccount } from "#server/better-auth/deleteAccount.ts";
|
|
8
|
+
|
|
9
|
+
export interface AccountHandOver<E> {
|
|
10
|
+
readonly handOver: (userId: string) => Effect.Effect<void, E>;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export interface AccountDeletionOptions<TIdentifier, E> {
|
|
14
|
+
readonly handOver?: Context.Service<TIdentifier, AccountHandOver<E>> | undefined;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
// A hand-over's failure is the application's to fix, so it is reported rather than answered to the person.
|
|
18
|
+
export function accountDeletion<TIdentifier = never, E = never>(
|
|
19
|
+
auth: Pick<AuthSchemaDeclaration, "options">,
|
|
20
|
+
options: AccountDeletionOptions<TIdentifier, E> = {},
|
|
21
|
+
) {
|
|
22
|
+
return Layer.effect(AccountDeletion)(
|
|
23
|
+
Effect.gen(function* () {
|
|
24
|
+
const sql = yield* SqlClient.SqlClient;
|
|
25
|
+
const reactivity = yield* Reactivity.Reactivity;
|
|
26
|
+
const service = options.handOver === undefined ? undefined : yield* options.handOver;
|
|
27
|
+
const policy = {
|
|
28
|
+
auth,
|
|
29
|
+
handOver: (userId: string) => (service === undefined ? Effect.void : Effect.orDie(service.handOver(userId))),
|
|
30
|
+
};
|
|
31
|
+
return AccountDeletion.of({
|
|
32
|
+
delete: (password) =>
|
|
33
|
+
deleteAccount(password).pipe(
|
|
34
|
+
Effect.provideService(AccountDeletionPolicy, policy),
|
|
35
|
+
Effect.provideService(SqlClient.SqlClient, sql),
|
|
36
|
+
Effect.provideService(Reactivity.Reactivity, reactivity),
|
|
37
|
+
),
|
|
38
|
+
});
|
|
39
|
+
}),
|
|
40
|
+
);
|
|
41
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { BetterAuthOptions } from "better-auth";
|
|
2
|
+
import { verifyPassword } from "better-auth/crypto";
|
|
3
|
+
import { Effect } from "effect";
|
|
4
|
+
import { providerFailure } from "#server/providerFailure.ts";
|
|
5
|
+
|
|
6
|
+
// Better Auth's context resolves the verifier the same way, so a custom hash in the options is checked by its own verify.
|
|
7
|
+
export function passwordMatches(options: BetterAuthOptions, hash: string, password: string) {
|
|
8
|
+
const verify = options.emailAndPassword?.password?.verify ?? verifyPassword;
|
|
9
|
+
return Effect.tryPromise(() => verify({ hash, password })).pipe(Effect.catch(providerFailure));
|
|
10
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { BetterAuthOptions } from "better-auth";
|
|
2
|
+
|
|
3
|
+
// Identity's account module is the one way to delete an account, because Better Auth's deletion runs outside any transaction.
|
|
4
|
+
export function closeAccountDeletion<TOptions extends BetterAuthOptions>(options: TOptions): TOptions {
|
|
5
|
+
return { ...options, disabledPaths: [...(options.disabledPaths ?? []), "/delete-user", "/delete-user/callback", "/admin/remove-user"] };
|
|
6
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import type { BetterAuthOptions } from "better-auth";
|
|
2
|
+
import { getAuthTables } from "better-auth/db";
|
|
3
|
+
import { Effect, Option, Schema } from "effect";
|
|
4
|
+
import { SqlClient, SqlSchema } from "effect/sql";
|
|
5
|
+
import { BadRequest, PreconditionFailed } from "@shivaedev/errors/taxonomy.ts";
|
|
6
|
+
import { SessionUser } from "#identity.ts";
|
|
7
|
+
import { passwordMatches } from "#server/better-auth/adapters/passwordMatches.ts";
|
|
8
|
+
|
|
9
|
+
// Better Auth's own limit when the options set none; a longer input is refused before it reaches the hash.
|
|
10
|
+
const MAX_PASSWORD_LENGTH = 128;
|
|
11
|
+
|
|
12
|
+
const Credential = Schema.Struct({ password: Schema.String });
|
|
13
|
+
|
|
14
|
+
export const confirmPassword = Effect.fn("Identity.confirmPassword")(function* (options: BetterAuthOptions, password: string) {
|
|
15
|
+
const { id: userId } = yield* SessionUser;
|
|
16
|
+
const { account } = getAuthTables(options);
|
|
17
|
+
const sql = (yield* SqlClient.SqlClient).withoutTransforms();
|
|
18
|
+
function column(field: "password" | "providerId" | "userId") {
|
|
19
|
+
return sql(account?.fields[field]?.fieldName ?? field);
|
|
20
|
+
}
|
|
21
|
+
const credential = yield* SqlSchema.findOneOption({
|
|
22
|
+
execute: (id) => sql`select ${column("password")} as password from ${sql(account?.modelName ?? "account")}
|
|
23
|
+
where ${column("userId")} = ${id} and ${column("providerId")} = 'credential' and ${column("password")} is not null`,
|
|
24
|
+
Request: Schema.String,
|
|
25
|
+
Result: Credential,
|
|
26
|
+
})(userId);
|
|
27
|
+
if (Option.isNone(credential)) {
|
|
28
|
+
return yield* new PreconditionFailed({ message: "This account has no password to confirm its deletion with." });
|
|
29
|
+
}
|
|
30
|
+
const maximum = options.emailAndPassword?.maxPasswordLength ?? MAX_PASSWORD_LENGTH;
|
|
31
|
+
if (password.length === 0 || password.length > maximum) {
|
|
32
|
+
return yield* new BadRequest({ field: "password", message: "Enter your current password." });
|
|
33
|
+
}
|
|
34
|
+
if (!(yield* passwordMatches(options, credential.value.password, password))) {
|
|
35
|
+
return yield* new BadRequest({ field: "password", message: "The password is incorrect." });
|
|
36
|
+
}
|
|
37
|
+
});
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { Effect } from "effect";
|
|
2
|
+
import { invalidationKeys } from "@shivaedev/changes/keys.ts";
|
|
3
|
+
import { invalidateOnCommit, transact } from "@shivaedev/sql/transact.ts";
|
|
4
|
+
import { SessionUser } from "#identity.ts";
|
|
5
|
+
import { AccountDeletionPolicy } from "#server/better-auth/AccountDeletionPolicy.ts";
|
|
6
|
+
import { accountData } from "#server/better-auth/accountData.ts";
|
|
7
|
+
import { confirmPassword } from "#server/better-auth/confirmPassword.ts";
|
|
8
|
+
import { deleteUserRows } from "#server/better-auth/deleteUserRows.ts";
|
|
9
|
+
import { sessionKeys } from "#signedInSessions.ts";
|
|
10
|
+
import { userKeys } from "#users.ts";
|
|
11
|
+
|
|
12
|
+
// An erase that cannot run is the operator's to fix, so its failure is reported with its tables rather than answered to the person.
|
|
13
|
+
export const deleteAccount = Effect.fn("Identity.deleteAccount")(function* (password: string) {
|
|
14
|
+
const { id } = yield* SessionUser;
|
|
15
|
+
const { auth, handOver } = yield* AccountDeletionPolicy;
|
|
16
|
+
yield* confirmPassword(auth.options, password);
|
|
17
|
+
yield* Effect.gen(function* () {
|
|
18
|
+
yield* handOver(id);
|
|
19
|
+
yield* accountData(auth)
|
|
20
|
+
.eraseOwnedRows(id)
|
|
21
|
+
.pipe(Effect.catchTags({ OwnedModelsUncollected: Effect.die, OwnedTableCycle: Effect.die, UncoveredUserColumns: Effect.die }));
|
|
22
|
+
yield* deleteUserRows(auth.options);
|
|
23
|
+
yield* invalidateOnCommit(invalidationKeys([userKeys.item(id), sessionKeys.list]));
|
|
24
|
+
}).pipe(transact());
|
|
25
|
+
});
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { BetterAuthOptions } from "better-auth";
|
|
2
|
+
import { getAuthTables } from "better-auth/db";
|
|
3
|
+
import { Effect } from "effect";
|
|
4
|
+
import { SqlClient } from "effect/sql";
|
|
5
|
+
import { SessionUser } from "#identity.ts";
|
|
6
|
+
|
|
7
|
+
// Better Auth's session and account tables cascade from the user row, so one delete removes the person's sign-ins with it.
|
|
8
|
+
// Verification rows carry no key to the user, so these are the exact identifiers Better Auth 1.7 writes for one person: the user id
|
|
9
|
+
// as a reset or deletion token's value, the address in an email code's identifier, and the id leading a change-email or two-factor code's.
|
|
10
|
+
const ADDRESS_CODES = ["email-verification", "sign-in", "forget-password"];
|
|
11
|
+
export const deleteUserRows = Effect.fn("Identity.deleteUserRows")(function* (options: BetterAuthOptions) {
|
|
12
|
+
const { email, id } = yield* SessionUser;
|
|
13
|
+
const { user, verification } = getAuthTables(options);
|
|
14
|
+
const sql = (yield* SqlClient.SqlClient).withoutTransforms();
|
|
15
|
+
const identifier = sql(verification?.fields.identifier?.fieldName ?? "identifier");
|
|
16
|
+
const value = sql(verification?.fields.value?.fieldName ?? "value");
|
|
17
|
+
const codes = ADDRESS_CODES.map((type) => `${type}-otp-${email}`);
|
|
18
|
+
yield* sql`delete from ${sql(verification?.modelName ?? "verification")} where ${value} = ${id} or ${identifier} in ${sql.in(codes)}
|
|
19
|
+
or starts_with(${identifier}, ${`change-email-otp-${id}:`}) or starts_with(${identifier}, ${`2fa-otp-${id}!`})`;
|
|
20
|
+
yield* sql`delete from ${sql(user?.modelName ?? "user")} where id = ${id}`;
|
|
21
|
+
});
|
|
@@ -22,6 +22,7 @@ import { roleSeedOptions } from "#server/better-auth/adapters/roleSeedOptions.ts
|
|
|
22
22
|
import { fromStorage, type PolicyStorage, type SignInPolicy, signInGate } from "#server/better-auth/adapters/signInGate.ts";
|
|
23
23
|
import { signInPolicyOptions } from "#server/better-auth/adapters/signInPolicyOptions.ts";
|
|
24
24
|
import { changeHooks } from "#server/better-auth/changeHooks.ts";
|
|
25
|
+
import { closeAccountDeletion } from "#server/better-auth/closeAccountDeletion.ts";
|
|
25
26
|
import { closeRoleEndpoints } from "#server/better-auth/closeRoleEndpoints.ts";
|
|
26
27
|
import type { BetterAuthDatabaseHooks } from "#server/better-auth/databaseHooks.ts";
|
|
27
28
|
import type { AuthDeclaration } from "#server/better-auth/define.ts";
|
|
@@ -73,7 +74,8 @@ const mountAuth = Effect.fn("Identity.mountAuth")(function* <const TOptions exte
|
|
|
73
74
|
const reset = passwordResetOptions(preferences, mount.onPasswordReset, runtime);
|
|
74
75
|
const announced = effectHookOptions(yield* emailOptions(reset, mount.emails, runtime), changeHooks, runtime);
|
|
75
76
|
const hooked = effectHookOptions(announced, mount.databaseHooks, runtime);
|
|
76
|
-
const
|
|
77
|
+
const closed = closeAccountDeletion(hooked);
|
|
78
|
+
const configured = declaration.roles === undefined ? closed : storedRoleOptions(closeRoleEndpoints(closed), declaration);
|
|
77
79
|
const gated = yield* signInPolicyOptions(configured, gate, (): Promise<PolicyStorage> => auth.$context);
|
|
78
80
|
const seed = mount.roleSeed === undefined ? undefined : yield* mount.roleSeed;
|
|
79
81
|
const seeded = roleSeedOptions(gate.active ? { ...configured, ...gated } : configured, seed);
|