@softure-ai/auth 0.1.5 → 0.1.7
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 +15 -0
- package/README.md +130 -21
- package/dist/contract.d.ts +3 -1
- package/dist/contract.d.ts.map +1 -1
- package/dist/contract.js.map +1 -1
- package/dist/index.d.ts +6 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -2
- package/dist/index.js.map +1 -1
- package/dist/messages/en.d.ts +1 -0
- package/dist/messages/en.d.ts.map +1 -1
- package/dist/messages/en.js +1 -0
- package/dist/messages/en.js.map +1 -1
- package/dist/messages/index.d.ts +2 -0
- package/dist/messages/index.d.ts.map +1 -1
- package/dist/messages/pl.d.ts.map +1 -1
- package/dist/messages/pl.js +1 -0
- package/dist/messages/pl.js.map +1 -1
- package/dist/next/actions.d.ts +1 -1
- package/dist/next/actions.d.ts.map +1 -1
- package/dist/next/actions.js +37 -16
- package/dist/next/actions.js.map +1 -1
- package/dist/next/context.js +2 -2
- package/dist/next/context.js.map +1 -1
- package/dist/next/index.d.ts +1 -1
- package/dist/next/index.d.ts.map +1 -1
- package/dist/next/index.js +1 -1
- package/dist/next/index.js.map +1 -1
- package/dist/next/pages.d.ts +13 -0
- package/dist/next/pages.d.ts.map +1 -1
- package/dist/next/pages.js +28 -2
- package/dist/next/pages.js.map +1 -1
- package/dist/next/session-cookie.d.ts +3 -0
- package/dist/next/session-cookie.d.ts.map +1 -1
- package/dist/next/session-cookie.js +39 -2
- package/dist/next/session-cookie.js.map +1 -1
- package/dist/options.d.ts +10 -1
- package/dist/options.d.ts.map +1 -1
- package/dist/options.js +44 -3
- package/dist/options.js.map +1 -1
- package/dist/proxy/index.d.ts +5 -0
- package/dist/proxy/index.d.ts.map +1 -1
- package/dist/proxy/index.js +25 -7
- package/dist/proxy/index.js.map +1 -1
- package/dist/safe-next-path.d.ts +3 -1
- package/dist/safe-next-path.d.ts.map +1 -1
- package/dist/safe-next-path.js +9 -3
- package/dist/safe-next-path.js.map +1 -1
- package/dist/scripts/index.d.ts +1 -0
- package/dist/scripts/index.d.ts.map +1 -1
- package/dist/scripts/index.js +3 -1
- package/dist/scripts/index.js.map +1 -1
- package/dist/scripts/temporary-password.d.ts +12 -0
- package/dist/scripts/temporary-password.d.ts.map +1 -0
- package/dist/scripts/temporary-password.js +47 -0
- package/dist/scripts/temporary-password.js.map +1 -0
- package/dist/server/change-password.d.ts +1 -1
- package/dist/server/change-password.d.ts.map +1 -1
- package/dist/server/change-password.js +4 -1
- package/dist/server/change-password.js.map +1 -1
- package/dist/server/index.d.ts +2 -2
- package/dist/server/index.d.ts.map +1 -1
- package/dist/server/index.js +2 -2
- package/dist/server/index.js.map +1 -1
- package/dist/server/login.js +5 -4
- package/dist/server/login.js.map +1 -1
- package/dist/server/options.d.ts +2 -0
- package/dist/server/options.d.ts.map +1 -1
- package/dist/server/options.js +14 -0
- package/dist/server/options.js.map +1 -1
- package/dist/server/password.d.ts +10 -3
- package/dist/server/password.d.ts.map +1 -1
- package/dist/server/password.js +24 -8
- package/dist/server/password.js.map +1 -1
- package/dist/server/rate-limits.d.ts +3 -2
- package/dist/server/rate-limits.d.ts.map +1 -1
- package/dist/server/rate-limits.js +9 -3
- package/dist/server/rate-limits.js.map +1 -1
- package/dist/server/register.d.ts +2 -0
- package/dist/server/register.d.ts.map +1 -1
- package/dist/server/register.js +13 -1
- package/dist/server/register.js.map +1 -1
- package/dist/server/session-token.d.ts +6 -2
- package/dist/server/session-token.d.ts.map +1 -1
- package/dist/server/session-token.js +7 -3
- package/dist/server/session-token.js.map +1 -1
- package/dist/server/sessions.d.ts +9 -0
- package/dist/server/sessions.d.ts.map +1 -1
- package/dist/server/sessions.js +13 -4
- package/dist/server/sessions.js.map +1 -1
- package/dist/testing/account.d.ts +17 -0
- package/dist/testing/account.d.ts.map +1 -0
- package/dist/testing/account.js +31 -0
- package/dist/testing/account.js.map +1 -0
- package/dist/testing/index.d.ts +2 -0
- package/dist/testing/index.d.ts.map +1 -0
- package/dist/testing/index.js +4 -0
- package/dist/testing/index.js.map +1 -0
- package/dist/ui/auth-forms.d.ts +14 -7
- package/dist/ui/auth-forms.d.ts.map +1 -1
- package/dist/ui/auth-forms.js +14 -12
- package/dist/ui/auth-forms.js.map +1 -1
- package/module.json +2 -2
- package/package.json +15 -3
- package/src/contract.ts +3 -0
- package/src/index.ts +2 -2
- package/src/messages/en.ts +1 -0
- package/src/messages/pl.ts +1 -0
- package/src/next/actions.ts +38 -14
- package/src/next/context.ts +2 -2
- package/src/next/index.ts +10 -1
- package/src/next/pages.tsx +44 -0
- package/src/next/session-cookie.ts +42 -2
- package/src/options.ts +49 -3
- package/src/proxy/index.ts +35 -8
- package/src/safe-next-path.ts +9 -3
- package/src/scripts/index.ts +7 -1
- package/src/scripts/temporary-password.ts +62 -0
- package/src/server/change-password.ts +4 -1
- package/src/server/index.ts +10 -2
- package/src/server/login.ts +5 -5
- package/src/server/options.ts +15 -0
- package/src/server/password.ts +26 -8
- package/src/server/rate-limits.ts +10 -3
- package/src/server/register.ts +16 -1
- package/src/server/session-token.ts +7 -3
- package/src/server/sessions.ts +19 -4
- package/src/testing/account.ts +43 -0
- package/src/testing/index.ts +3 -0
- package/src/ui/auth-forms.tsx +26 -7
|
@@ -12,4 +12,13 @@ export declare function logoutSession(ctx: AuthContext, token: string): Promise<
|
|
|
12
12
|
export declare function pruneSessions(ctx: AuthContext): Promise<number>;
|
|
13
13
|
/** Deletes the expired sessions of one user (at their login, so rows do not pile up without a job). */
|
|
14
14
|
export declare function deleteExpiredSessions(ctx: AuthContext, userId: string): Promise<void>;
|
|
15
|
+
export interface RevokeUserSessionsOptions {
|
|
16
|
+
/** A session token to keep, e.g. the one of the admin acting on their own account. */
|
|
17
|
+
readonly except?: string;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Ends every session of `userId` (all but `except`), e.g. after an account recovery or a suspected
|
|
21
|
+
* leak; each device must log in again. Returns how many sessions were ended.
|
|
22
|
+
*/
|
|
23
|
+
export declare function revokeUserSessions(ctx: AuthContext, userId: string, options?: RevokeUserSessionsOptions): Promise<number>;
|
|
15
24
|
//# sourceMappingURL=sessions.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sessions.d.ts","sourceRoot":"","sources":["../../src/server/sessions.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AACtD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAEhD,OAAO,KAAK,EAAE,QAAQ,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAK3D,MAAM,MAAM,WAAW,GAAG,aAAa,CAAC,SAAS,CAAC,CAAC;AAInD,6EAA6E;AAC7E,wBAAsB,aAAa,CAAC,GAAG,EAAE,WAAW,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,UAAU,CAAC,CAMzF;AAED,sFAAsF;AACtF,wBAAsB,eAAe,CAAC,GAAG,EAAE,WAAW,EAAE,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,QAAQ,GAAG,IAAI,CAAC,CAS/F;AAED,uFAAuF;AACvF,wBAAsB,aAAa,CAAC,GAAG,EAAE,WAAW,EAAE,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAGlF;AAED,yFAAyF;AACzF,wBAAsB,aAAa,CAAC,GAAG,EAAE,WAAW,GAAG,OAAO,CAAC,MAAM,CAAC,CAGrE;AAED,uGAAuG;AACvG,wBAAsB,qBAAqB,CAAC,GAAG,EAAE,WAAW,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAE3F"}
|
|
1
|
+
{"version":3,"file":"sessions.d.ts","sourceRoot":"","sources":["../../src/server/sessions.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AACtD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAEhD,OAAO,KAAK,EAAE,QAAQ,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAK3D,MAAM,MAAM,WAAW,GAAG,aAAa,CAAC,SAAS,CAAC,CAAC;AAInD,6EAA6E;AAC7E,wBAAsB,aAAa,CAAC,GAAG,EAAE,WAAW,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,UAAU,CAAC,CAMzF;AAED,sFAAsF;AACtF,wBAAsB,eAAe,CAAC,GAAG,EAAE,WAAW,EAAE,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,QAAQ,GAAG,IAAI,CAAC,CAS/F;AAED,uFAAuF;AACvF,wBAAsB,aAAa,CAAC,GAAG,EAAE,WAAW,EAAE,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAGlF;AAED,yFAAyF;AACzF,wBAAsB,aAAa,CAAC,GAAG,EAAE,WAAW,GAAG,OAAO,CAAC,MAAM,CAAC,CAGrE;AAED,uGAAuG;AACvG,wBAAsB,qBAAqB,CAAC,GAAG,EAAE,WAAW,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAE3F;AAED,MAAM,WAAW,yBAAyB;IACxC,sFAAsF;IACtF,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC;CAC1B;AAED;;;GAGG;AACH,wBAAsB,kBAAkB,CAAC,GAAG,EAAE,WAAW,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,GAAE,yBAA8B,GAAG,OAAO,CAAC,MAAM,CAAC,CAInI"}
|
package/dist/server/sessions.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { and, eq, gt, lte } from "drizzle-orm";
|
|
1
|
+
import { and, eq, gt, lte, ne } from "drizzle-orm";
|
|
2
2
|
import { sessions, users } from "../schema.js";
|
|
3
|
-
import { getAuthOptions } from "./options.js";
|
|
3
|
+
import { getAuthOptions, getLegacyTokenPattern } from "./options.js";
|
|
4
4
|
import { createSessionToken, hashSessionToken, isSessionTokenShape } from "./session-token.js";
|
|
5
5
|
const DAY_MS = 24 * 60 * 60 * 1000;
|
|
6
6
|
/** Opens a session for `userId`; the returned token goes into the cookie. */
|
|
@@ -13,7 +13,7 @@ export async function createSession(ctx, userId) {
|
|
|
13
13
|
}
|
|
14
14
|
/** The user of a live session, or null for an unknown, malformed or expired token. */
|
|
15
15
|
export async function findSessionUser(ctx, token) {
|
|
16
|
-
if (!isSessionTokenShape(token))
|
|
16
|
+
if (!isSessionTokenShape(token, getLegacyTokenPattern(ctx.config)))
|
|
17
17
|
return null;
|
|
18
18
|
const [row] = await ctx.db
|
|
19
19
|
.select({ id: users.id, email: users.email, createdAt: users.createdAt })
|
|
@@ -25,7 +25,7 @@ export async function findSessionUser(ctx, token) {
|
|
|
25
25
|
}
|
|
26
26
|
/** Ends one session. An unknown token is already logged out, so it is not an error. */
|
|
27
27
|
export async function logoutSession(ctx, token) {
|
|
28
|
-
if (!isSessionTokenShape(token))
|
|
28
|
+
if (!isSessionTokenShape(token, getLegacyTokenPattern(ctx.config)))
|
|
29
29
|
return;
|
|
30
30
|
await ctx.db.delete(sessions).where(eq(sessions.tokenHash, hashSessionToken(token)));
|
|
31
31
|
}
|
|
@@ -38,4 +38,13 @@ export async function pruneSessions(ctx) {
|
|
|
38
38
|
export async function deleteExpiredSessions(ctx, userId) {
|
|
39
39
|
await ctx.db.delete(sessions).where(and(eq(sessions.userId, userId), lte(sessions.expiresAt, ctx.clock.now())));
|
|
40
40
|
}
|
|
41
|
+
/**
|
|
42
|
+
* Ends every session of `userId` (all but `except`), e.g. after an account recovery or a suspected
|
|
43
|
+
* leak; each device must log in again. Returns how many sessions were ended.
|
|
44
|
+
*/
|
|
45
|
+
export async function revokeUserSessions(ctx, userId, options = {}) {
|
|
46
|
+
const kept = options.except === undefined ? undefined : ne(sessions.tokenHash, hashSessionToken(options.except));
|
|
47
|
+
const deleted = await ctx.db.delete(sessions).where(and(eq(sessions.userId, userId), kept)).returning();
|
|
48
|
+
return deleted.length;
|
|
49
|
+
}
|
|
41
50
|
//# sourceMappingURL=sessions.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sessions.js","sourceRoot":"","sources":["../../src/server/sessions.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,GAAG,EAAE,EAAE,EAAE,EAAE,EAAE,GAAG,EAAE,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"sessions.js","sourceRoot":"","sources":["../../src/server/sessions.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,GAAG,EAAE,EAAE,EAAE,EAAE,EAAE,GAAG,EAAE,EAAE,EAAE,MAAM,aAAa,CAAC;AAEnD,OAAO,EAAE,QAAQ,EAAE,KAAK,EAAE,MAAM,cAAc,CAAC;AAC/C,OAAO,EAAE,cAAc,EAAE,qBAAqB,EAAE,MAAM,cAAc,CAAC;AACrE,OAAO,EAAE,kBAAkB,EAAE,gBAAgB,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAC;AAI/F,MAAM,MAAM,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC;AAEnC,6EAA6E;AAC7E,MAAM,CAAC,KAAK,UAAU,aAAa,CAAC,GAAgB,EAAE,MAAc;IAClE,MAAM,GAAG,GAAG,GAAG,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC;IAC5B,MAAM,SAAS,GAAG,IAAI,IAAI,CAAC,GAAG,CAAC,OAAO,EAAE,GAAG,cAAc,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,OAAO,CAAC,OAAO,GAAG,MAAM,CAAC,CAAC;IAChG,MAAM,EAAE,KAAK,EAAE,SAAS,EAAE,GAAG,kBAAkB,EAAE,CAAC;IAClD,MAAM,GAAG,CAAC,EAAE,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC,MAAM,CAAC,EAAE,SAAS,EAAE,MAAM,EAAE,SAA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@@
|
|
|
1
|
+
import type { Queryable } from "@softure-ai/db";
|
|
2
|
+
import type { AuthUser } from "../contract.js";
|
|
3
|
+
import { type ScryptParams } from "../options.js";
|
|
4
|
+
export interface TestAccountInput {
|
|
5
|
+
readonly email: string;
|
|
6
|
+
readonly password: string;
|
|
7
|
+
/** Rows of `auth.user_roles`, e.g. `["admin"]`. */
|
|
8
|
+
readonly roles?: readonly string[];
|
|
9
|
+
/** The app's hash parameters (`getAuthOptions(config).password.scrypt`), so its login does not rehash. */
|
|
10
|
+
readonly scrypt?: ScryptParams;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Creates an account and its roles in one transaction and returns it. The email is normalized as
|
|
14
|
+
* registration normalizes it. An invalid or taken email throws: in test setup it is a bug of the test.
|
|
15
|
+
*/
|
|
16
|
+
export declare function createTestAccount(db: Queryable, input: TestAccountInput): Promise<AuthUser>;
|
|
17
|
+
//# sourceMappingURL=account.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"account.d.ts","sourceRoot":"","sources":["../../src/testing/account.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAChD,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAC/C,OAAO,EAAuB,KAAK,YAAY,EAAE,MAAM,eAAe,CAAC;AAQvE,MAAM,WAAW,gBAAgB;IAC/B,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,mDAAmD;IACnD,QAAQ,CAAC,KAAK,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;IACnC,0GAA0G;IAC1G,QAAQ,CAAC,MAAM,CAAC,EAAE,YAAY,CAAC;CAChC;AAED;;;GAGG;AACH,wBAAsB,iBAAiB,CAAC,EAAE,EAAE,SAAS,EAAE,KAAK,EAAE,gBAAgB,GAAG,OAAO,CAAC,QAAQ,CAAC,CAiBjG"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { DEFAULT_SCRYPT_COST } from "../options.js";
|
|
2
|
+
import { userRoles, users } from "../schema.js";
|
|
3
|
+
import { hashPassword } from "../server/password.js";
|
|
4
|
+
import { parseEmail } from "../server/validation.js";
|
|
5
|
+
/** Auth's own hash parameters when the app sets none (`password.scrypt` in `auth({ ... })`). */
|
|
6
|
+
const DEFAULT_SCRYPT = { cost: DEFAULT_SCRYPT_COST, blockSize: 8, parallelization: 1 };
|
|
7
|
+
/**
|
|
8
|
+
* Creates an account and its roles in one transaction and returns it. The email is normalized as
|
|
9
|
+
* registration normalizes it. An invalid or taken email throws: in test setup it is a bug of the test.
|
|
10
|
+
*/
|
|
11
|
+
export async function createTestAccount(db, input) {
|
|
12
|
+
const email = parseEmail(input.email);
|
|
13
|
+
if (!email.ok)
|
|
14
|
+
throw new Error(`createTestAccount: "${input.email}" is not a valid email`);
|
|
15
|
+
const passwordHash = await hashPassword(input.password, input.scrypt ?? DEFAULT_SCRYPT);
|
|
16
|
+
const now = new Date();
|
|
17
|
+
return db.transaction(async (tx) => {
|
|
18
|
+
const [row] = await tx
|
|
19
|
+
.insert(users)
|
|
20
|
+
.values({ email: email.value, passwordHash, createdAt: now, passwordChangedAt: now })
|
|
21
|
+
.onConflictDoNothing({ target: users.email })
|
|
22
|
+
.returning();
|
|
23
|
+
if (row === undefined)
|
|
24
|
+
throw new Error(`createTestAccount: an account with the email "${email.value}" already exists`);
|
|
25
|
+
const roles = input.roles ?? [];
|
|
26
|
+
if (roles.length > 0)
|
|
27
|
+
await tx.insert(userRoles).values(roles.map((role) => ({ userId: row.id, role, grantedAt: now })));
|
|
28
|
+
return { id: row.id, email: row.email, createdAt: row.createdAt };
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
//# sourceMappingURL=account.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"account.js","sourceRoot":"","sources":["../../src/test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kBAAkB,CAAC,CAAC;QACvH,MAAM,KAAK,GAAG,KAAK,CAAC,KAAK,IAAI,EAAE,CAAC;QAChC,IAAI,KAAK,CAAC,MAAM,GAAG,CAAC;YAAE,MAAM,EAAE,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC,EAAE,MAAM,EAAE,GAAG,CAAC,EAAE,EAAE,IAAI,EAAE,SAAS,EAAE,GAAG,EAAE,CAAC,CAAC,CAAC,CAAC;QACzH,OAAO,EAAE,EAAE,EAAE,GAAG,CAAC,EAAE,EAAE,KAAK,EAAE,GAAG,CAAC,KAAK,EAAE,SAAS,EAAE,GAAG,CAAC,SAAS,EAAE,CAAC;IACpE,CAAC,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/testing/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,iBAAiB,EAAE,KAAK,gBAAgB,EAAE,MAAM,cAAc,CAAC"}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
// Test helpers of @softure-ai/auth: accounts created directly in the database, for tests that need
|
|
2
|
+
// a user but are not about registration. Server-only; never imported by the module's runtime code.
|
|
3
|
+
export { createTestAccount } from "./account.js";
|
|
4
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/testing/index.ts"],"names":[],"mappings":"AAAA,mGAAmG;AACnG,mGAAmG;AACnG,OAAO,EAAE,iBAAiB,EAAyB,MAAM,cAAc,CAAC"}
|
package/dist/ui/auth-forms.d.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { type Locale } from "@softure-ai/core";
|
|
2
|
-
import { type ClassNames } from "@softure-ai/ui";
|
|
2
|
+
import { type ButtonVariant, type ClassNames } from "@softure-ai/ui";
|
|
3
3
|
import { type ReactNode } from "react";
|
|
4
4
|
import { type AuthFormState } from "../contract.js";
|
|
5
5
|
import { type AuthMessages } from "../messages/index.js";
|
|
6
6
|
export type AuthFormAction = (previous: AuthFormState, formData: FormData) => Promise<AuthFormState>;
|
|
7
|
-
export type AuthFormSlot = "root" | "form" | "footer" | "link" | "notice";
|
|
7
|
+
export type AuthFormSlot = "root" | "form" | "footer" | "link" | "notice" | "submit";
|
|
8
8
|
interface AuthFormBaseProps {
|
|
9
9
|
readonly action: AuthFormAction;
|
|
10
10
|
readonly messages: AuthMessages;
|
|
@@ -12,6 +12,8 @@ interface AuthFormBaseProps {
|
|
|
12
12
|
readonly locale?: Locale;
|
|
13
13
|
readonly classNames?: ClassNames<AuthFormSlot>;
|
|
14
14
|
readonly unstyled?: boolean;
|
|
15
|
+
/** The submit button's look; `primary` by default. Its class goes in `classNames.submit`. */
|
|
16
|
+
readonly submitVariant?: ButtonVariant;
|
|
15
17
|
}
|
|
16
18
|
export interface LoginFormProps extends AuthFormBaseProps {
|
|
17
19
|
/** Where to go after login; checked again on the server. */
|
|
@@ -23,7 +25,7 @@ export interface LoginFormProps extends AuthFormBaseProps {
|
|
|
23
25
|
/** A confirmation shown under the form, e.g. after a password reset. */
|
|
24
26
|
readonly notice?: string;
|
|
25
27
|
}
|
|
26
|
-
export declare function LoginForm({ action, messages, locale, next, registerHref, forgotPasswordHref, notice, classNames, unstyled }: LoginFormProps): import("react").JSX.Element;
|
|
28
|
+
export declare function LoginForm({ action, messages, locale, next, registerHref, forgotPasswordHref, notice, classNames, unstyled, submitVariant }: LoginFormProps): import("react").JSX.Element;
|
|
27
29
|
export interface RegisterFormProps extends AuthFormBaseProps {
|
|
28
30
|
readonly next?: string;
|
|
29
31
|
readonly loginHref?: string;
|
|
@@ -33,25 +35,30 @@ export interface RegisterFormProps extends AuthFormBaseProps {
|
|
|
33
35
|
readonly minPasswordLength: number;
|
|
34
36
|
/** The consent statement; may contain links to the terms. Defaults to `messages.fields.consent`. */
|
|
35
37
|
readonly consentLabel?: ReactNode;
|
|
38
|
+
/**
|
|
39
|
+
* The app's own inputs, before the consent checkbox. Their values reach `onRegistered` as
|
|
40
|
+
* `event.fields` when their names are declared in `auth({ registrationFields })`.
|
|
41
|
+
*/
|
|
42
|
+
readonly extraFields?: ReactNode;
|
|
36
43
|
}
|
|
37
|
-
export declare function RegisterForm({ action, messages, locale, next, loginHref, requireConsent, minPasswordLength, consentLabel, classNames, unstyled, }: RegisterFormProps): import("react").JSX.Element;
|
|
44
|
+
export declare function RegisterForm({ action, messages, locale, next, loginHref, requireConsent, minPasswordLength, consentLabel, extraFields, classNames, unstyled, submitVariant, }: RegisterFormProps): import("react").JSX.Element;
|
|
38
45
|
export interface ChangePasswordFormProps extends AuthFormBaseProps {
|
|
39
46
|
readonly minPasswordLength: number;
|
|
40
47
|
}
|
|
41
|
-
export declare function ChangePasswordForm({ action, messages, locale, minPasswordLength, classNames, unstyled }: ChangePasswordFormProps): import("react").JSX.Element;
|
|
48
|
+
export declare function ChangePasswordForm({ action, messages, locale, minPasswordLength, classNames, unstyled, submitVariant }: ChangePasswordFormProps): import("react").JSX.Element;
|
|
42
49
|
export interface ForgotPasswordFormProps extends AuthFormBaseProps {
|
|
43
50
|
/** How long a link works, for the confirmation. */
|
|
44
51
|
readonly ttlMinutes: number;
|
|
45
52
|
readonly loginHref?: string;
|
|
46
53
|
}
|
|
47
54
|
/** Asks for a reset link. Its confirmation is the same whether or not the email has an account. */
|
|
48
|
-
export declare function ForgotPasswordForm({ action, messages, locale, ttlMinutes, loginHref, classNames, unstyled }: ForgotPasswordFormProps): import("react").JSX.Element;
|
|
55
|
+
export declare function ForgotPasswordForm({ action, messages, locale, ttlMinutes, loginHref, classNames, unstyled, submitVariant }: ForgotPasswordFormProps): import("react").JSX.Element;
|
|
49
56
|
export interface ResetPasswordFormProps extends AuthFormBaseProps {
|
|
50
57
|
/** The token from the reset link; checked again on the server. */
|
|
51
58
|
readonly token: string;
|
|
52
59
|
readonly minPasswordLength: number;
|
|
53
60
|
}
|
|
54
61
|
/** Sets a new password from a reset link; its action goes to the login page on success. */
|
|
55
|
-
export declare function ResetPasswordForm({ action, messages, locale, token, minPasswordLength, classNames, unstyled }: ResetPasswordFormProps): import("react").JSX.Element;
|
|
62
|
+
export declare function ResetPasswordForm({ action, messages, locale, token, minPasswordLength, classNames, unstyled, submitVariant }: ResetPasswordFormProps): import("react").JSX.Element;
|
|
56
63
|
export {};
|
|
57
64
|
//# sourceMappingURL=auth-forms.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"auth-forms.d.ts","sourceRoot":"","sources":["../../src/ui/auth-forms.tsx"],"names":[],"mappings":"AAEA,OAAO,EAAiB,KAAK,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAC9D,OAAO,
|
|
1
|
+
{"version":3,"file":"auth-forms.d.ts","sourceRoot":"","sources":["../../src/ui/auth-forms.tsx"],"names":[],"mappings":"AAEA,OAAO,EAAiB,KAAK,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAC9D,OAAO,EAAU,KAAK,aAAa,EAAY,KAAK,UAAU,EAA8D,MAAM,gBAAgB,CAAC;AACnJ,OAAO,EAAE,KAAK,SAAS,EAAkB,MAAM,OAAO,CAAC;AACvD,OAAO,EAAsB,KAAK,aAAa,EAA2B,MAAM,gBAAgB,CAAC;AACjG,OAAO,EAAE,KAAK,YAAY,EAAuB,MAAM,sBAAsB,CAAC;AAM9E,MAAM,MAAM,cAAc,GAAG,CAAC,QAAQ,EAAE,aAAa,EAAE,QAAQ,EAAE,QAAQ,KAAK,OAAO,CAAC,aAAa,CAAC,CAAC;AAErG,MAAM,MAAM,YAAY,GAAG,MAAM,GAAG,MAAM,GAAG,QAAQ,GAAG,MAAM,GAAG,QAAQ,GAAG,QAAQ,CAAC;AAErF,UAAU,iBAAiB;IACzB,QAAQ,CAAC,MAAM,EAAE,cAAc,CAAC;IAChC,QAAQ,CAAC,QAA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,SAAS,EACT,cAAc,EACd,iBAAiB,EACjB,YAAY,EACZ,WAAW,EACX,UAAU,EACV,QAAQ,EACR,aAAa,GACd,EAAE,iBAAiB,+BAqDnB;AAED,MAAM,WAAW,uBAAwB,SAAQ,iBAAiB;IAChE,QAAQ,CAAC,iBAAiB,EAAE,MAAM,CAAC;CACpC;AAED,wBAAgB,kBAAkB,CAAC,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,iBAAiB,EAAE,UAAU,EAAE,QAAQ,EAAE,aAAa,EAAE,EAAE,uBAAuB,+BA0C/I;AAED,MAAM,WAAW,uBAAwB,SAAQ,iBAAiB;IAChE,mDAAmD;IACnD,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAC5B,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM,CAAC;CAC7B;AAED,mGAAmG;AACnG,wBAAgB,kBAAkB,CAAC,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,UAAU,EAAE,SAAS,EAAE,UAAU,EAAE,QAAQ,EAAE,aAAa,EAAE,EAAE,uBAAuB,+BA+CnJ;AAED,MAAM,WAAW,sBAAuB,SAAQ,iBAAiB;IAC/D,kEAAkE;IAClE,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,iBAAiB,EAAE,MAAM,CAAC;CACpC;AAED,2FAA2F;AAC3F,wBAAgB,iBAAiB,CAAC,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,KAAK,EAAE,iBAAiB,EAAE,UAAU,EAAE,QAAQ,EAAE,aAAa,EAAE,EAAE,sBAAsB,+BA4BpJ"}
|
package/dist/ui/auth-forms.js
CHANGED
|
@@ -11,6 +11,8 @@ const DEFAULT_CLASSES = {
|
|
|
11
11
|
footer: "sft:m-0 sft:text-sm sft:text-muted",
|
|
12
12
|
link: "sft:font-medium sft:text-accent",
|
|
13
13
|
notice: "sft:m-0 sft:text-sm sft:text-success",
|
|
14
|
+
// The button styles itself; the slot only carries the app's class.
|
|
15
|
+
submit: "",
|
|
14
16
|
};
|
|
15
17
|
/** The error of one field, or of the form when no field owns it. */
|
|
16
18
|
function useErrors(state, messages) {
|
|
@@ -20,32 +22,32 @@ function useErrors(state, messages) {
|
|
|
20
22
|
form: state.field === undefined ? message : undefined,
|
|
21
23
|
};
|
|
22
24
|
}
|
|
23
|
-
function FormShell({ formAction, isPending, submitLabel, pendingLabel, formError, footer, slot, unstyled, children, }) {
|
|
24
|
-
return (_jsxs("div", { className: slot("root"), children: [_jsxs("form", { action: formAction, className: slot("form"), children: [children, _jsx(FormError, { message: formError, unstyled: unstyled }), _jsx(Button, { type: "submit", variant:
|
|
25
|
+
function FormShell({ formAction, isPending, submitLabel, pendingLabel, formError, footer, slot, unstyled, submitVariant = "primary", children, }) {
|
|
26
|
+
return (_jsxs("div", { className: slot("root"), children: [_jsxs("form", { action: formAction, className: slot("form"), children: [children, _jsx(FormError, { message: formError, unstyled: unstyled }), _jsx(Button, { type: "submit", variant: submitVariant, fullWidth: true, pending: isPending, classNames: { root: slot("submit") }, unstyled: unstyled, children: isPending ? pendingLabel : submitLabel })] }), footer] }));
|
|
25
27
|
}
|
|
26
|
-
export function LoginForm({ action, messages, locale, next, registerHref, forgotPasswordHref, notice, classNames, unstyled }) {
|
|
28
|
+
export function LoginForm({ action, messages, locale, next, registerHref, forgotPasswordHref, notice, classNames, unstyled, submitVariant }) {
|
|
27
29
|
const [state, formAction, isPending] = useActionState(action, INITIAL_AUTH_FORM_STATE);
|
|
28
30
|
const errors = useErrors(state, messages);
|
|
29
31
|
const slot = createSlotClassGetter({ defaults: DEFAULT_CLASSES, classNames, unstyled });
|
|
30
32
|
const footer = registerHref === undefined && forgotPasswordHref === undefined && notice === undefined ? undefined : (_jsxs(_Fragment, { children: [notice === undefined ? null : (_jsx("p", { role: "status", className: slot("notice"), children: notice })), forgotPasswordHref === undefined ? null : (_jsx("p", { className: slot("footer"), children: _jsx("a", { href: forgotPasswordHref, className: slot("link"), children: messages.login.forgotPassword }) })), registerHref === undefined ? null : (_jsxs("p", { className: slot("footer"), children: [messages.login.noAccount, " ", _jsx("a", { href: registerHref, className: slot("link"), children: messages.login.registerLink })] }))] }));
|
|
31
|
-
return (_jsxs(FormShell, { formAction: formAction, isPending: isPending, submitLabel: messages.login.submit, pendingLabel: messages.login.pending, formError: errors.form, footer: footer, slot: slot, unstyled: unstyled, children: [next === undefined ? null : _jsx("input", { type: "hidden", name: "next", value: next }), _jsx(TextField, { name: "email", type: "email", label: messages.fields.email, autoComplete: "email", required: true, defaultValue: state.email ?? "", error: errors.at("email"), unstyled: unstyled, locale: locale }), _jsx(PasswordField, { name: "password", label: messages.fields.password, autoComplete: "current-password", error: errors.at("password"), unstyled: unstyled, locale: locale })] }));
|
|
33
|
+
return (_jsxs(FormShell, { formAction: formAction, isPending: isPending, submitLabel: messages.login.submit, pendingLabel: messages.login.pending, formError: errors.form, footer: footer, slot: slot, unstyled: unstyled, submitVariant: submitVariant, children: [next === undefined ? null : _jsx("input", { type: "hidden", name: "next", value: next }), _jsx(TextField, { name: "email", type: "email", label: messages.fields.email, autoComplete: "email", required: true, defaultValue: state.email ?? "", error: errors.at("email"), unstyled: unstyled, locale: locale }), _jsx(PasswordField, { name: "password", label: messages.fields.password, autoComplete: "current-password", error: errors.at("password"), unstyled: unstyled, locale: locale })] }));
|
|
32
34
|
}
|
|
33
|
-
export function RegisterForm({ action, messages, locale, next, loginHref, requireConsent, minPasswordLength, consentLabel, classNames, unstyled, }) {
|
|
35
|
+
export function RegisterForm({ action, messages, locale, next, loginHref, requireConsent, minPasswordLength, consentLabel, extraFields, classNames, unstyled, submitVariant, }) {
|
|
34
36
|
const [state, formAction, isPending] = useActionState(action, INITIAL_AUTH_FORM_STATE);
|
|
35
37
|
const errors = useErrors(state, messages);
|
|
36
38
|
const slot = createSlotClassGetter({ defaults: DEFAULT_CLASSES, classNames, unstyled });
|
|
37
39
|
const footer = loginHref === undefined ? undefined : (_jsxs("p", { className: slot("footer"), children: [messages.register.hasAccount, " ", _jsx("a", { href: loginHref, className: slot("link"), children: messages.register.loginLink })] }));
|
|
38
|
-
return (_jsxs(FormShell, { formAction: formAction, isPending: isPending, submitLabel: messages.register.submit, pendingLabel: messages.register.pending, formError: errors.form, footer: footer, slot: slot, unstyled: unstyled, children: [next === undefined ? null : _jsx("input", { type: "hidden", name: "next", value: next }), _jsx(TextField, { name: "email", type: "email", label: messages.fields.email, autoComplete: "email", required: true, defaultValue: state.email ?? "", error: errors.at("email"), unstyled: unstyled, locale: locale }), _jsx(PasswordField, { name: "password", label: messages.fields.password, hint: formatMessage(messages.fields.newPasswordHint, { minLength: minPasswordLength }), autoComplete: "new-password", minLength: minPasswordLength, error: errors.at("password"), unstyled: unstyled, locale: locale }), requireConsent ? (_jsx(Checkbox, { name: "consent", label: consentLabel ?? messages.fields.consent, required: true, error: errors.at("consent"), unstyled: unstyled })) : null] }));
|
|
40
|
+
return (_jsxs(FormShell, { formAction: formAction, isPending: isPending, submitLabel: messages.register.submit, pendingLabel: messages.register.pending, formError: errors.form, footer: footer, slot: slot, unstyled: unstyled, submitVariant: submitVariant, children: [next === undefined ? null : _jsx("input", { type: "hidden", name: "next", value: next }), _jsx(TextField, { name: "email", type: "email", label: messages.fields.email, autoComplete: "email", required: true, defaultValue: state.email ?? "", error: errors.at("email"), unstyled: unstyled, locale: locale }), _jsx(PasswordField, { name: "password", label: messages.fields.password, hint: formatMessage(messages.fields.newPasswordHint, { minLength: minPasswordLength }), autoComplete: "new-password", minLength: minPasswordLength, error: errors.at("password"), unstyled: unstyled, locale: locale }), extraFields, requireConsent ? (_jsx(Checkbox, { name: "consent", label: consentLabel ?? messages.fields.consent, required: true, error: errors.at("consent"), unstyled: unstyled })) : null] }));
|
|
39
41
|
}
|
|
40
|
-
export function ChangePasswordForm({ action, messages, locale, minPasswordLength, classNames, unstyled }) {
|
|
42
|
+
export function ChangePasswordForm({ action, messages, locale, minPasswordLength, classNames, unstyled, submitVariant }) {
|
|
41
43
|
const [state, formAction, isPending] = useActionState(action, INITIAL_AUTH_FORM_STATE);
|
|
42
44
|
const errors = useErrors(state, messages);
|
|
43
45
|
const slot = createSlotClassGetter({ defaults: DEFAULT_CLASSES, classNames, unstyled });
|
|
44
46
|
const notice = state.status === "ok" ? (_jsx("p", { role: "status", className: slot("notice"), children: messages.changePassword.success })) : undefined;
|
|
45
|
-
return (_jsxs(FormShell, { formAction: formAction, isPending: isPending, submitLabel: messages.changePassword.submit, pendingLabel: messages.changePassword.pending, formError: errors.form, footer: notice, slot: slot, unstyled: unstyled, children: [_jsx(PasswordField, { name: "currentPassword", label: messages.fields.currentPassword, autoComplete: "current-password", error: errors.at("currentPassword"), unstyled: unstyled, locale: locale }), _jsx(PasswordField, { name: "newPassword", label: messages.fields.newPassword, hint: formatMessage(messages.fields.newPasswordHint, { minLength: minPasswordLength }), autoComplete: "new-password", minLength: minPasswordLength, error: errors.at("newPassword"), unstyled: unstyled, locale: locale })] }));
|
|
47
|
+
return (_jsxs(FormShell, { formAction: formAction, isPending: isPending, submitLabel: messages.changePassword.submit, pendingLabel: messages.changePassword.pending, formError: errors.form, footer: notice, slot: slot, unstyled: unstyled, submitVariant: submitVariant, children: [_jsx(PasswordField, { name: "currentPassword", label: messages.fields.currentPassword, autoComplete: "current-password", error: errors.at("currentPassword"), unstyled: unstyled, locale: locale }), _jsx(PasswordField, { name: "newPassword", label: messages.fields.newPassword, hint: formatMessage(messages.fields.newPasswordHint, { minLength: minPasswordLength }), autoComplete: "new-password", minLength: minPasswordLength, error: errors.at("newPassword"), unstyled: unstyled, locale: locale })] }));
|
|
46
48
|
}
|
|
47
49
|
/** Asks for a reset link. Its confirmation is the same whether or not the email has an account. */
|
|
48
|
-
export function ForgotPasswordForm({ action, messages, locale, ttlMinutes, loginHref, classNames, unstyled }) {
|
|
50
|
+
export function ForgotPasswordForm({ action, messages, locale, ttlMinutes, loginHref, classNames, unstyled, submitVariant }) {
|
|
49
51
|
const [state, formAction, isPending] = useActionState(action, INITIAL_AUTH_FORM_STATE);
|
|
50
52
|
const errors = useErrors(state, messages);
|
|
51
53
|
const slot = createSlotClassGetter({ defaults: DEFAULT_CLASSES, classNames, unstyled });
|
|
@@ -53,13 +55,13 @@ export function ForgotPasswordForm({ action, messages, locale, ttlMinutes, login
|
|
|
53
55
|
if (state.status === "ok") {
|
|
54
56
|
return (_jsxs("div", { className: slot("root"), children: [_jsx("p", { role: "status", className: slot("notice"), children: formatMessage(messages.forgotPassword.sent, { ttlMinutes }) }), backToLogin] }));
|
|
55
57
|
}
|
|
56
|
-
return (_jsx(FormShell, { formAction: formAction, isPending: isPending, submitLabel: messages.forgotPassword.submit, pendingLabel: messages.forgotPassword.pending, formError: errors.form, footer: backToLogin, slot: slot, unstyled: unstyled, children: _jsx(TextField, { name: "email", type: "email", label: messages.fields.email, autoComplete: "email", required: true, defaultValue: state.email ?? "", error: errors.at("email"), unstyled: unstyled, locale: locale }) }));
|
|
58
|
+
return (_jsx(FormShell, { formAction: formAction, isPending: isPending, submitLabel: messages.forgotPassword.submit, pendingLabel: messages.forgotPassword.pending, formError: errors.form, footer: backToLogin, slot: slot, unstyled: unstyled, submitVariant: submitVariant, children: _jsx(TextField, { name: "email", type: "email", label: messages.fields.email, autoComplete: "email", required: true, defaultValue: state.email ?? "", error: errors.at("email"), unstyled: unstyled, locale: locale }) }));
|
|
57
59
|
}
|
|
58
60
|
/** Sets a new password from a reset link; its action goes to the login page on success. */
|
|
59
|
-
export function ResetPasswordForm({ action, messages, locale, token, minPasswordLength, classNames, unstyled }) {
|
|
61
|
+
export function ResetPasswordForm({ action, messages, locale, token, minPasswordLength, classNames, unstyled, submitVariant }) {
|
|
60
62
|
const [state, formAction, isPending] = useActionState(action, INITIAL_AUTH_FORM_STATE);
|
|
61
63
|
const errors = useErrors(state, messages);
|
|
62
64
|
const slot = createSlotClassGetter({ defaults: DEFAULT_CLASSES, classNames, unstyled });
|
|
63
|
-
return (_jsxs(FormShell, { formAction: formAction, isPending: isPending, submitLabel: messages.resetPassword.submit, pendingLabel: messages.resetPassword.pending, formError: errors.form, slot: slot, unstyled: unstyled, children: [_jsx("input", { type: "hidden", name: "token", value: token }), _jsx(PasswordField, { name: "newPassword", label: messages.fields.newPassword, hint: formatMessage(messages.fields.newPasswordHint, { minLength: minPasswordLength }), autoComplete: "new-password", minLength: minPasswordLength, error: errors.at("newPassword"), unstyled: unstyled, locale: locale })] }));
|
|
65
|
+
return (_jsxs(FormShell, { formAction: formAction, isPending: isPending, submitLabel: messages.resetPassword.submit, pendingLabel: messages.resetPassword.pending, formError: errors.form, slot: slot, unstyled: unstyled, submitVariant: submitVariant, children: [_jsx("input", { type: "hidden", name: "token", value: token }), _jsx(PasswordField, { name: "newPassword", label: messages.fields.newPassword, hint: formatMessage(messages.fields.newPasswordHint, { minLength: minPasswordLength }), autoComplete: "new-password", minLength: minPasswordLength, error: errors.at("newPassword"), unstyled: unstyled, locale: locale })] }));
|
|
64
66
|
}
|
|
65
67
|
//# sourceMappingURL=auth-forms.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"auth-forms.js","sourceRoot":"","sources":["../../src/ui/auth-forms.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAC;;AAEb,OAAO,EAAE,aAAa,EAAe,MAAM,kBAAkB,CAAC;AAC9D,OAAO,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"auth-forms.js","sourceRoot":"","sources":["../../src/ui/auth-forms.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAC;;AAEb,OAAO,EAAE,aAAa,EAAe,MAAM,kBAAkB,CAAC;AAC9D,OAAO,EAAE,MAAM,EAAsB,QAAQ,EAAmB,qBAAqB,EAAE,SAAS,EAAE,aAAa,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AACnJ,OAAO,EAAkB,cAAc,EAAE,MAAM,OAAO,CAAC;AACvD,OAAO,EAA0C,uBAAuB,EAAE,MAAM,gBAAgB,CAAC;AACjG,OAAO,EAAqB,mBA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ACV,QAAQ,EAAE,QAAQ,EAClB,aAAa,EAAE,aAAa,aAE5B,gBAAO,IAAI,EAAC,QAAQ,EAAC,IAAI,EAAC,OAAO,EAAC,KAAK,EAAE,KAAK,GAAI,EAClD,KAAC,aAAa,IACZ,IAAI,EAAC,aAAa,EAClB,KAAK,EAAE,QAAQ,CAAC,MAAM,CAAC,WAAW,EAClC,IAAI,EAAE,aAAa,CAAC,QAAQ,CAAC,MAAM,CAAC,eAAe,EAAE,EAAE,SAAS,EAAE,iBAAiB,EAAE,CAAC,EACtF,YAAY,EAAC,cAAc,EAC3B,SAAS,EAAE,iBAAiB,EAC5B,KAAK,EAAE,MAAM,CAAC,EAAE,CAAC,aAAa,CAAC,EAC/B,QAAQ,EAAE,QAAQ,EAClB,MAAM,EAAE,MAAM,GACd,IACQ,CACb,CAAC;AACJ,CAAC"}
|
package/module.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"id": "auth",
|
|
3
|
-
"version": "0.1.
|
|
4
|
-
"dependsOn": { "security": "^0.1.0" },
|
|
3
|
+
"version": "0.1.7",
|
|
4
|
+
"dependsOn": { "security": "^0.1.0", "mailing": "^0.1.0?", "ops": "^0.1.0?" },
|
|
5
5
|
"dbSchema": "auth",
|
|
6
6
|
"tables": ["users", "sessions", "user_roles", "password_resets"],
|
|
7
7
|
"env": [
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@softure-ai/auth",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.7",
|
|
4
4
|
"description": "SOFTURE AI auth module: users, scrypt passwords, database sessions, register with consent, login, logout, password change, roles, a proxy route guard, pages and forms for Next.js, and a password reset sender over @softure-ai/mailing.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -15,6 +15,7 @@
|
|
|
15
15
|
},
|
|
16
16
|
"files": [
|
|
17
17
|
"dist",
|
|
18
|
+
"CHANGELOG.md",
|
|
18
19
|
"src",
|
|
19
20
|
"!src/**/*.test.ts",
|
|
20
21
|
"!src/**/*.test.tsx",
|
|
@@ -56,6 +57,11 @@
|
|
|
56
57
|
"types": "./dist/scripts/index.d.ts",
|
|
57
58
|
"default": "./dist/scripts/index.js"
|
|
58
59
|
},
|
|
60
|
+
"./testing": {
|
|
61
|
+
"@softure-ai/source": "./src/testing/index.ts",
|
|
62
|
+
"types": "./dist/testing/index.d.ts",
|
|
63
|
+
"default": "./dist/testing/index.js"
|
|
64
|
+
},
|
|
59
65
|
"./ui": {
|
|
60
66
|
"@softure-ai/source": "./src/ui/index.ts",
|
|
61
67
|
"types": "./dist/ui/index.d.ts",
|
|
@@ -68,20 +74,26 @@
|
|
|
68
74
|
"dependencies": {
|
|
69
75
|
"@softure-ai/core": "^0.1.0",
|
|
70
76
|
"@softure-ai/db": "^0.1.0",
|
|
71
|
-
"@softure-ai/ops": "^0.1.0",
|
|
72
77
|
"@softure-ai/security": "^0.1.0",
|
|
73
|
-
"@softure-ai/ui": "^0.1.0",
|
|
74
78
|
"zod": "^4.6.5"
|
|
75
79
|
},
|
|
76
80
|
"peerDependencies": {
|
|
77
81
|
"@softure-ai/mailing": "^0.1.0",
|
|
82
|
+
"@softure-ai/ops": "^0.1.0",
|
|
83
|
+
"@softure-ai/ui": "^0.1.0",
|
|
78
84
|
"drizzle-orm": "^0.45.2",
|
|
79
85
|
"next": "^16.0.0",
|
|
80
86
|
"react": "^19.0.0"
|
|
81
87
|
},
|
|
88
|
+
"devDependencies": {
|
|
89
|
+
"@softure-ai/ui": "^0.1.7"
|
|
90
|
+
},
|
|
82
91
|
"peerDependenciesMeta": {
|
|
83
92
|
"@softure-ai/mailing": {
|
|
84
93
|
"optional": true
|
|
94
|
+
},
|
|
95
|
+
"@softure-ai/ops": {
|
|
96
|
+
"optional": true
|
|
85
97
|
}
|
|
86
98
|
}
|
|
87
99
|
}
|
package/src/contract.ts
CHANGED
|
@@ -12,6 +12,7 @@ export type AuthErrorCode =
|
|
|
12
12
|
| "auth.consent_required"
|
|
13
13
|
| "auth.registration_closed"
|
|
14
14
|
| "auth.current_password_invalid"
|
|
15
|
+
| "auth.password_unchanged"
|
|
15
16
|
| "auth.unauthenticated"
|
|
16
17
|
| "auth.forbidden"
|
|
17
18
|
| "auth.reset_token_invalid"
|
|
@@ -43,6 +44,8 @@ export interface SignedIn {
|
|
|
43
44
|
export interface RegisteredEvent {
|
|
44
45
|
readonly user: AuthUser;
|
|
45
46
|
readonly consent: { readonly acceptedAt: Date } | null;
|
|
47
|
+
/** The declared `registrationFields` the form sent, by name; client input, so validate it. */
|
|
48
|
+
readonly fields: Readonly<Record<string, string>>;
|
|
46
49
|
}
|
|
47
50
|
|
|
48
51
|
/** The fields of the auth forms that can carry their own error. */
|
package/src/index.ts
CHANGED
|
@@ -41,8 +41,8 @@ export const AUTH_RATE_LIMIT_BUCKETS = {
|
|
|
41
41
|
export const auth = defineModule({
|
|
42
42
|
manifest: {
|
|
43
43
|
id: MODULE_ID,
|
|
44
|
-
version: "0.1.
|
|
45
|
-
dependsOn: { security: "^0.1.0" },
|
|
44
|
+
version: "0.1.7",
|
|
45
|
+
dependsOn: { security: "^0.1.0", mailing: "^0.1.0?", ops: "^0.1.0?" },
|
|
46
46
|
dbSchema: "auth",
|
|
47
47
|
tables: ["users", "sessions", "user_roles", "password_resets"],
|
|
48
48
|
env: [
|
package/src/messages/en.ts
CHANGED
|
@@ -74,6 +74,7 @@ export const en = {
|
|
|
74
74
|
consent_required: "You need to accept the terms to create an account.",
|
|
75
75
|
registration_closed: "Registration is closed.",
|
|
76
76
|
current_password_invalid: "The current password is incorrect.",
|
|
77
|
+
password_unchanged: "The new password must differ from the current one.",
|
|
77
78
|
unauthenticated: "Your session has ended. Log in again.",
|
|
78
79
|
forbidden: "You do not have access to this.",
|
|
79
80
|
reset_token_invalid: "This link has expired or has already been used. Ask for a new one.",
|
package/src/messages/pl.ts
CHANGED
|
@@ -75,6 +75,7 @@ export const pl: typeof en = {
|
|
|
75
75
|
consent_required: "Aby założyć konto, zaakceptuj regulamin.",
|
|
76
76
|
registration_closed: "Rejestracja jest zamknięta.",
|
|
77
77
|
current_password_invalid: "Obecne hasło jest nieprawidłowe.",
|
|
78
|
+
password_unchanged: "Nowe hasło musi różnić się od obecnego.",
|
|
78
79
|
unauthenticated: "Sesja wygasła. Zaloguj się ponownie.",
|
|
79
80
|
forbidden: "Nie masz dostępu do tej funkcji.",
|
|
80
81
|
reset_token_invalid: "Ten link wygasł albo został już użyty. Poproś o nowy.",
|
package/src/next/actions.ts
CHANGED
|
@@ -14,8 +14,9 @@ import { after } from "next/server";
|
|
|
14
14
|
import { z } from "zod";
|
|
15
15
|
import type { AuthFormErrorCode, AuthFormField, AuthFormState } from "../contract.js";
|
|
16
16
|
import { resolveRedirectTarget } from "../redirect-target.js";
|
|
17
|
-
import { toSafeNextPath } from "../safe-next-path.js";
|
|
17
|
+
import { MAX_NEXT_PATH_LENGTH, toSafeNextPath } from "../safe-next-path.js";
|
|
18
18
|
import { changePassword } from "../server/change-password.js";
|
|
19
|
+
import { getAuthOptions } from "../server/options.js";
|
|
19
20
|
import { loginUser } from "../server/login.js";
|
|
20
21
|
import { getAuthRoutes } from "../server/options.js";
|
|
21
22
|
import { deliverPasswordReset, requestPasswordReset, resetPassword } from "../server/password-reset.js";
|
|
@@ -23,7 +24,7 @@ import { registerUser } from "../server/register.js";
|
|
|
23
24
|
import { logoutSession } from "../server/sessions.js";
|
|
24
25
|
import { getAuthContext } from "./context.js";
|
|
25
26
|
import { PASSWORD_RESET_DONE_PARAM } from "./params.js";
|
|
26
|
-
import { clearSessionCookie, readSessionToken, writeSessionCookie } from "./session-cookie.js";
|
|
27
|
+
import { clearSessionCookie, readLegacySessionToken, readSessionToken, writeSessionCookie } from "./session-cookie.js";
|
|
27
28
|
|
|
28
29
|
/** Longer values are cut: the server functions refuse them anyway, and nothing huge is echoed back. */
|
|
29
30
|
const MAX_FIELD_LENGTH = 4096;
|
|
@@ -32,8 +33,14 @@ const text = z
|
|
|
32
33
|
.catch("")
|
|
33
34
|
.transform((value) => value.slice(0, MAX_FIELD_LENGTH));
|
|
34
35
|
|
|
35
|
-
|
|
36
|
-
const
|
|
36
|
+
// One character over the cap, so `toSafeNextPath` still sees an overlong path as overlong, not cut.
|
|
37
|
+
const nextPath = z
|
|
38
|
+
.string()
|
|
39
|
+
.catch("")
|
|
40
|
+
.transform((value) => value.slice(0, MAX_NEXT_PATH_LENGTH + 1));
|
|
41
|
+
|
|
42
|
+
const loginInput = z.object({ email: text, password: text, next: nextPath });
|
|
43
|
+
const registerInput = z.object({ email: text, password: text, next: nextPath, consent: z.string().nullable().catch(null) });
|
|
37
44
|
const changePasswordInput = z.object({ currentPassword: text, newPassword: text });
|
|
38
45
|
const forgotPasswordInput = z.object({ email: text });
|
|
39
46
|
const resetPasswordInput = z.object({ token: text, newPassword: text });
|
|
@@ -48,6 +55,7 @@ const FIELD_OF: Partial<Record<AuthFormErrorCode, AuthFormField>> = {
|
|
|
48
55
|
|
|
49
56
|
const CHANGE_FIELD_OF: Partial<Record<AuthFormErrorCode, AuthFormField>> = {
|
|
50
57
|
"auth.current_password_invalid": "currentPassword",
|
|
58
|
+
"auth.password_unchanged": "newPassword",
|
|
51
59
|
"auth.password_too_short": "newPassword",
|
|
52
60
|
"auth.password_too_long": "newPassword",
|
|
53
61
|
};
|
|
@@ -67,6 +75,16 @@ function readForm<T extends z.ZodType>(schema: T, formData: FormData): z.output<
|
|
|
67
75
|
return schema.parse(raw);
|
|
68
76
|
}
|
|
69
77
|
|
|
78
|
+
/** The app's declared registration fields the form sent as text; files and other names are ignored (the server cuts them to 512). */
|
|
79
|
+
function readRegistrationFields(config: SoftureConfig, formData: FormData): Record<string, string> {
|
|
80
|
+
const fields: Record<string, string> = {};
|
|
81
|
+
for (const name of getAuthOptions(config).registrationFields) {
|
|
82
|
+
const value = formData.get(name);
|
|
83
|
+
if (typeof value === "string") fields[name] = value.slice(0, MAX_FIELD_LENGTH);
|
|
84
|
+
}
|
|
85
|
+
return fields;
|
|
86
|
+
}
|
|
87
|
+
|
|
70
88
|
function reportFailure(operation: string, error: unknown): AuthFormErrorCode {
|
|
71
89
|
console.error(`@softure-ai/auth: ${operation} failed: ${errorLogLabel(error)}`);
|
|
72
90
|
return safeError(error).error;
|
|
@@ -105,6 +123,7 @@ export async function registerAction(_previous: AuthFormState, formData: FormDat
|
|
|
105
123
|
// A checked HTML checkbox sends "on" (or its value); an unchecked one sends nothing.
|
|
106
124
|
hasConsented: input.consent !== null,
|
|
107
125
|
clientKey: client.value,
|
|
126
|
+
fields: readRegistrationFields(config, formData),
|
|
108
127
|
});
|
|
109
128
|
} catch (error) {
|
|
110
129
|
return failure(reportFailure("registration", error), { email: input.email });
|
|
@@ -189,22 +208,27 @@ export async function resetPasswordAction(_previous: AuthFormState, formData: Fo
|
|
|
189
208
|
redirect(await resolveRedirectTarget(config, `${getAuthRoutes(config).login}?${PASSWORD_RESET_DONE_PARAM}=1`));
|
|
190
209
|
}
|
|
191
210
|
|
|
192
|
-
/**
|
|
211
|
+
/** Every session token the browser holds: the current cookie's and a legacy session's. */
|
|
212
|
+
async function readHeldTokens(config: SoftureConfig): Promise<string[]> {
|
|
213
|
+
const tokens = [await readSessionToken(config), await readLegacySessionToken(config)];
|
|
214
|
+
return [...new Set(tokens.filter((token) => token !== null))];
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
/** Ends the sessions the browser held before a login or register, so they cannot be reused. */
|
|
193
218
|
async function endPreviousSession(config: SoftureConfig): Promise<void> {
|
|
194
|
-
const previous
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
219
|
+
for (const previous of await readHeldTokens(config)) {
|
|
220
|
+
try {
|
|
221
|
+
await logoutSession(await getAuthContext(config), previous);
|
|
222
|
+
} catch (error) {
|
|
223
|
+
reportFailure("ending the previous session", error);
|
|
224
|
+
}
|
|
200
225
|
}
|
|
201
226
|
}
|
|
202
227
|
|
|
203
|
-
/** Ends the request's
|
|
228
|
+
/** Ends the request's sessions and goes to `afterLogout`. The cookies are cleared even if the delete fails. */
|
|
204
229
|
export async function logoutAction(): Promise<void> {
|
|
205
230
|
const config = getSoftureConfig();
|
|
206
|
-
const token
|
|
207
|
-
if (token !== null) {
|
|
231
|
+
for (const token of await readHeldTokens(config)) {
|
|
208
232
|
try {
|
|
209
233
|
await logoutSession(await getAuthContext(config), token);
|
|
210
234
|
} catch (error) {
|
package/src/next/context.ts
CHANGED
|
@@ -2,13 +2,13 @@
|
|
|
2
2
|
// handle and the wall clock. Request scope (cookies, headers) stays in this folder.
|
|
3
3
|
import { systemClock, type SoftureConfig } from "@softure-ai/core";
|
|
4
4
|
import { getSoftureConfig } from "@softure-ai/core/next";
|
|
5
|
-
import {
|
|
5
|
+
import { getConfiguredDatabase } from "@softure-ai/db";
|
|
6
6
|
import type { AuthContext } from "../server/sessions.js";
|
|
7
7
|
|
|
8
8
|
export async function getAuthContext(config: SoftureConfig = getSoftureConfig()): Promise<AuthContext> {
|
|
9
9
|
if (config.database === null) {
|
|
10
10
|
throw new Error("@softure-ai/auth: softure.config.ts has no database; auth needs one");
|
|
11
11
|
}
|
|
12
|
-
const { db } = await
|
|
12
|
+
const { db } = await getConfiguredDatabase(config.database);
|
|
13
13
|
return { db, clock: systemClock, config };
|
|
14
14
|
}
|