@softure-ai/auth 0.1.5 → 0.1.8
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 +23 -0
- package/README.md +172 -24
- 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 +9 -2
- package/dist/next/actions.d.ts.map +1 -1
- package/dist/next/actions.js +51 -18
- 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 +2 -2
- 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/logout-button.d.ts +3 -1
- package/dist/next/logout-button.d.ts.map +1 -1
- package/dist/next/logout-button.js +4 -4
- package/dist/next/logout-button.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 +11 -0
- package/dist/proxy/index.d.ts.map +1 -1
- package/dist/proxy/index.js +60 -9
- 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 +58 -16
- package/src/next/context.ts +2 -2
- package/src/next/index.ts +11 -1
- package/src/next/logout-button.tsx +5 -2
- 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 +78 -10
- 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
|
@@ -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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AQ,EAAE,eAAe,EAAE,UAAU,EAAE,QAAQ,EAAE,CAAC,CAAC;IACxF,OAAO,CACL,MAAC,SAAS,IACR,UAAU,EAAE,UAAU,EACtB,SAAS,EAAE,SAAS,EACpB,WAAW,EAAE,QAAQ,CAAC,aAAa,CAAC,MAAM,EAC1C,YAAY,EAAE,QAAQ,CAAC,aAAa,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"}
|
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.8",
|
|
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.8",
|
|
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.8",
|
|
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,45 @@ 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
|
-
/**
|
|
204
|
-
export
|
|
228
|
+
/** Where to go after logout: a path on this app, checked like login's `next`. */
|
|
229
|
+
export interface LogoutInput {
|
|
230
|
+
readonly next?: string;
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
// Any client can call the action with any serializable value: only a `next` string counts.
|
|
234
|
+
const logoutInput = z.object({ next: nextPath }).catch({ next: "" });
|
|
235
|
+
|
|
236
|
+
/** The `next` of a posted form or of an object; anything else is no target. */
|
|
237
|
+
function readLogoutNext(input: unknown): string {
|
|
238
|
+
if (input instanceof FormData) return logoutInput.parse({ next: input.get("next") }).next;
|
|
239
|
+
return logoutInput.parse(input).next;
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
/**
|
|
243
|
+
* Ends the request's sessions and goes to `next` (a form field or `{ next }`, e.g. `/login?next=…` to
|
|
244
|
+
* sign in as someone else), else to `afterLogout`. The cookies are cleared even if the delete fails.
|
|
245
|
+
*/
|
|
246
|
+
export async function logoutAction(input?: FormData | LogoutInput): Promise<void> {
|
|
205
247
|
const config = getSoftureConfig();
|
|
206
|
-
const
|
|
207
|
-
|
|
248
|
+
const target = toSafeNextPath(readLogoutNext(input), getAuthRoutes(config).afterLogout);
|
|
249
|
+
for (const token of await readHeldTokens(config)) {
|
|
208
250
|
try {
|
|
209
251
|
await logoutSession(await getAuthContext(config), token);
|
|
210
252
|
} catch (error) {
|
|
@@ -212,5 +254,5 @@ export async function logoutAction(): Promise<void> {
|
|
|
212
254
|
}
|
|
213
255
|
}
|
|
214
256
|
await clearSessionCookie(config);
|
|
215
|
-
redirect(await resolveRedirectTarget(config,
|
|
257
|
+
redirect(await resolveRedirectTarget(config, target));
|
|
216
258
|
}
|
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
|
}
|
package/src/next/index.ts
CHANGED
|
@@ -5,6 +5,7 @@ export {
|
|
|
5
5
|
forgotPasswordAction,
|
|
6
6
|
loginAction,
|
|
7
7
|
logoutAction,
|
|
8
|
+
type LogoutInput,
|
|
8
9
|
registerAction,
|
|
9
10
|
resetPasswordAction,
|
|
10
11
|
} from "./actions.js";
|
|
@@ -19,6 +20,15 @@ export {
|
|
|
19
20
|
} from "./current-user.js";
|
|
20
21
|
export { LogoutButton, type LogoutButtonProps } from "./logout-button.js";
|
|
21
22
|
export { getAuthMessages } from "./messages.js";
|
|
22
|
-
export {
|
|
23
|
+
export {
|
|
24
|
+
type AuthPageProps,
|
|
25
|
+
ChangePasswordPage,
|
|
26
|
+
createRegisterPage,
|
|
27
|
+
ForgotPasswordPage,
|
|
28
|
+
LoginPage,
|
|
29
|
+
RegisterPage,
|
|
30
|
+
type RegisterPageOptions,
|
|
31
|
+
ResetPasswordPage,
|
|
32
|
+
} from "./pages.js";
|
|
23
33
|
export { getSessionRoute } from "./route.js";
|
|
24
34
|
export type { PageSearchParams } from "./search-params.js";
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// A logout button for the app's own pages: a plain form posting to `logoutAction`, so it works
|
|
2
|
-
// without JavaScript. Server component.
|
|
2
|
+
// without JavaScript. Server component. `next` rides along as a hidden field.
|
|
3
3
|
import { getSoftureConfig } from "@softure-ai/core/next";
|
|
4
4
|
import { Button, type ButtonVariant } from "@softure-ai/ui";
|
|
5
5
|
import { logoutAction } from "./actions.js";
|
|
@@ -8,12 +8,15 @@ import { getAuthMessages } from "./messages.js";
|
|
|
8
8
|
export interface LogoutButtonProps {
|
|
9
9
|
readonly variant?: ButtonVariant;
|
|
10
10
|
readonly className?: string;
|
|
11
|
+
/** Where to go after logout (a path on this app), e.g. `/login?next=…`; default `afterLogout`. */
|
|
12
|
+
readonly next?: string;
|
|
11
13
|
}
|
|
12
14
|
|
|
13
|
-
export function LogoutButton({ variant = "secondary", className }: LogoutButtonProps) {
|
|
15
|
+
export function LogoutButton({ variant = "secondary", className, next }: LogoutButtonProps) {
|
|
14
16
|
const messages = getAuthMessages(getSoftureConfig());
|
|
15
17
|
return (
|
|
16
18
|
<form action={logoutAction} className={className}>
|
|
19
|
+
{next === undefined ? null : <input type="hidden" name="next" value={next} />}
|
|
17
20
|
<Button type="submit" variant={variant}>
|
|
18
21
|
{messages.logout.submit}
|
|
19
22
|
</Button>
|
package/src/next/pages.tsx
CHANGED
|
@@ -27,6 +27,8 @@ export interface AuthPageProps {
|
|
|
27
27
|
const LAYOUT_CLASS = "sft:mx-auto sft:box-border sft:w-full sft:sm:max-w-md sft:px-4 sft:py-4";
|
|
28
28
|
const FOOTER_CLASS = "sft:m-0 sft:text-sm sft:text-muted";
|
|
29
29
|
const LINK_CLASS = "sft:font-medium sft:text-accent";
|
|
30
|
+
/** The server keeps 512 characters of a registration field; nothing longer is echoed into the page. */
|
|
31
|
+
const MAX_CARRIED_LENGTH = 512;
|
|
30
32
|
|
|
31
33
|
function AuthLayout({ title, lead, children }: { title: string; lead: string; children: ReactNode }) {
|
|
32
34
|
return (
|
|
@@ -74,7 +76,29 @@ export async function LoginPage({ searchParams }: AuthPageProps) {
|
|
|
74
76
|
);
|
|
75
77
|
}
|
|
76
78
|
|
|
79
|
+
export interface RegisterPageOptions {
|
|
80
|
+
/** The consent statement, e.g. with links to the terms and the privacy policy. */
|
|
81
|
+
readonly consentLabel?: ReactNode;
|
|
82
|
+
/** The app's own inputs, before the consent checkbox (`auth({ registrationFields })` declares their names). */
|
|
83
|
+
readonly extraFields?: ReactNode;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* A register page with the app's consent label and extra inputs:
|
|
88
|
+
* `export default createRegisterPage({ consentLabel: <>I accept the <a href="/terms">terms</a></> })`.
|
|
89
|
+
* A declared registration field present in the page's URL (`?z=…`) is carried as a hidden input.
|
|
90
|
+
*/
|
|
91
|
+
export function createRegisterPage(pageOptions: RegisterPageOptions = {}) {
|
|
92
|
+
return async function RegisterPageWithOptions({ searchParams }: AuthPageProps) {
|
|
93
|
+
return renderRegisterPage(searchParams, pageOptions);
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
|
|
77
97
|
export async function RegisterPage({ searchParams }: AuthPageProps) {
|
|
98
|
+
return renderRegisterPage(searchParams, {});
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
async function renderRegisterPage(searchParams: SearchParams | undefined, pageOptions: RegisterPageOptions) {
|
|
78
102
|
const config = getSoftureConfig();
|
|
79
103
|
const routes = getAuthRoutes(config);
|
|
80
104
|
const next = await readNext(searchParams, routes.afterLogin);
|
|
@@ -88,6 +112,7 @@ export async function RegisterPage({ searchParams }: AuthPageProps) {
|
|
|
88
112
|
);
|
|
89
113
|
}
|
|
90
114
|
const options = getAuthOptions(config);
|
|
115
|
+
const carried = await readCarriedFields(searchParams, options.registrationFields);
|
|
91
116
|
return (
|
|
92
117
|
<AuthLayout title={messages.register.title} lead={messages.register.lead}>
|
|
93
118
|
<RegisterForm
|
|
@@ -98,11 +123,30 @@ export async function RegisterPage({ searchParams }: AuthPageProps) {
|
|
|
98
123
|
loginHref={routes.login}
|
|
99
124
|
requireConsent={options.requireConsent}
|
|
100
125
|
minPasswordLength={options.password.minLength}
|
|
126
|
+
consentLabel={pageOptions.consentLabel}
|
|
127
|
+
extraFields={
|
|
128
|
+
<>
|
|
129
|
+
{carried.map(([name, value]) => (
|
|
130
|
+
<input key={name} type="hidden" name={name} value={value} />
|
|
131
|
+
))}
|
|
132
|
+
{pageOptions.extraFields}
|
|
133
|
+
</>
|
|
134
|
+
}
|
|
101
135
|
/>
|
|
102
136
|
</AuthLayout>
|
|
103
137
|
);
|
|
104
138
|
}
|
|
105
139
|
|
|
140
|
+
/** The declared registration fields present in the page's URL, carried into the form as hidden inputs. */
|
|
141
|
+
async function readCarriedFields(searchParams: SearchParams | undefined, declared: readonly string[]): Promise<[string, string][]> {
|
|
142
|
+
const carried: [string, string][] = [];
|
|
143
|
+
for (const name of declared) {
|
|
144
|
+
const value = await readParam(searchParams, name);
|
|
145
|
+
if (value !== undefined && value !== "") carried.push([name, value.slice(0, MAX_CARRIED_LENGTH)]);
|
|
146
|
+
}
|
|
147
|
+
return carried;
|
|
148
|
+
}
|
|
149
|
+
|
|
106
150
|
export async function ChangePasswordPage() {
|
|
107
151
|
const config = getSoftureConfig();
|
|
108
152
|
const routes = getAuthRoutes(config);
|
|
@@ -2,12 +2,49 @@
|
|
|
2
2
|
import type { SoftureConfig } from "@softure-ai/core";
|
|
3
3
|
import { cookies } from "next/headers";
|
|
4
4
|
import type { NewSession } from "../contract.js";
|
|
5
|
+
import { getAuthOptions } from "../server/options.js";
|
|
5
6
|
import { getSessionCookie } from "../session-cookie.js";
|
|
6
7
|
|
|
8
|
+
type CookieStore = Awaited<ReturnType<typeof cookies>>;
|
|
9
|
+
|
|
10
|
+
function readCookie(store: CookieStore, name: string): string | null {
|
|
11
|
+
const value = store.get(name)?.value;
|
|
12
|
+
return value === undefined || value === "" ? null : value;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/** The request's session token: the current cookie's, else the legacy session's (`legacySession`). */
|
|
7
16
|
export async function readSessionToken(config: SoftureConfig): Promise<string | null> {
|
|
8
17
|
const store = await cookies();
|
|
9
|
-
|
|
10
|
-
|
|
18
|
+
return readCookie(store, getSessionCookie(config).name) ?? (await readLegacySessionToken(config));
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/** The legacy session cookie's token, or null (also without `legacySession`). */
|
|
22
|
+
export async function readLegacySessionToken(config: SoftureConfig): Promise<string | null> {
|
|
23
|
+
const name = getAuthOptions(config).legacySession?.cookieName;
|
|
24
|
+
return name === undefined ? null : readCookie(await cookies(), name);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Removes the legacy cookie, if the app declared one: with `Path=/` and the configured domain, the
|
|
29
|
+
* only attributes the module knows. A legacy cookie set on another path or domain stays until it
|
|
30
|
+
* expires; its session row is ended anyway.
|
|
31
|
+
*/
|
|
32
|
+
async function clearLegacySessionCookie(config: SoftureConfig): Promise<void> {
|
|
33
|
+
const name = getAuthOptions(config).legacySession?.cookieName;
|
|
34
|
+
if (name === undefined) return;
|
|
35
|
+
const store = await cookies();
|
|
36
|
+
if (store.get(name) === undefined) return;
|
|
37
|
+
const cookie = getSessionCookie(config);
|
|
38
|
+
// Browsers refuse a `__Host-` cookie with a Domain or without Secure, the removal included.
|
|
39
|
+
const isHostOnly = name.startsWith("__Host-");
|
|
40
|
+
store.set(name, "", {
|
|
41
|
+
httpOnly: true,
|
|
42
|
+
secure: isHostOnly || cookie.secure,
|
|
43
|
+
sameSite: cookie.sameSite,
|
|
44
|
+
path: "/",
|
|
45
|
+
domain: isHostOnly ? undefined : cookie.domain,
|
|
46
|
+
maxAge: 0,
|
|
47
|
+
});
|
|
11
48
|
}
|
|
12
49
|
|
|
13
50
|
/** Only in a server action or a route handler: pages cannot set cookies. */
|
|
@@ -22,6 +59,8 @@ export async function writeSessionCookie(config: SoftureConfig, session: NewSess
|
|
|
22
59
|
domain: cookie.domain,
|
|
23
60
|
maxAge: cookie.maxAgeSeconds,
|
|
24
61
|
});
|
|
62
|
+
// A new session replaces the legacy one: the browser keeps one cookie from here on.
|
|
63
|
+
await clearLegacySessionCookie(config);
|
|
25
64
|
}
|
|
26
65
|
|
|
27
66
|
/** Removes the cookie with the attributes it was set with, so the browser drops that one. */
|
|
@@ -36,4 +75,5 @@ export async function clearSessionCookie(config: SoftureConfig): Promise<void> {
|
|
|
36
75
|
domain: cookie.domain,
|
|
37
76
|
maxAge: 0,
|
|
38
77
|
});
|
|
78
|
+
await clearLegacySessionCookie(config);
|
|
39
79
|
}
|
package/src/options.ts
CHANGED
|
@@ -6,11 +6,21 @@ import type { RegisteredEvent } from "./contract.js";
|
|
|
6
6
|
import type { PasswordResetSender } from "./password-reset-sender.js";
|
|
7
7
|
import { ROLE_NAME_PATTERN } from "./roles.js";
|
|
8
8
|
|
|
9
|
-
/**
|
|
9
|
+
/**
|
|
10
|
+
* OWASP's scrypt cost for passwords: N = 2^17, r = 8, p = 1. One hash takes 128 * N * r bytes
|
|
11
|
+
* (128 MiB) and about 0.4 s of a core; Node runs up to four at once on its libuv pool, so a burst of
|
|
12
|
+
* logins can take 512 MiB. A small server lowers `password.scrypt.cost` (README §3).
|
|
13
|
+
*/
|
|
10
14
|
export const DEFAULT_SCRYPT_COST = 2 ** 17;
|
|
11
15
|
|
|
12
16
|
const MAX_EMAIL_LENGTH = 254;
|
|
13
17
|
const COOKIE_NAME = /^[A-Za-z0-9_-]{1,64}$/;
|
|
18
|
+
/** A legacy cookie may carry its own prefix (`__Host-session`) or a dot. */
|
|
19
|
+
const LEGACY_COOKIE_NAME = /^[A-Za-z0-9_.-]{1,128}$/;
|
|
20
|
+
const DEFAULT_COOKIE_NAME = "softure_session";
|
|
21
|
+
const REGISTRATION_FIELD_NAME = /^[a-z][a-zA-Z0-9_]{0,31}$/;
|
|
22
|
+
/** The register form's own fields, which an app field must not shadow. */
|
|
23
|
+
const REGISTER_FORM_FIELDS: ReadonlySet<string> = new Set(["email", "password", "next", "consent"]);
|
|
14
24
|
const DOMAIN = /^(?=.{1,253}$)[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?(?:\.[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?)+$/;
|
|
15
25
|
|
|
16
26
|
/** Runs inside the registration transaction; a thrown error rolls the registration back. */
|
|
@@ -58,7 +68,7 @@ export const authOptionsSchema = z.strictObject({
|
|
|
58
68
|
.strictObject({
|
|
59
69
|
/** Shortest password a user may set (characters). */
|
|
60
70
|
minLength: z.number().int().min(8).max(128).default(10),
|
|
61
|
-
/** Hash cost. Raising it rehashes each password at its owner's next login. */
|
|
71
|
+
/** Hash cost; memory per hash is 128 * cost * blockSize bytes. Raising it rehashes each password at its owner's next login. */
|
|
62
72
|
scrypt: scryptSchema.prefault({}),
|
|
63
73
|
})
|
|
64
74
|
.prefault({}),
|
|
@@ -71,13 +81,43 @@ export const authOptionsSchema = z.strictObject({
|
|
|
71
81
|
cookie: z
|
|
72
82
|
.strictObject({
|
|
73
83
|
/** Base name; `__Host-` or `__Secure-` is added when the cookie is secure. */
|
|
74
|
-
name: z.string().regex(COOKIE_NAME, "must be 1-64 letters, digits, _ or -").default(
|
|
84
|
+
name: z.string().regex(COOKIE_NAME, "must be 1-64 letters, digits, _ or -").default(DEFAULT_COOKIE_NAME),
|
|
75
85
|
/** Share the session with subdomains, e.g. `example.com` for the apex and `app.example.com`. */
|
|
76
86
|
domain: z.string().regex(DOMAIN, "must be a lowercase host name such as example.com").optional(),
|
|
77
87
|
/** Defaults to whether `appOrigin` is https. */
|
|
78
88
|
secure: z.boolean().optional(),
|
|
79
89
|
})
|
|
80
90
|
.prefault({}),
|
|
91
|
+
/**
|
|
92
|
+
* Sessions of the system the app took over, so adopting the module does not log everyone out:
|
|
93
|
+
* the cookie it set and the shape of its tokens, stored as the sha256 hex of the token like here.
|
|
94
|
+
* Read when the current cookie is absent; ended and cleared at the next login, register or logout.
|
|
95
|
+
*/
|
|
96
|
+
legacySession: z
|
|
97
|
+
.strictObject({
|
|
98
|
+
/** The old cookie's full name, prefix included. */
|
|
99
|
+
cookieName: z.string().regex(LEGACY_COOKIE_NAME, "must be 1-128 letters, digits, _ . or -"),
|
|
100
|
+
/** The whole token's shape, e.g. /[0-9a-f]{64}/; anchored by the module. */
|
|
101
|
+
tokenPattern: z.custom<RegExp>(
|
|
102
|
+
(value) => value instanceof RegExp && !value.global && !value.sticky,
|
|
103
|
+
"must be a RegExp without the g or y flag",
|
|
104
|
+
),
|
|
105
|
+
})
|
|
106
|
+
.optional(),
|
|
107
|
+
/**
|
|
108
|
+
* Extra register form fields handed to `onRegistered` as `event.fields` (strings, at most 512
|
|
109
|
+
* characters; empty ones are left out). `RegisterPage` carries a declared field from its URL as a
|
|
110
|
+
* hidden input (e.g. `?z=` for a channel tag). Values come from the client: validate them in the hook.
|
|
111
|
+
*/
|
|
112
|
+
registrationFields: z
|
|
113
|
+
.array(
|
|
114
|
+
z
|
|
115
|
+
.string()
|
|
116
|
+
.regex(REGISTRATION_FIELD_NAME, "must be a field name such as channel (a-z first, then letters, digits or _, at most 32)")
|
|
117
|
+
.refine((name) => !REGISTER_FORM_FIELDS.has(name), "is a field of the register form itself"),
|
|
118
|
+
)
|
|
119
|
+
.refine((names) => new Set(names).size === names.length, "must not repeat a name")
|
|
120
|
+
.default([]),
|
|
81
121
|
/** Registration needs a ticked consent checkbox. */
|
|
82
122
|
requireConsent: z.boolean().default(true),
|
|
83
123
|
/** Declared default of the `auth.registration_closed` switch. */
|
|
@@ -101,6 +141,12 @@ export const authOptionsSchema = z.strictObject({
|
|
|
101
141
|
onRegistered: z.custom<OnRegisteredHook>((value) => typeof value === "function", "must be a function").optional(),
|
|
102
142
|
/** Rewrites the path of every auth redirect (e.g. `tagRedirect` from `@softure-ai/analytics/next`). */
|
|
103
143
|
rewriteRedirect: z.custom<RewriteRedirect>((value) => typeof value === "function", "must be a function").optional(),
|
|
144
|
+
}).superRefine((options, context) => {
|
|
145
|
+
const legacy = options.legacySession?.cookieName;
|
|
146
|
+
const base = options.cookie.name;
|
|
147
|
+
if (legacy !== undefined && [base, `__Host-${base}`, `__Secure-${base}`].includes(legacy)) {
|
|
148
|
+
context.addIssue({ code: "custom", path: ["legacySession", "cookieName"], message: "must differ from the current session cookie's name" });
|
|
149
|
+
}
|
|
104
150
|
});
|
|
105
151
|
|
|
106
152
|
export type AuthOptionsInput = z.input<typeof authOptionsSchema>;
|