@softure-ai/auth 0.0.0-stage → 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/LICENSE +21 -0
- package/README.md +490 -2
- package/dist/contract.d.ts +46 -0
- package/dist/contract.d.ts.map +1 -0
- package/dist/contract.js +2 -0
- package/dist/contract.js.map +1 -0
- package/dist/index.d.ts +194 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +84 -0
- package/dist/index.js.map +1 -0
- package/dist/mailing/index.d.ts +2 -0
- package/dist/mailing/index.d.ts.map +1 -0
- package/dist/mailing/index.js +4 -0
- package/dist/mailing/index.js.map +1 -0
- package/dist/mailing/reset-mail.d.ts +27 -0
- package/dist/mailing/reset-mail.d.ts.map +1 -0
- package/dist/mailing/reset-mail.js +55 -0
- package/dist/mailing/reset-mail.js.map +1 -0
- package/dist/messages/en.d.ts +98 -0
- package/dist/messages/en.d.ts.map +1 -0
- package/dist/messages/en.js +93 -0
- package/dist/messages/en.js.map +1 -0
- package/dist/messages/index.d.ts +201 -0
- package/dist/messages/index.d.ts.map +1 -0
- package/dist/messages/index.js +11 -0
- package/dist/messages/index.js.map +1 -0
- package/dist/messages/pl.d.ts +3 -0
- package/dist/messages/pl.d.ts.map +1 -0
- package/dist/messages/pl.js +92 -0
- package/dist/messages/pl.js.map +1 -0
- package/dist/next/actions.d.ts +19 -0
- package/dist/next/actions.d.ts.map +1 -0
- package/dist/next/actions.js +231 -0
- package/dist/next/actions.js.map +1 -0
- package/dist/next/context.d.ts +4 -0
- package/dist/next/context.d.ts.map +1 -0
- package/dist/next/context.js +13 -0
- package/dist/next/context.js.map +1 -0
- package/dist/next/current-user.d.ts +34 -0
- package/dist/next/current-user.d.ts.map +1 -0
- package/dist/next/current-user.js +77 -0
- package/dist/next/current-user.js.map +1 -0
- package/dist/next/index.d.ts +8 -0
- package/dist/next/index.d.ts.map +1 -0
- package/dist/next/index.js +9 -0
- package/dist/next/index.js.map +1 -0
- package/dist/next/logout-button.d.ts +7 -0
- package/dist/next/logout-button.d.ts.map +1 -0
- package/dist/next/logout-button.js +12 -0
- package/dist/next/logout-button.js.map +1 -0
- package/dist/next/messages.d.ts +5 -0
- package/dist/next/messages.d.ts.map +1 -0
- package/dist/next/messages.js +7 -0
- package/dist/next/messages.js.map +1 -0
- package/dist/next/pages.d.ts +31 -0
- package/dist/next/pages.d.ts.map +1 -0
- package/dist/next/pages.js +118 -0
- package/dist/next/pages.js.map +1 -0
- package/dist/next/params.d.ts +3 -0
- package/dist/next/params.d.ts.map +1 -0
- package/dist/next/params.js +4 -0
- package/dist/next/params.js.map +1 -0
- package/dist/next/route.d.ts +3 -0
- package/dist/next/route.d.ts.map +1 -0
- package/dist/next/route.js +17 -0
- package/dist/next/route.js.map +1 -0
- package/dist/next/search-params.d.ts +5 -0
- package/dist/next/search-params.d.ts.map +1 -0
- package/dist/next/search-params.js +13 -0
- package/dist/next/search-params.js.map +1 -0
- package/dist/next/session-cookie.d.ts +11 -0
- package/dist/next/session-cookie.d.ts.map +1 -0
- package/dist/next/session-cookie.js +71 -0
- package/dist/next/session-cookie.js.map +1 -0
- package/dist/options.d.ts +72 -0
- package/dist/options.d.ts.map +1 -0
- package/dist/options.js +115 -0
- package/dist/options.js.map +1 -0
- package/dist/password-reset-sender.d.ts +21 -0
- package/dist/password-reset-sender.d.ts.map +1 -0
- package/dist/password-reset-sender.js +12 -0
- package/dist/password-reset-sender.js.map +1 -0
- package/dist/proxy/index.d.ts +14 -0
- package/dist/proxy/index.d.ts.map +1 -0
- package/dist/proxy/index.js +59 -0
- package/dist/proxy/index.js.map +1 -0
- package/dist/redirect-target.d.ts +7 -0
- package/dist/redirect-target.d.ts.map +1 -0
- package/dist/redirect-target.js +25 -0
- package/dist/redirect-target.js.map +1 -0
- package/dist/roles.d.ts +5 -0
- package/dist/roles.d.ts.map +1 -0
- package/dist/roles.js +6 -0
- package/dist/roles.js.map +1 -0
- package/dist/safe-next-path.d.ts +5 -0
- package/dist/safe-next-path.d.ts.map +1 -0
- package/dist/safe-next-path.js +25 -0
- package/dist/safe-next-path.js.map +1 -0
- package/dist/schema.d.ts +302 -0
- package/dist/schema.d.ts.map +1 -0
- package/dist/schema.js +37 -0
- package/dist/schema.js.map +1 -0
- package/dist/scripts/index.d.ts +3 -0
- package/dist/scripts/index.d.ts.map +1 -0
- package/dist/scripts/index.js +5 -0
- package/dist/scripts/index.js.map +1 -0
- package/dist/scripts/role-scripts.d.ts +15 -0
- package/dist/scripts/role-scripts.d.ts.map +1 -0
- package/dist/scripts/role-scripts.js +76 -0
- package/dist/scripts/role-scripts.js.map +1 -0
- 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 +14 -0
- package/dist/server/change-password.d.ts.map +1 -0
- package/dist/server/change-password.js +50 -0
- package/dist/server/change-password.js.map +1 -0
- package/dist/server/health.d.ts +3 -0
- package/dist/server/health.d.ts.map +1 -0
- package/dist/server/health.js +15 -0
- package/dist/server/health.js.map +1 -0
- package/dist/server/index.d.ts +12 -0
- package/dist/server/index.d.ts.map +1 -0
- package/dist/server/index.js +14 -0
- package/dist/server/index.js.map +1 -0
- package/dist/server/login.d.ts +14 -0
- package/dist/server/login.d.ts.map +1 -0
- package/dist/server/login.js +50 -0
- package/dist/server/login.js.map +1 -0
- package/dist/server/options.d.ts +19 -0
- package/dist/server/options.d.ts.map +1 -0
- package/dist/server/options.js +50 -0
- package/dist/server/options.js.map +1 -0
- package/dist/server/password-reset.d.ts +54 -0
- package/dist/server/password-reset.d.ts.map +1 -0
- package/dist/server/password-reset.js +134 -0
- package/dist/server/password-reset.js.map +1 -0
- package/dist/server/password.d.ts +25 -0
- package/dist/server/password.d.ts.map +1 -0
- package/dist/server/password.js +93 -0
- package/dist/server/password.js.map +1 -0
- package/dist/server/privacy.d.ts +33 -0
- package/dist/server/privacy.d.ts.map +1 -0
- package/dist/server/privacy.js +52 -0
- package/dist/server/privacy.js.map +1 -0
- package/dist/server/rate-limits.d.ts +22 -0
- package/dist/server/rate-limits.d.ts.map +1 -0
- package/dist/server/rate-limits.js +45 -0
- package/dist/server/rate-limits.js.map +1 -0
- package/dist/server/reauthenticate.d.ts +7 -0
- package/dist/server/reauthenticate.d.ts.map +1 -0
- package/dist/server/reauthenticate.js +16 -0
- package/dist/server/reauthenticate.js.map +1 -0
- package/dist/server/register.d.ts +23 -0
- package/dist/server/register.d.ts.map +1 -0
- package/dist/server/register.js +64 -0
- package/dist/server/register.js.map +1 -0
- package/dist/server/roles.d.ts +25 -0
- package/dist/server/roles.d.ts.map +1 -0
- package/dist/server/roles.js +56 -0
- package/dist/server/roles.js.map +1 -0
- package/dist/server/session-token.d.ts +12 -0
- package/dist/server/session-token.d.ts.map +1 -0
- package/dist/server/session-token.js +22 -0
- package/dist/server/session-token.js.map +1 -0
- package/dist/server/sessions.d.ts +24 -0
- package/dist/server/sessions.d.ts.map +1 -0
- package/dist/server/sessions.js +50 -0
- package/dist/server/sessions.js.map +1 -0
- package/dist/server/switches.d.ts +9 -0
- package/dist/server/switches.d.ts.map +1 -0
- package/dist/server/switches.js +34 -0
- package/dist/server/switches.js.map +1 -0
- package/dist/server/validation.d.ts +10 -0
- package/dist/server/validation.d.ts.map +1 -0
- package/dist/server/validation.js +32 -0
- package/dist/server/validation.js.map +1 -0
- package/dist/session-cookie.d.ts +14 -0
- package/dist/session-cookie.d.ts.map +1 -0
- package/dist/session-cookie.js +31 -0
- package/dist/session-cookie.js.map +1 -0
- 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 +64 -0
- package/dist/ui/auth-forms.d.ts.map +1 -0
- package/dist/ui/auth-forms.js +67 -0
- package/dist/ui/auth-forms.js.map +1 -0
- package/dist/ui/index.d.ts +2 -0
- package/dist/ui/index.d.ts.map +1 -0
- package/dist/ui/index.js +4 -0
- package/dist/ui/index.js.map +1 -0
- package/migrations/0001_create_users_and_sessions.sql +25 -0
- package/migrations/0002_create_user_roles.sql +10 -0
- package/migrations/0003_create_password_resets.sql +15 -0
- package/migrations/0004_index_users_created_at.sql +5 -0
- package/module.json +34 -0
- package/package.json +97 -4
- package/src/contract.ts +67 -0
- package/src/index.ts +100 -0
- package/src/mailing/index.ts +3 -0
- package/src/mailing/reset-mail.ts +73 -0
- package/src/messages/en.ts +92 -0
- package/src/messages/index.ts +15 -0
- package/src/messages/pl.ts +93 -0
- package/src/next/actions.ts +240 -0
- package/src/next/context.ts +14 -0
- package/src/next/current-user.ts +90 -0
- package/src/next/index.ts +33 -0
- package/src/next/logout-button.tsx +22 -0
- package/src/next/messages.ts +9 -0
- package/src/next/next-modules.d.ts +16 -0
- package/src/next/pages.tsx +223 -0
- package/src/next/params.ts +4 -0
- package/src/next/route.ts +17 -0
- package/src/next/search-params.ts +14 -0
- package/src/next/session-cookie.ts +79 -0
- package/src/options.ts +154 -0
- package/src/password-reset-sender.ts +33 -0
- package/src/proxy/index.ts +85 -0
- package/src/redirect-target.ts +24 -0
- package/src/roles.ts +7 -0
- package/src/safe-next-path.ts +21 -0
- package/src/schema.ts +45 -0
- package/src/scripts/index.ts +8 -0
- package/src/scripts/role-scripts.ts +98 -0
- package/src/scripts/temporary-password.ts +62 -0
- package/src/server/change-password.ts +64 -0
- package/src/server/health.ts +16 -0
- package/src/server/index.ts +46 -0
- package/src/server/login.ts +61 -0
- package/src/server/options.ts +64 -0
- package/src/server/password-reset.ts +164 -0
- package/src/server/password.ts +108 -0
- package/src/server/privacy.ts +70 -0
- package/src/server/rate-limits.ts +51 -0
- package/src/server/reauthenticate.ts +16 -0
- package/src/server/register.ts +87 -0
- package/src/server/roles.ts +72 -0
- package/src/server/session-token.ts +25 -0
- package/src/server/sessions.ts +65 -0
- package/src/server/switches.ts +31 -0
- package/src/server/validation.ts +37 -0
- package/src/session-cookie.ts +47 -0
- package/src/testing/account.ts +43 -0
- package/src/testing/index.ts +3 -0
- package/src/ui/auth-forms.tsx +383 -0
- package/src/ui/index.ts +16 -0
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { SoftureConfig } from "@softure-ai/core";
|
|
2
|
+
export interface SessionCookie {
|
|
3
|
+
readonly name: string;
|
|
4
|
+
readonly domain: string | undefined;
|
|
5
|
+
readonly secure: boolean;
|
|
6
|
+
readonly httpOnly: true;
|
|
7
|
+
readonly sameSite: "lax";
|
|
8
|
+
readonly path: "/";
|
|
9
|
+
readonly maxAgeSeconds: number;
|
|
10
|
+
}
|
|
11
|
+
export declare function getSessionCookie(config: SoftureConfig): SessionCookie;
|
|
12
|
+
/** The session token in a `Cookie` header, or null. */
|
|
13
|
+
export declare function readSessionToken(cookieHeader: string | null, cookieName: string): string | null;
|
|
14
|
+
//# sourceMappingURL=session-cookie.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"session-cookie.d.ts","sourceRoot":"","sources":["../src/session-cookie.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AAKtD,MAAM,WAAW,aAAa;IAC5B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC;IACpC,QAAQ,CAAC,MAAM,EAAE,OAAO,CAAC;IACzB,QAAQ,CAAC,QAAQ,EAAE,IAAI,CAAC;IACxB,QAAQ,CAAC,QAAQ,EAAE,KAAK,CAAC;IACzB,QAAQ,CAAC,IAAI,EAAE,GAAG,CAAC;IACnB,QAAQ,CAAC,aAAa,EAAE,MAAM,CAAC;CAChC;AAED,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,aAAa,GAAG,aAAa,CAcrE;AAED,uDAAuD;AACvD,wBAAgB,gBAAgB,CAAC,YAAY,EAAE,MAAM,GAAG,IAAI,EAAE,UAAU,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAU/F"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { getAuthOptions } from "./server/options.js";
|
|
2
|
+
const DAY_SECONDS = 24 * 60 * 60;
|
|
3
|
+
export function getSessionCookie(config) {
|
|
4
|
+
const options = getAuthOptions(config);
|
|
5
|
+
const secure = options.cookie.secure ?? config.appOrigin.startsWith("https:");
|
|
6
|
+
const domain = options.cookie.domain;
|
|
7
|
+
const prefix = !secure ? "" : domain === undefined ? "__Host-" : "__Secure-";
|
|
8
|
+
return {
|
|
9
|
+
name: `${prefix}${options.cookie.name}`,
|
|
10
|
+
domain,
|
|
11
|
+
secure,
|
|
12
|
+
httpOnly: true,
|
|
13
|
+
sameSite: "lax",
|
|
14
|
+
path: "/",
|
|
15
|
+
maxAgeSeconds: options.session.ttlDays * DAY_SECONDS,
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
/** The session token in a `Cookie` header, or null. */
|
|
19
|
+
export function readSessionToken(cookieHeader, cookieName) {
|
|
20
|
+
if (cookieHeader === null)
|
|
21
|
+
return null;
|
|
22
|
+
for (const part of cookieHeader.split(";")) {
|
|
23
|
+
const separator = part.indexOf("=");
|
|
24
|
+
if (separator !== -1 && part.slice(0, separator).trim() === cookieName) {
|
|
25
|
+
const value = part.slice(separator + 1).trim();
|
|
26
|
+
return value === "" ? null : value;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
return null;
|
|
30
|
+
}
|
|
31
|
+
//# sourceMappingURL=session-cookie.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"session-cookie.js","sourceRoot":"","sources":["../src/session-cookie.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,cA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,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC;YAC/C,OAAO,KAAK,KAAK,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,CAAC;QACrC,CAAC;IACH,CAAC;IACD,OAAO,IAAI,CAAC;AACd,CAAC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
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/testing/account.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,mBAAmB,EAAqB,MAAM,eAAe,CAAC;AACvE,OAAO,EAAE,SAAS,EAAE,KAAK,EAAE,MAAM,cAAc,CAAC;AAChD,OAAO,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AACrD,OAAO,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAC;AAErD,gGAAgG;AAChG,MAAM,cAAc,GAAiB,EAAE,IAAI,EAAE,mBAAmB,EAAE,SAAS,EAAE,CAAC,EAAE,eAAe,EAAE,CAAC,EAAE,CAAC;AAWrG;;;GAGG;AACH,MAAM,CAAC,KAAK,UAAU,iBAAiB,CAAC,EAAa,EAAE,KAAuB;IAC5E,MAAM,KAAK,GAAG,UAAU,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;IACtC,IAAI,CAAC,KAAK,CAAC,EAAE;QAAE,MAAM,IAAI,KAAK,CAAC,uBAAuB,KAAK,CAAC,KAAK,wBAAwB,CAAC,CAAC;IAC3F,MAAM,YAAY,GAAG,MAAM,YAAY,CAAC,KAAK,CAAC,QAAQ,EAAE,KAAK,CAAC,MAAM,IAAI,cAAc,CAAC,CAAC;IACxF,MAAM,GAAG,GAAG,IAAI,IAAI,EAAE,CAAC;IAEvB,OAAO,EAAE,CAAC,WAAW,CAAC,KAAK,EAAE,EAAE,EAAE,EAAE;QACjC,MAAM,CAAC,GAAG,CAAC,GAAG,MAAM,EAAE;aACnB,MAAM,CAAC,KAAK,CAAC;aACb,MAAM,CAAC,EAAE,KAAK,EAAE,KAAK,CAAC,KAAK,EAAE,YAAY,EAAE,SAAS,EAAE,GAAG,EAAE,iBAAiB,EAAE,GAAG,EAAE,CAAC;aACpF,mBAAmB,CAAC,EAAE,MAAM,EAAE,KAAK,CAAC,KAAK,EAAE,CAAC;aAC5C,SAAS,EAAE,CAAC;QACf,IAAI,GAAG,KAAK,SAAS;YAAE,MAAM,IAAI,KAAK,CAAC,iDAAiD,KAAK,CAAC,KAAK,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"}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { type Locale } from "@softure-ai/core";
|
|
2
|
+
import { type ButtonVariant, type ClassNames } from "@softure-ai/ui";
|
|
3
|
+
import { type ReactNode } from "react";
|
|
4
|
+
import { type AuthFormState } from "../contract.js";
|
|
5
|
+
import { type AuthMessages } from "../messages/index.js";
|
|
6
|
+
export type AuthFormAction = (previous: AuthFormState, formData: FormData) => Promise<AuthFormState>;
|
|
7
|
+
export type AuthFormSlot = "root" | "form" | "footer" | "link" | "notice" | "submit";
|
|
8
|
+
interface AuthFormBaseProps {
|
|
9
|
+
readonly action: AuthFormAction;
|
|
10
|
+
readonly messages: AuthMessages;
|
|
11
|
+
/** Locale of the built-in copy of the ui primitives. */
|
|
12
|
+
readonly locale?: Locale;
|
|
13
|
+
readonly classNames?: ClassNames<AuthFormSlot>;
|
|
14
|
+
readonly unstyled?: boolean;
|
|
15
|
+
/** The submit button's look; `primary` by default. Its class goes in `classNames.submit`. */
|
|
16
|
+
readonly submitVariant?: ButtonVariant;
|
|
17
|
+
}
|
|
18
|
+
export interface LoginFormProps extends AuthFormBaseProps {
|
|
19
|
+
/** Where to go after login; checked again on the server. */
|
|
20
|
+
readonly next?: string;
|
|
21
|
+
/** Link to the register page; omitted when registration is not offered. */
|
|
22
|
+
readonly registerHref?: string;
|
|
23
|
+
/** Link to the password reset request page; omitted when reset is not offered. */
|
|
24
|
+
readonly forgotPasswordHref?: string;
|
|
25
|
+
/** A confirmation shown under the form, e.g. after a password reset. */
|
|
26
|
+
readonly notice?: string;
|
|
27
|
+
}
|
|
28
|
+
export declare function LoginForm({ action, messages, locale, next, registerHref, forgotPasswordHref, notice, classNames, unstyled, submitVariant }: LoginFormProps): import("react").JSX.Element;
|
|
29
|
+
export interface RegisterFormProps extends AuthFormBaseProps {
|
|
30
|
+
readonly next?: string;
|
|
31
|
+
readonly loginHref?: string;
|
|
32
|
+
/** Show the consent checkbox (the module's `requireConsent`). */
|
|
33
|
+
readonly requireConsent: boolean;
|
|
34
|
+
/** The password policy's minimum, for the hint and the browser check. */
|
|
35
|
+
readonly minPasswordLength: number;
|
|
36
|
+
/** The consent statement; may contain links to the terms. Defaults to `messages.fields.consent`. */
|
|
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;
|
|
43
|
+
}
|
|
44
|
+
export declare function RegisterForm({ action, messages, locale, next, loginHref, requireConsent, minPasswordLength, consentLabel, extraFields, classNames, unstyled, submitVariant, }: RegisterFormProps): import("react").JSX.Element;
|
|
45
|
+
export interface ChangePasswordFormProps extends AuthFormBaseProps {
|
|
46
|
+
readonly minPasswordLength: number;
|
|
47
|
+
}
|
|
48
|
+
export declare function ChangePasswordForm({ action, messages, locale, minPasswordLength, classNames, unstyled, submitVariant }: ChangePasswordFormProps): import("react").JSX.Element;
|
|
49
|
+
export interface ForgotPasswordFormProps extends AuthFormBaseProps {
|
|
50
|
+
/** How long a link works, for the confirmation. */
|
|
51
|
+
readonly ttlMinutes: number;
|
|
52
|
+
readonly loginHref?: string;
|
|
53
|
+
}
|
|
54
|
+
/** Asks for a reset link. Its confirmation is the same whether or not the email has an account. */
|
|
55
|
+
export declare function ForgotPasswordForm({ action, messages, locale, ttlMinutes, loginHref, classNames, unstyled, submitVariant }: ForgotPasswordFormProps): import("react").JSX.Element;
|
|
56
|
+
export interface ResetPasswordFormProps extends AuthFormBaseProps {
|
|
57
|
+
/** The token from the reset link; checked again on the server. */
|
|
58
|
+
readonly token: string;
|
|
59
|
+
readonly minPasswordLength: number;
|
|
60
|
+
}
|
|
61
|
+
/** Sets a new password from a reset link; its action goes to the login page on success. */
|
|
62
|
+
export declare function ResetPasswordForm({ action, messages, locale, token, minPasswordLength, classNames, unstyled, submitVariant }: ResetPasswordFormProps): import("react").JSX.Element;
|
|
63
|
+
export {};
|
|
64
|
+
//# sourceMappingURL=auth-forms.d.ts.map
|
|
@@ -0,0 +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,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,QAAQ,EAAE,YAAY,CAAC;IAChC,wDAAwD;IACxD,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,UAAU,CAAC,EAAE,UAAU,CAAC,YAAY,CAAC,CAAC;IAC/C,QAAQ,CAAC,QAAQ,CAAC,EAAE,OAAO,CAAC;IAC5B,6FAA6F;IAC7F,QAAQ,CAAC,aAAa,CAAC,EAAE,aAAa,CAAC;CACxC;AA0DD,MAAM,WAAW,cAAe,SAAQ,iBAAiB;IACvD,4DAA4D;IAC5D,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,CAAC;IACvB,2EAA2E;IAC3E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E,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"}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
3
|
+
import { formatMessage } from "@softure-ai/core";
|
|
4
|
+
import { Button, Checkbox, createSlotClassGetter, FormError, PasswordField, TextField } from "@softure-ai/ui";
|
|
5
|
+
import { useActionState } from "react";
|
|
6
|
+
import { INITIAL_AUTH_FORM_STATE } from "../contract.js";
|
|
7
|
+
import { getAuthErrorMessage } from "../messages/index.js";
|
|
8
|
+
const DEFAULT_CLASSES = {
|
|
9
|
+
root: "sft:flex sft:flex-col sft:gap-3 sft:font-sans",
|
|
10
|
+
form: "sft:flex sft:flex-col sft:gap-3",
|
|
11
|
+
footer: "sft:m-0 sft:text-sm sft:text-muted",
|
|
12
|
+
link: "sft:font-medium sft:text-accent",
|
|
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: "",
|
|
16
|
+
};
|
|
17
|
+
/** The error of one field, or of the form when no field owns it. */
|
|
18
|
+
function useErrors(state, messages) {
|
|
19
|
+
const message = state.error === undefined ? undefined : getAuthErrorMessage(messages, state.error);
|
|
20
|
+
return {
|
|
21
|
+
at: (field) => (state.field === field ? message : undefined),
|
|
22
|
+
form: state.field === undefined ? message : undefined,
|
|
23
|
+
};
|
|
24
|
+
}
|
|
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] }));
|
|
27
|
+
}
|
|
28
|
+
export function LoginForm({ action, messages, locale, next, registerHref, forgotPasswordHref, notice, classNames, unstyled, submitVariant }) {
|
|
29
|
+
const [state, formAction, isPending] = useActionState(action, INITIAL_AUTH_FORM_STATE);
|
|
30
|
+
const errors = useErrors(state, messages);
|
|
31
|
+
const slot = createSlotClassGetter({ defaults: DEFAULT_CLASSES, classNames, unstyled });
|
|
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 })] }))] }));
|
|
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 })] }));
|
|
34
|
+
}
|
|
35
|
+
export function RegisterForm({ action, messages, locale, next, loginHref, requireConsent, minPasswordLength, consentLabel, extraFields, classNames, unstyled, submitVariant, }) {
|
|
36
|
+
const [state, formAction, isPending] = useActionState(action, INITIAL_AUTH_FORM_STATE);
|
|
37
|
+
const errors = useErrors(state, messages);
|
|
38
|
+
const slot = createSlotClassGetter({ defaults: DEFAULT_CLASSES, classNames, unstyled });
|
|
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 })] }));
|
|
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] }));
|
|
41
|
+
}
|
|
42
|
+
export function ChangePasswordForm({ action, messages, locale, minPasswordLength, classNames, unstyled, submitVariant }) {
|
|
43
|
+
const [state, formAction, isPending] = useActionState(action, INITIAL_AUTH_FORM_STATE);
|
|
44
|
+
const errors = useErrors(state, messages);
|
|
45
|
+
const slot = createSlotClassGetter({ defaults: DEFAULT_CLASSES, classNames, unstyled });
|
|
46
|
+
const notice = state.status === "ok" ? (_jsx("p", { role: "status", className: slot("notice"), children: messages.changePassword.success })) : undefined;
|
|
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 })] }));
|
|
48
|
+
}
|
|
49
|
+
/** Asks for a reset link. Its confirmation is the same whether or not the email has an account. */
|
|
50
|
+
export function ForgotPasswordForm({ action, messages, locale, ttlMinutes, loginHref, classNames, unstyled, submitVariant }) {
|
|
51
|
+
const [state, formAction, isPending] = useActionState(action, INITIAL_AUTH_FORM_STATE);
|
|
52
|
+
const errors = useErrors(state, messages);
|
|
53
|
+
const slot = createSlotClassGetter({ defaults: DEFAULT_CLASSES, classNames, unstyled });
|
|
54
|
+
const backToLogin = loginHref === undefined ? undefined : (_jsx("p", { className: slot("footer"), children: _jsx("a", { href: loginHref, className: slot("link"), children: messages.forgotPassword.backToLogin }) }));
|
|
55
|
+
if (state.status === "ok") {
|
|
56
|
+
return (_jsxs("div", { className: slot("root"), children: [_jsx("p", { role: "status", className: slot("notice"), children: formatMessage(messages.forgotPassword.sent, { ttlMinutes }) }), backToLogin] }));
|
|
57
|
+
}
|
|
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 }) }));
|
|
59
|
+
}
|
|
60
|
+
/** Sets a new password from a reset link; its action goes to the login page on success. */
|
|
61
|
+
export function ResetPasswordForm({ action, messages, locale, token, minPasswordLength, classNames, unstyled, submitVariant }) {
|
|
62
|
+
const [state, formAction, isPending] = useActionState(action, INITIAL_AUTH_FORM_STATE);
|
|
63
|
+
const errors = useErrors(state, messages);
|
|
64
|
+
const slot = createSlotClassGetter({ defaults: DEFAULT_CLASSES, classNames, unstyled });
|
|
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 })] }));
|
|
66
|
+
}
|
|
67
|
+
//# sourceMappingURL=auth-forms.js.map
|
|
@@ -0,0 +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,EAAsB,QAAQ,EAAmB,qBAAqB,EAAE,SAAS,EAAE,aAAa,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AACnJ,OAAO,EAAkB,cAAc,EAAE,MAAM,OAAO,CAAC;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a,CAAC,OAAO,EAC5C,SAAS,EAAE,MAAM,CAAC,IAAI,EACtB,IAAI,EAAE,IAAI,EACV,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"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
export { type AuthFormAction, type AuthFormSlot, ChangePasswordForm, type ChangePasswordFormProps, ForgotPasswordForm, type ForgotPasswordFormProps, LoginForm, type LoginFormProps, RegisterForm, type RegisterFormProps, ResetPasswordForm, type ResetPasswordFormProps, } from "./auth-forms.js";
|
|
2
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/ui/index.ts"],"names":[],"mappings":"AAEA,OAAO,EACL,KAAK,cAAc,EACnB,KAAK,YAAY,EACjB,kBAAkB,EAClB,KAAK,uBAAuB,EAC5B,kBAAkB,EAClB,KAAK,uBAAuB,EAC5B,SAAS,EACT,KAAK,cAAc,EACnB,YAAY,EACZ,KAAK,iBAAiB,EACtB,iBAAiB,EACjB,KAAK,sBAAsB,GAC5B,MAAM,iBAAiB,CAAC"}
|
package/dist/ui/index.js
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
// The auth forms, to compose into the app's own pages. They take the server actions from
|
|
2
|
+
// `@softure-ai/auth/next` as props: no `next/*` import here (docs/02-module-standard.md §5).
|
|
3
|
+
export { ChangePasswordForm, ForgotPasswordForm, LoginForm, RegisterForm, ResetPasswordForm, } from "./auth-forms.js";
|
|
4
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/ui/index.ts"],"names":[],"mappings":"AAAA,yFAAyF;AACzF,6FAA6F;AAC7F,OAAO,EAGL,kBAAkB,EAElB,kBAAkB,EAElB,SAAS,EAET,YAAY,EAEZ,iBAAiB,GAElB,MAAM,iBAAiB,CAAC"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
-- Accounts and their database sessions.
|
|
2
|
+
-- Rollback: DROP TABLE auth.sessions; DROP TABLE auth.users; then
|
|
3
|
+
-- DELETE FROM softure.migrations WHERE module = 'auth' AND version = 1;
|
|
4
|
+
CREATE TABLE users (
|
|
5
|
+
id uuid PRIMARY KEY DEFAULT gen_random_uuid(),
|
|
6
|
+
-- Stored trimmed and lowercased, so the unique constraint is the case-insensitive one.
|
|
7
|
+
email text NOT NULL CHECK (email = lower(btrim(email)) AND char_length(email) BETWEEN 3 AND 254),
|
|
8
|
+
password_hash text NOT NULL CHECK (password_hash LIKE 'scrypt$%'),
|
|
9
|
+
created_at timestamptz NOT NULL,
|
|
10
|
+
password_changed_at timestamptz NOT NULL,
|
|
11
|
+
CONSTRAINT users_email_key UNIQUE (email)
|
|
12
|
+
);
|
|
13
|
+
|
|
14
|
+
-- Only the sha256 of a session token is stored; the token itself lives in the cookie alone.
|
|
15
|
+
CREATE TABLE sessions (
|
|
16
|
+
token_hash text PRIMARY KEY CHECK (token_hash ~ '^[0-9a-f]{64}$'),
|
|
17
|
+
user_id uuid NOT NULL REFERENCES users (id) ON DELETE CASCADE,
|
|
18
|
+
created_at timestamptz NOT NULL,
|
|
19
|
+
expires_at timestamptz NOT NULL,
|
|
20
|
+
CHECK (expires_at > created_at)
|
|
21
|
+
);
|
|
22
|
+
|
|
23
|
+
-- A password change and the login cleanup delete by user; pruning deletes by age.
|
|
24
|
+
CREATE INDEX sessions_user_id_idx ON sessions (user_id);
|
|
25
|
+
CREATE INDEX sessions_expires_at_idx ON sessions (expires_at);
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
-- Roles granted to accounts. A role an app checks must also be declared in auth({ roles }); `admin`
|
|
2
|
+
-- is always declared. Admins listed in auth({ adminEmails }) are never stored here.
|
|
3
|
+
-- Rollback: DROP TABLE auth.user_roles; then
|
|
4
|
+
-- DELETE FROM softure.migrations WHERE module = 'auth' AND version = 2;
|
|
5
|
+
CREATE TABLE user_roles (
|
|
6
|
+
user_id uuid NOT NULL REFERENCES users (id) ON DELETE CASCADE,
|
|
7
|
+
role text NOT NULL CHECK (role ~ '^[a-z][a-z0-9_-]{0,31}$'),
|
|
8
|
+
granted_at timestamptz NOT NULL,
|
|
9
|
+
PRIMARY KEY (user_id, role)
|
|
10
|
+
);
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
-- Pending password resets: at most one per account (a new request replaces the token), only the
|
|
2
|
+
-- sha256 of the token is stored, and a reset deletes its row, so a link works once.
|
|
3
|
+
-- Rollback: DROP TABLE auth.password_resets; then
|
|
4
|
+
-- DELETE FROM softure.migrations WHERE module = 'auth' AND version = 3;
|
|
5
|
+
CREATE TABLE password_resets (
|
|
6
|
+
user_id uuid PRIMARY KEY REFERENCES users (id) ON DELETE CASCADE,
|
|
7
|
+
token_hash text NOT NULL CHECK (token_hash ~ '^[0-9a-f]{64}$'),
|
|
8
|
+
created_at timestamptz NOT NULL,
|
|
9
|
+
expires_at timestamptz NOT NULL,
|
|
10
|
+
CHECK (expires_at > created_at),
|
|
11
|
+
CONSTRAINT password_resets_token_hash_key UNIQUE (token_hash)
|
|
12
|
+
);
|
|
13
|
+
|
|
14
|
+
-- Pruning deletes by age.
|
|
15
|
+
CREATE INDEX password_resets_expires_at_idx ON password_resets (expires_at);
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
-- Accounts by creation time: billing finds the accounts whose derived trial is in a reminder
|
|
2
|
+
-- window with a range on created_at, without scanning every account.
|
|
3
|
+
-- Rollback: DROP INDEX auth.users_created_at_idx; then
|
|
4
|
+
-- DELETE FROM softure.migrations WHERE module = 'auth' AND version = 4;
|
|
5
|
+
CREATE INDEX users_created_at_idx ON users (created_at);
|
package/module.json
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
{
|
|
2
|
+
"id": "auth",
|
|
3
|
+
"version": "0.1.7",
|
|
4
|
+
"dependsOn": { "security": "^0.1.0", "mailing": "^0.1.0?", "ops": "^0.1.0?" },
|
|
5
|
+
"dbSchema": "auth",
|
|
6
|
+
"tables": ["users", "sessions", "user_roles", "password_resets"],
|
|
7
|
+
"env": [
|
|
8
|
+
{
|
|
9
|
+
"name": "SOFTURE_SWITCH_AUTH_REGISTRATION_CLOSED",
|
|
10
|
+
"required": false,
|
|
11
|
+
"description": "Overrides the auth.registration_closed switch: true or 1 closes registration, false or 0 opens it."
|
|
12
|
+
}
|
|
13
|
+
],
|
|
14
|
+
"switches": ["auth.registration_closed"],
|
|
15
|
+
"routes": {
|
|
16
|
+
"login": "/login",
|
|
17
|
+
"register": "/register",
|
|
18
|
+
"changePassword": "/account/password",
|
|
19
|
+
"forgotPassword": "/forgot-password",
|
|
20
|
+
"resetPassword": "/reset-password",
|
|
21
|
+
"afterLogin": "/",
|
|
22
|
+
"afterLogout": "/login"
|
|
23
|
+
},
|
|
24
|
+
"mount": [
|
|
25
|
+
{ "kind": "page", "path": "app/login/page.tsx", "export": "LoginPage" },
|
|
26
|
+
{ "kind": "page", "path": "app/register/page.tsx", "export": "RegisterPage" },
|
|
27
|
+
{ "kind": "page", "path": "app/account/password/page.tsx", "export": "ChangePasswordPage" },
|
|
28
|
+
{ "kind": "page", "path": "app/forgot-password/page.tsx", "export": "ForgotPasswordPage" },
|
|
29
|
+
{ "kind": "page", "path": "app/reset-password/page.tsx", "export": "ResetPasswordPage" },
|
|
30
|
+
{ "kind": "route-handler", "path": "app/api/auth/session/route.ts", "export": "getSessionRoute" },
|
|
31
|
+
{ "kind": "middleware", "path": "proxy.ts", "export": "createAuthGuard" }
|
|
32
|
+
],
|
|
33
|
+
"privacy": { "exports": true, "deletes": true }
|
|
34
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,99 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@softure-ai/auth",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.1.7",
|
|
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
|
+
"license": "MIT",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"sideEffects": false,
|
|
8
|
+
"engines": {
|
|
9
|
+
"node": ">=22"
|
|
10
|
+
},
|
|
11
|
+
"repository": {
|
|
12
|
+
"type": "git",
|
|
13
|
+
"url": "git+https://github.com/SOFTURE/AI.git",
|
|
14
|
+
"directory": "modules/auth"
|
|
15
|
+
},
|
|
16
|
+
"files": [
|
|
17
|
+
"dist",
|
|
18
|
+
"CHANGELOG.md",
|
|
19
|
+
"src",
|
|
20
|
+
"!src/**/*.test.ts",
|
|
21
|
+
"!src/**/*.test.tsx",
|
|
22
|
+
"migrations",
|
|
23
|
+
"module.json"
|
|
24
|
+
],
|
|
25
|
+
"publishConfig": {
|
|
26
|
+
"access": "public",
|
|
27
|
+
"provenance": true
|
|
28
|
+
},
|
|
29
|
+
"exports": {
|
|
30
|
+
".": {
|
|
31
|
+
"@softure-ai/source": "./src/index.ts",
|
|
32
|
+
"types": "./dist/index.d.ts",
|
|
33
|
+
"default": "./dist/index.js"
|
|
34
|
+
},
|
|
35
|
+
"./server": {
|
|
36
|
+
"@softure-ai/source": "./src/server/index.ts",
|
|
37
|
+
"types": "./dist/server/index.d.ts",
|
|
38
|
+
"default": "./dist/server/index.js"
|
|
39
|
+
},
|
|
40
|
+
"./next": {
|
|
41
|
+
"@softure-ai/source": "./src/next/index.ts",
|
|
42
|
+
"types": "./dist/next/index.d.ts",
|
|
43
|
+
"default": "./dist/next/index.js"
|
|
44
|
+
},
|
|
45
|
+
"./mailing": {
|
|
46
|
+
"@softure-ai/source": "./src/mailing/index.ts",
|
|
47
|
+
"types": "./dist/mailing/index.d.ts",
|
|
48
|
+
"default": "./dist/mailing/index.js"
|
|
49
|
+
},
|
|
50
|
+
"./proxy": {
|
|
51
|
+
"@softure-ai/source": "./src/proxy/index.ts",
|
|
52
|
+
"types": "./dist/proxy/index.d.ts",
|
|
53
|
+
"default": "./dist/proxy/index.js"
|
|
54
|
+
},
|
|
55
|
+
"./scripts": {
|
|
56
|
+
"@softure-ai/source": "./src/scripts/index.ts",
|
|
57
|
+
"types": "./dist/scripts/index.d.ts",
|
|
58
|
+
"default": "./dist/scripts/index.js"
|
|
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
|
+
},
|
|
65
|
+
"./ui": {
|
|
66
|
+
"@softure-ai/source": "./src/ui/index.ts",
|
|
67
|
+
"types": "./dist/ui/index.d.ts",
|
|
68
|
+
"default": "./dist/ui/index.js"
|
|
69
|
+
}
|
|
70
|
+
},
|
|
71
|
+
"scripts": {
|
|
72
|
+
"build": "tsc -p tsconfig.build.json"
|
|
73
|
+
},
|
|
74
|
+
"dependencies": {
|
|
75
|
+
"@softure-ai/core": "^0.1.0",
|
|
76
|
+
"@softure-ai/db": "^0.1.0",
|
|
77
|
+
"@softure-ai/security": "^0.1.0",
|
|
78
|
+
"zod": "^4.6.5"
|
|
79
|
+
},
|
|
80
|
+
"peerDependencies": {
|
|
81
|
+
"@softure-ai/mailing": "^0.1.0",
|
|
82
|
+
"@softure-ai/ops": "^0.1.0",
|
|
83
|
+
"@softure-ai/ui": "^0.1.0",
|
|
84
|
+
"drizzle-orm": "^0.45.2",
|
|
85
|
+
"next": "^16.0.0",
|
|
86
|
+
"react": "^19.0.0"
|
|
87
|
+
},
|
|
88
|
+
"devDependencies": {
|
|
89
|
+
"@softure-ai/ui": "^0.1.7"
|
|
90
|
+
},
|
|
91
|
+
"peerDependenciesMeta": {
|
|
92
|
+
"@softure-ai/mailing": {
|
|
93
|
+
"optional": true
|
|
94
|
+
},
|
|
95
|
+
"@softure-ai/ops": {
|
|
96
|
+
"optional": true
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
}
|
package/src/contract.ts
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
// Result types and error codes of the auth module. No user-facing copy here: the UI translates
|
|
2
|
+
// codes through `messages` (docs/02-module-standard.md §6).
|
|
3
|
+
import type { CoreErrorCode } from "@softure-ai/core";
|
|
4
|
+
import type { SecurityErrorCode } from "@softure-ai/security";
|
|
5
|
+
|
|
6
|
+
export type AuthErrorCode =
|
|
7
|
+
| "auth.invalid_credentials"
|
|
8
|
+
| "auth.email_invalid"
|
|
9
|
+
| "auth.email_taken"
|
|
10
|
+
| "auth.password_too_short"
|
|
11
|
+
| "auth.password_too_long"
|
|
12
|
+
| "auth.consent_required"
|
|
13
|
+
| "auth.registration_closed"
|
|
14
|
+
| "auth.current_password_invalid"
|
|
15
|
+
| "auth.password_unchanged"
|
|
16
|
+
| "auth.unauthenticated"
|
|
17
|
+
| "auth.forbidden"
|
|
18
|
+
| "auth.reset_token_invalid"
|
|
19
|
+
| "auth.password_reset_unavailable";
|
|
20
|
+
|
|
21
|
+
/** Every code an auth form can show: its own, the rate limiter's and the generic ones. */
|
|
22
|
+
export type AuthFormErrorCode = AuthErrorCode | Extract<SecurityErrorCode, "security.rate_limited" | "security.client_unidentified"> | CoreErrorCode;
|
|
23
|
+
|
|
24
|
+
/** A signed-up account, as the app sees it. The password hash never leaves the module. */
|
|
25
|
+
export interface AuthUser {
|
|
26
|
+
readonly id: string;
|
|
27
|
+
readonly email: string;
|
|
28
|
+
readonly createdAt: Date;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/** A session just opened: the token goes into the cookie and is never stored. */
|
|
32
|
+
export interface NewSession {
|
|
33
|
+
readonly token: string;
|
|
34
|
+
readonly expiresAt: Date;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/** A successful register or login. */
|
|
38
|
+
export interface SignedIn {
|
|
39
|
+
readonly user: AuthUser;
|
|
40
|
+
readonly session: NewSession;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/** What `onRegistered` receives. `consent` is null when the app turned `requireConsent` off. */
|
|
44
|
+
export interface RegisteredEvent {
|
|
45
|
+
readonly user: AuthUser;
|
|
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>>;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/** The fields of the auth forms that can carry their own error. */
|
|
52
|
+
export type AuthFormField = "email" | "password" | "currentPassword" | "newPassword" | "consent";
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* What an auth server action returns to its form (`useActionState`). A successful login or
|
|
56
|
+
* register redirects instead of returning; a password change returns `ok`.
|
|
57
|
+
*/
|
|
58
|
+
export interface AuthFormState {
|
|
59
|
+
readonly status: "idle" | "ok" | "error";
|
|
60
|
+
/** The error to show; when `field` is set it is shown at that field. */
|
|
61
|
+
readonly error?: AuthFormErrorCode;
|
|
62
|
+
readonly field?: AuthFormField;
|
|
63
|
+
/** The submitted email, so a rejected form keeps it (passwords are never sent back). */
|
|
64
|
+
readonly email?: string;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
export const INITIAL_AUTH_FORM_STATE: AuthFormState = { status: "idle" };
|