@softure-ai/auth 0.1.13 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -4,6 +4,19 @@ Newest first. Each version lists what changed for an app that uses `@softure-ai/
4
4
  production, the version gets a line `verified in: <app>@<commit>` ([docs/05](../../docs/05-adoption-playbook.md),
5
5
  "Definition of done"). Versions before the first one below are described in their GitHub Releases (`auth@x.y.z`).
6
6
 
7
+ ## 0.2.0
8
+
9
+ - **Breaking (#446):** the built-in `pl` dictionary is gone; English is the only built-in copy and the fallback for
10
+ every other locale, which is now any BCP 47 tag. Migrate: an app that shows Polish keeps its own translation and
11
+ passes it as the overrides for its locale, `auth({ messages: { pl: myTranslation } })`; a key it leaves out reads
12
+ English.
13
+ - `createAuthGuard` with `redirect: "relative"` answers 307 inside Next's proxy instead of 500 (`Invalid URL`): the
14
+ login URL is built on the request URL's own origin, which Next sends to the browser path-only, as before (#452). An
15
+ app that went back to the absolute redirect with its stack's origin in `origins.trustedOrigins` can switch back.
16
+ - `createAuthGuard` drops Next's `_rsc` cache key from `next=` and keeps every other query parameter as the request
17
+ spelled it, so a signed-out client navigation no longer lands on `/page?_rsc=…` after sign-in (#424). An app that
18
+ strips `_rsc` before calling the guard can drop that.
19
+
7
20
  ## 0.1.13
8
21
 
9
22
  - `resolveOnlyAccount({ db, envName, env? })` in `@softure-ai/auth/server`: the account a local tool acts for, named by
package/README.md CHANGED
@@ -54,7 +54,7 @@ import { cloudflareIp, overrideBuckets, security } from "@softure-ai/security";
54
54
 
55
55
  const config = defineSoftureConfig({
56
56
  database: { url: process.env.DATABASE_URL! },
57
- locale: "pl",
57
+ locale: "en",
58
58
  timezone: "Europe/Warsaw",
59
59
  appOrigin: process.env.APP_ORIGIN!,
60
60
  modules: [
@@ -93,7 +93,7 @@ export default config;
93
93
  | `passwordReset.send` | `(link, user, details) => Promise<void>` | none | Delivers reset links (section 4, "Password reset"). Without it password reset is off. |
94
94
  | `passwordReset.ttlMinutes` | `number` (5-1440) | `60` | How long a reset link works. |
95
95
  | `routes` | `{ login, register, changePassword, forgotPassword, resetPassword, afterLogin, afterLogout }` | `/login`, `/register`, `/account/password`, `/forgot-password`, `/reset-password`, `/`, `/login` | Where the pages are mounted and where users land. |
96
- | `messages` | partial `pl` / `en` dictionaries | built in | Copy overrides (section 9). |
96
+ | `messages` | partial dictionaries per locale (`en` built in; any other is the app's own translation) | built in | Copy overrides (section 9). |
97
97
 
98
98
  **Cookie.** Always `HttpOnly`, `SameSite=Lax`, `Path=/`, `Max-Age` = the TTL. A secure cookie gets
99
99
  the prefix browsers enforce: `__Host-softure_session` when it is host-only, `__Secure-softure_session`
@@ -198,8 +198,8 @@ Private prefixes still belong behind the route guard below; the option covers th
198
198
  (billing's payment page passes its parameters).
199
199
 
200
200
  **Route guard.** `createAuthGuard` returns `(request) => Response | null`: a redirect to the login
201
- page (with `?next=`) for a protected path without a session cookie, `null` otherwise. It only
202
- checks that the cookie is present, so **every private page and action still calls
201
+ page (with `?next=`, the path and query without Next's `_rsc` cache key) for a protected path without a session
202
+ cookie, `null` otherwise. It only checks that the cookie is present, so **every private page and action still calls
203
203
  `requireUser`**: the guard is a convenience, not the access check. Paths are compared decoded and
204
204
  lowercased (`/%61ccount` and `/ACCOUNT` are guarded like `/account`). It imports nothing from Next,
205
205
  so it chains with other proxy pieces:
@@ -259,8 +259,9 @@ never guarded, so `protect: ["/"]` cannot send the login page to itself. The cha
259
259
  stays guarded even under an excluded prefix.
260
260
 
261
261
  A stack the config cannot list (an integration run on a random port, a host added at deploy time)
262
- sets `redirect: "relative"`: the `Location` is the path only (`/login?next=%2Faccount`), so the browser
263
- stays on the host and port it used and no request header is read. An app whose image serves hosts it
262
+ sets `redirect: "relative"`: the login URL is built on the request URL's own origin, which Next's proxy sends to
263
+ the browser as the path only (`/login?next=%2Faccount`), so the browser stays on the host and port it used and no
264
+ request header is read. Outside Next's proxy the `Location` stays absolute on the request URL's origin. An app whose image serves hosts it
264
265
  does not know in advance can instead set the config's `origins.trustRequestHost` (core README).
265
266
 
266
267
  **Roles.** A role is a declared name (`admin`, plus `auth({ roles: ["editor"] })`) held by an
@@ -563,8 +564,9 @@ for the submit button's class), `submitVariant` (a `Button` variant, `primary` b
563
564
 
564
565
  ## 9. Copy
565
566
 
566
- `authMessages.en` and `authMessages.pl`, overridable per locale:
567
- `auth({ messages: { en: { login: { title: "Sign in to Acme" } } } })`. Groups: `fields`, `login`,
567
+ `authMessages.en` (English, the only built-in language), overridable per locale:
568
+ `auth({ messages: { en: { login: { title: "Sign in to Acme" } } } })`; another language is the app's own
569
+ translation under its locale, `auth({ messages: { de: authDe } })`. Groups: `fields`, `login`,
568
570
  `register`, `changePassword`, `forgotPassword`, `resetPassword`, `resetMail` (the reset mail of
569
571
  `mailingResetSender()`; `minutes` holds plural forms), `logout`, and `errors.{auth,security,core}` keyed by the error code
570
572
  (`auth.invalid_credentials` → `errors.auth.invalid_credentials`). `getAuthErrorMessage(messages, code)`
package/dist/index.js CHANGED
@@ -36,8 +36,8 @@ export const AUTH_RATE_LIMIT_BUCKETS = {
36
36
  export const auth = defineModule({
37
37
  manifest: {
38
38
  id: MODULE_ID,
39
- version: "0.1.13",
40
- dependsOn: { security: "^0.1.0", mailing: "^0.1.0?", ops: "^0.1.0?" },
39
+ version: "0.2.0",
40
+ dependsOn: { security: "^0.2.0", mailing: "^0.2.0?", ops: "^0.2.0?" },
41
41
  dbSchema: "auth",
42
42
  tables: ["users", "sessions", "user_roles", "password_resets"],
43
43
  env: [
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,oGAAoG;AACpG,qIAAqI;AACrI,4EAA4E;AAC5E,OAAO,EAAE,YAAY,EAAE,oBAAoB,EAAE,MAAM,kBAAkB,CAAC;AAEtE,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;A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oot":"","sources":["../../src/mailing/reset-mail.ts"],"names":[],"mappings":"AAGA,OAAO,EAAiB,KAAK,MAAM,EAAoD,MAAM,kBAAkB,CAAC;AAEhH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAExD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AACzD,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,6BAA6B,CAAC;AAGvE,MAAM,WAAW,sBAAsB;IACrC,+CAA+C;IAC/C,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,4DAA4D;IAC5D,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;CAC7B;AAED,qEAAqE;AACrE,MAAM,MAAM,iBAAiB,GAAG,IAAI,CAAC,YAAY,EAAE,SAAS,GAAG,MAAM,CAAC,GAAG;IAAE,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;CAAE,CAAC;AAQnG;;;GAGG;AACH,wBAAgB,uBAAuB,CAAC,QAAQ,EAAE,YAAY,EAAE,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,sBAAsB,GAAG,iBAAiB,CAehI;AAQD;;;;;GAKG;AACH,wBAAgB,kBAAkB,IAAI,mBAAmB,CAYxD"}
@@ -1,7 +1,7 @@
1
1
  // The password reset mail: rendered from auth's dictionaries in the app's locale and sent through
2
2
  // `@softure-ai/mailing`. A transactional mail: no unsubscribe link, never suppressed. The link is
3
3
  // placed by the code, never by a translatable string, so a copy override cannot drop it.
4
- import { formatMessage, selectPlural } from "@softure-ai/core";
4
+ import { formatMessage, selectMessages, selectPlural } from "@softure-ai/core";
5
5
  import { getSoftureConfig } from "@softure-ai/core/next";
6
6
  import { sendMail } from "@softure-ai/mailing/server";
7
7
  import { getAuthModule, getAuthOptions } from "../server/options.js";
@@ -31,7 +31,7 @@ export function renderPasswordResetMail(messages, locale, input) {
31
31
  /** The app's auth dictionary for `locale`, with its overrides applied. */
32
32
  function getMessages(config, locale) {
33
33
  // The module factory merged the dictionaries; their shape is the module's own.
34
- return getAuthModule(config).messages[locale];
34
+ return selectMessages(getAuthModule(config).messages, locale);
35
35
  }
36
36
  /**
37
37
  * A `passwordReset.send` that mails the link through `@softure-ai/mailing`:
@@ -1 +1 @@
1
- {"version":3,"file":"reset-mail.js","sourceRoot":"","sources":["../../src/mailing/reset-mail.ts"],"names":[],"mappings":"AAAA,kGAAkG;AAClG,kGAAkG;AAClG,yFAAyF;AACzF,OAAO,EAAE,aAAa,EAAE,YAAY,EAAmC,MAAM,kBAAkB,CAAC;AAChG,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AAEzD,OAAO,EAAE,QAAQ,EAAE,MAAM,4BAA4B,CAAC;AAGtD,OAAO,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAYrE,MAAM,YAAY,GAAqC,EAAE,GAAG,EAAE,OAAO,EAAE,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,QAAQ,EAAE,GAAG,EAAE,OAAO,EAAE,CAAC;AAE/H,SAAS,UAAU,CAAC,KAAa;IAC/B,OAAO,KAAK,CAAC,OAAO,CAAC,UAAU,EAAE,CAAC,SAAS,EAAE,EAAE,CAAC,YAAY,CAAC,SAAS,CAAC,IAAI,SAAS,CAAC,CAAC;AACxF,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,uBAAuB,CAAC,QAAsB,EAAE,MAAc,EAAE,KAA6B;IAC3G,MAAM,IAAI,GAAG,QAAQ,CAAC,SAAS,CAAC;IAChC,MAAM,QAAQ,GAAG,aAAa,CAAC,YAAY,CAAC,MAAM,EAAE,KAAK,CAAC,UAAU,EAAE,IAAI,CAAC,OAAO,CAAC,EAAE,EAAE,KAAK,EAAE,KAAK,CAAC,UAAU,EAAE,CAAC,CAAC;IAClH,MAAM,MAAM,GAAG,aAAa,CAAC,IAAI,CAAC,MAAM,EAAE,EAAE,QAAQ,EAAE,CAAC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AC,MAAM,EAAE,OAAO,CAAC,MAAM,CAAC,EAAE,OAAO,CAAC,MAAM,EAAE;YACxF,IAAI;YACJ,UAAU,EAAE,cAAc,CAAC,MAAM,CAAC,CAAC,aAAa,CAAC,UAAU;SAC5D,CAAC,CAAC;QACH,MAAM,MAAM,GAAG,MAAM,QAAQ,CAAC,EAAE,MAAM,EAAE,EAAE,EAAE,EAAE,EAAE,IAAI,CAAC,KAAK,EAAE,GAAG,IAAI,EAAE,CAAC,CAAC;QACvE,IAAI,CAAC,MAAM,CAAC,EAAE,EAAE,CAAC;YACf,MAAM,IAAI,KAAK,CAAC,2DAA2D,MAAM,CAAC,KAAK,GAAG,CAAC,CAAC;QAC9F,CAAC;IACH,CAAC,CAAC;AACJ,CAAC"}
@@ -1,6 +1,6 @@
1
1
  import type { AuthFormErrorCode } from "../contract.js";
2
2
  import { en } from "./en.js";
3
- /** Complete default dictionaries; apps pass partial overrides per locale. */
3
+ /** The built-in English dictionary; an app passes partial overrides or its own translation per locale. */
4
4
  export declare const authMessages: {
5
5
  en: {
6
6
  fields: {
@@ -98,102 +98,6 @@ export declare const authMessages: {
98
98
  };
99
99
  };
100
100
  };
101
- pl: {
102
- fields: {
103
- email: string;
104
- password: string;
105
- currentPassword: string;
106
- newPassword: string;
107
- newPasswordHint: string;
108
- consent: string;
109
- };
110
- login: {
111
- title: string;
112
- lead: string;
113
- submit: string;
114
- pending: string;
115
- noAccount: string;
116
- registerLink: string;
117
- forgotPassword: string;
118
- };
119
- register: {
120
- title: string;
121
- lead: string;
122
- submit: string;
123
- pending: string;
124
- hasAccount: string;
125
- loginLink: string;
126
- closedTitle: string;
127
- closedBody: string;
128
- };
129
- changePassword: {
130
- title: string;
131
- lead: string;
132
- submit: string;
133
- pending: string;
134
- success: string;
135
- };
136
- forgotPassword: {
137
- title: string;
138
- lead: string;
139
- submit: string;
140
- pending: string;
141
- sent: string;
142
- backToLogin: string;
143
- };
144
- resetPassword: {
145
- title: string;
146
- lead: string;
147
- submit: string;
148
- pending: string;
149
- success: string;
150
- invalidTitle: string;
151
- invalidBody: string;
152
- requestNew: string;
153
- };
154
- resetMail: {
155
- subject: string;
156
- greeting: string;
157
- intro: string;
158
- action: string;
159
- expiry: string;
160
- minutes: {
161
- one: string;
162
- few: string;
163
- many: string;
164
- other: string;
165
- };
166
- ignore: string;
167
- };
168
- logout: {
169
- submit: string;
170
- };
171
- errors: {
172
- auth: {
173
- invalid_credentials: string;
174
- email_invalid: string;
175
- email_taken: string;
176
- password_too_short: string;
177
- password_too_long: string;
178
- consent_required: string;
179
- registration_closed: string;
180
- current_password_invalid: string;
181
- password_unchanged: string;
182
- unauthenticated: string;
183
- forbidden: string;
184
- reset_token_invalid: string;
185
- password_reset_unavailable: string;
186
- };
187
- security: {
188
- rate_limited: string;
189
- client_unidentified: string;
190
- };
191
- core: {
192
- database_failed: string;
193
- unexpected: string;
194
- };
195
- };
196
- };
197
101
  };
198
102
  export type AuthMessages = typeof en;
199
103
  /** The copy for an error code; an unknown code gets the generic failure. */
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/messages/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AACxD,OAAO,EAAE,EAAE,EAAE,MAAM,SAAS,CAAC;AAG7B,6EAA6E;AAC7E,eAAO,MAAM,YAAY;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAAa,CAAC;AAEvC,MAAM,MAAM,YAAY,GAAG,OAAO,EAAE,CAAC;AAErC,4EAA4E;AAC5E,wBAAgB,mBAAmB,CAAC,QAAQ,EAAE,YAAY,EAAE,IAAI,EAAE,iBAAiB,GAAG,MAAM,CAI3F"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/messages/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AACxD,OAAO,EAAE,EAAE,EAAE,MAAM,SAAS,CAAC;AAE7B,0GAA0G;AAC1G,eAAO,MAAM,YAAY;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAAS,CAAC;AAEnC,MAAM,MAAM,YAAY,GAAG,OAAO,EAAE,CAAC;AAErC,4EAA4E;AAC5E,wBAAgB,mBAAmB,CAAC,QAAQ,EAAE,YAAY,EAAE,IAAI,EAAE,iBAAiB,GAAG,MAAM,CAI3F"}
@@ -1,7 +1,6 @@
1
1
  import { en } from "./en.js";
2
- import { pl } from "./pl.js";
3
- /** Complete default dictionaries; apps pass partial overrides per locale. */
4
- export const authMessages = { en, pl };
2
+ /** The built-in English dictionary; an app passes partial overrides or its own translation per locale. */
3
+ export const authMessages = { en };
5
4
  /** The copy for an error code; an unknown code gets the generic failure. */
6
5
  export function getAuthErrorMessage(messages, code) {
7
6
  const [namespace, name] = code.split(".", 2);
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/messages/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,EAAE,EAAE,MAAM,SAAS,CAAC;AAC7B,OAAO,EAAE,EAAE,EAAE,MAAM,SAAS,CAAC;AAE7B,6EAA6E;AAC7E,MAAM,CAAC,MAAM,YAAY,GAAG,EAAE,EAAE,EAAE,EAAE,EAAE,CAAC;AAIvC,4EAA4E;AAC5E,MAAM,UAAU,mBAAmB,CAAC,QAAsB,EAAE,IAAuB;IACjF,MAAM,CAAC,SAAS,EAAE,IAAI,CAAC,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC,CAAqB,CAAC;IACjE,MAAM,KAAK,GAAkD,QAAQ,CAAC,MAAqE,CAAC,SAAS,CAAC,CAAC;IACvJ,OAAO,CAAC,KAAK,KAAK,SAAS,IAAI,MAAM,CAAC,MAAM,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,IAAI,QAAQ,CAAC,MAAM,CAAC,IAAI,CAAC,UAAU,CAAC;AAC1H,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/messages/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,EAAE,EAAE,MAAM,SAAS,CAAC;AAE7B,0GAA0G;AAC1G,MAAM,CAAC,MAAM,YAAY,GAAG,EAAE,EAAE,EAAE,CAAC;AAInC,4EAA4E;AAC5E,MAAM,UAAU,mBAAmB,CAAC,QAAsB,EAAE,IAAuB;IACjF,MAAM,CAAC,SAAS,EAAE,IAAI,CAAC,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC,CAAqB,CAAC;IACjE,MAAM,KAAK,GAAkD,QAAQ,CAAC,MAAqE,CAAC,SAAS,CAAC,CAAC;IACvJ,OAAO,CAAC,KAAK,KAAK,SAAS,IAAI,MAAM,CAAC,MAAM,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,IAAI,QAAQ,CAAC,MAAM,CAAC,IAAI,CAAC,UAAU,CAAC;AAC1H,CAAC"}
@@ -1,4 +1,4 @@
1
- import type { SoftureConfig } from "@softure-ai/core";
1
+ import { type SoftureConfig } from "@softure-ai/core";
2
2
  import type { AuthMessages } from "../messages/index.js";
3
3
  /** The module's copy in the app's locale, with the app's overrides applied. */
4
4
  export declare function getAuthMessages(config: SoftureConfig): AuthMessages;
@@ -1 +1 @@
1
- {"version":3,"file":"messages.d.ts","sourceRoot":"","sources":["../../src/next/messages.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AACtD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AAGzD,+EAA+E;AAC/E,wBAAgB,eAAe,CAAC,MAAM,EAAE,aAAa,GAAG,YAAY,CAGnE"}
1
+ {"version":3,"file":"messages.d.ts","sourceRoot":"","sources":["../../src/next/messages.ts"],"names":[],"mappings":"AAAA,OAAO,EAAkB,KAAK,aAAa,EAAE,MAAM,kBAAkB,CAAC;AACtE,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AAGzD,+EAA+E;AAC/E,wBAAgB,eAAe,CAAC,MAAM,EAAE,aAAa,GAAG,YAAY,CAGnE"}
@@ -1,7 +1,8 @@
1
+ import { selectMessages } from "@softure-ai/core";
1
2
  import { getAuthModule } from "../server/options.js";
2
3
  /** The module's copy in the app's locale, with the app's overrides applied. */
3
4
  export function getAuthMessages(config) {
4
5
  // The module factory merged the dictionaries; their shape is the module's own.
5
- return getAuthModule(config).messages[config.locale];
6
+ return selectMessages(getAuthModule(config).messages, config.locale);
6
7
  }
7
8
  //# sourceMappingURL=messages.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"messages.js","sourceRoot":"","sources":["../../src/next/messages.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAErD,+EAA+E;AAC/E,MAAM,UAAU,eAAe,CAAC,MAAqB;IACnD,+EAA+E;IAC/E,OAAO,aAAa,CAAC,MAAM,CAAC,CAAC,QAAQ,CAAC,MAAM,CAAC,MAAM,CAAiB,CAAC;AACvE,CAAC"}
1
+ {"version":3,"file":"messages.js","sourceRoot":"","sources":["../../src/next/messages.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAsB,MAAM,kBAAkB,CAAC;AAEtE,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAErD,+EAA+E;AAC/E,MAAM,UAAU,eAAe,CAAC,MAAqB;IACnD,+EAA+E;IAC/E,OAAO,cAAc,CAAC,aAAa,CAAC,MAAM,CAAC,CAAC,QAAQ,EAAE,MAAM,CAAC,MAAM,CAAiB,CAAC;AACvF,CAAC"}
@@ -20,9 +20,11 @@ export interface AuthGuardOptions {
20
20
  */
21
21
  readonly trustedOrigins?: readonly string[];
22
22
  /**
23
- * `"absolute"` (default): the login URL is built on the resolved origin (above). `"relative"`: the `Location` is
24
- * the path only (`/login?next=…`), so the browser stays on whatever host and port it used; for a stack served on
25
- * ports or hosts the config cannot list (an integration run on a random port).
23
+ * `"absolute"` (default): the login URL is built on the resolved origin (above). `"relative"`: it is built on the
24
+ * request URL's own origin, which Next's proxy sends to the browser as the path only (`/login?next=…`), so the
25
+ * browser stays on whatever host and port it used; for a stack served on ports or hosts the config cannot list (an
26
+ * integration run on a random port). Outside Next the `Location` stays absolute on that origin, which behind a
27
+ * reverse proxy is the internal one: keep the default there.
26
28
  */
27
29
  readonly redirect?: "absolute" | "relative";
28
30
  }
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/proxy/index.ts"],"names":[],"mappings":"AASA,OAAO,EAAiC,KAAK,aAAa,EAAE,MAAM,kBAAkB,CAAC;AAIrF,MAAM,WAAW,gBAAgB;IAC/B,kGAAkG;IAClG,QAAQ,CAAC,OAAO,EAAE,SAAS,MAAM,EAAE,CAAC;IACpC;;;OAGG;IACH,QAAQ,CAAC,OAAO,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;IACrC;;;OAGG;IACH,QAAQ,CAAC,YAAY,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;IAC1C;;;;;OAKG;IACH,QAAQ,CAAC,cAAc,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;IAC5C;;;;OAIG;IACH,QAAQ,CAAC,QAAQ,CAAC,EAAE,UAAU,GAAG,UAAU,CAAC;CAC7C;AAKD,MAAM,MAAM,SAAS,GAAG,CAAC,OAAO,EAAE,OAAO,KAAK,QAAQ,GAAG,IAAI,CAAC;AAE9D,6GAA6G;AAC7G,wBAAgB,eAAe,CAAC,MAAM,EAAE,aAAa,EAAE,OAAO,EAAE,gBAAgB,GAAG,SAAS,CAoC3F"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/proxy/index.ts"],"names":[],"mappings":"AASA,OAAO,EAAiC,KAAK,aAAa,EAAE,MAAM,kBAAkB,CAAC;AAIrF,MAAM,WAAW,gBAAgB;IAC/B,kGAAkG;IAClG,QAAQ,CAAC,OAAO,EAAE,SAAS,MAAM,EAAE,CAAC;IACpC;;;OAGG;IACH,QAAQ,CAAC,OAAO,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;IACrC;;;OAGG;IACH,QAAQ,CAAC,YAAY,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;IAC1C;;;;;OAKG;IACH,QAAQ,CAAC,cAAc,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;IAC5C;;;;;;OAMG;IACH,QAAQ,CAAC,QAAQ,CAAC,EAAE,UAAU,GAAG,UAAU,CAAC;CAC7C;AAKD,MAAM,MAAM,SAAS,GAAG,CAAC,OAAO,EAAE,OAAO,KAAK,QAAQ,GAAG,IAAI,CAAC;AAE9D,6GAA6G;AAC7G,wBAAgB,eAAe,CAAC,MAAM,EAAE,aAAa,EAAE,OAAO,EAAE,gBAAgB,GAAG,SAAS,CAqC3F"}
@@ -45,13 +45,33 @@ export function createAuthGuard(config, options) {
45
45
  // Built on appOrigin, or on the request's public origin when the app trusts it: behind a proxy
46
46
  // the request URL carries an internal host, and request headers alone are never trusted.
47
47
  const login = new URL(routes.login, resolveAppOrigin(config, request, { trustedOrigins }));
48
- login.searchParams.set("next", `${url.pathname}${url.search}`);
48
+ login.searchParams.set("next", getReturnPath(url));
49
49
  if (options.redirect !== "relative")
50
50
  return Response.redirect(login, 307);
51
- // A path-only Location reads no request header at all; `Response.redirect` would need an absolute URL.
52
- return new Response(null, { status: 307, headers: { location: `${login.pathname}${login.search}` } });
51
+ // On the origin the request URL names, reading no request header. Next's proxy needs an absolute Location
52
+ // (a path-only one is a 500) and sends a same-host one to the browser path-only (#452).
53
+ return Response.redirect(new URL(`${login.pathname}${login.search}`, url.origin), 307);
53
54
  };
54
55
  }
56
+ /** Next's client-navigation cache key: meaningless to the page, so it never belongs in a return address. */
57
+ const NEXT_CACHE_KEY = "_rsc";
58
+ /**
59
+ * The path and query to come back to after sign-in, without Next's `_rsc`. The raw query segments are
60
+ * filtered rather than rebuilt, so every other parameter keeps the spelling the request gave it.
61
+ */
62
+ function getReturnPath(url) {
63
+ const segments = url.search.slice(1).split("&").filter((segment) => segment !== "" && !isNextCacheKey(segment));
64
+ return segments.length === 0 ? url.pathname : `${url.pathname}?${segments.join("&")}`;
65
+ }
66
+ function isNextCacheKey(segment) {
67
+ const name = segment.split("=", 1)[0] ?? "";
68
+ try {
69
+ return decodeURIComponent(name) === NEXT_CACHE_KEY;
70
+ }
71
+ catch {
72
+ return false;
73
+ }
74
+ }
55
75
  function normalizePrefix(prefix, kind) {
56
76
  if (!prefix.startsWith("/")) {
57
77
  throw new Error(`createAuthGuard: ${kind} path "${prefix}" must start with /`);
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/proxy/index.ts"],"names":[],"mappings":"AAAA,iGAAiG;AACjG,gGAAgG;AAChG,mGAAmG;AACnG,sDAAsD;AACtD,EAAE;AACF,6FAA6F;AAC7F,6FAA6F;AAC7F,mGAAmG;AACnG,mGAAmG;AACnG,OAAO,EAAE,WAAW,EAAE,gBAAgB,EAAsB,MAAM,kBAAkB,CAAC;AACrF,OAAO,EAAE,cAAc,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AACrE,OAAO,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AA8B1E,+GAA+G;AAC/G,MAAM,aA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"ops": "^0.1.0?" },
3
+ "version": "0.2.0",
4
+ "dependsOn": { "security": "^0.2.0", "mailing": "^0.2.0?", "ops": "^0.2.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.13",
3
+ "version": "0.2.0",
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",
@@ -72,21 +72,21 @@
72
72
  "build": "tsc -p tsconfig.build.json"
73
73
  },
74
74
  "dependencies": {
75
- "@softure-ai/core": "^0.1.8",
75
+ "@softure-ai/core": "^0.2.0",
76
76
  "@softure-ai/db": "^0.1.0",
77
- "@softure-ai/security": "^0.1.8",
77
+ "@softure-ai/security": "^0.2.0",
78
78
  "zod": "^4.6.5"
79
79
  },
80
80
  "peerDependencies": {
81
- "@softure-ai/mailing": "^0.1.0",
82
- "@softure-ai/ops": "^0.1.0",
83
- "@softure-ai/ui": "^0.1.0 || ^0.2.0",
81
+ "@softure-ai/mailing": "^0.2.0",
82
+ "@softure-ai/ops": "^0.2.0",
83
+ "@softure-ai/ui": "^0.3.0",
84
84
  "drizzle-orm": "^0.45.2",
85
85
  "next": "^16.0.0",
86
86
  "react": "^19.0.0"
87
87
  },
88
88
  "devDependencies": {
89
- "@softure-ai/ui": "^0.1.7 || ^0.2.0"
89
+ "@softure-ai/ui": "^0.3.0"
90
90
  },
91
91
  "peerDependenciesMeta": {
92
92
  "@softure-ai/mailing": {
package/src/index.ts CHANGED
@@ -42,8 +42,8 @@ export const AUTH_RATE_LIMIT_BUCKETS = {
42
42
  export const auth = defineModule({
43
43
  manifest: {
44
44
  id: MODULE_ID,
45
- version: "0.1.13",
46
- dependsOn: { security: "^0.1.0", mailing: "^0.1.0?", ops: "^0.1.0?" },
45
+ version: "0.2.0",
46
+ dependsOn: { security: "^0.2.0", mailing: "^0.2.0?", ops: "^0.2.0?" },
47
47
  dbSchema: "auth",
48
48
  tables: ["users", "sessions", "user_roles", "password_resets"],
49
49
  env: [
@@ -1,7 +1,7 @@
1
1
  // The password reset mail: rendered from auth's dictionaries in the app's locale and sent through
2
2
  // `@softure-ai/mailing`. A transactional mail: no unsubscribe link, never suppressed. The link is
3
3
  // placed by the code, never by a translatable string, so a copy override cannot drop it.
4
- import { formatMessage, selectPlural, type Locale, type SoftureConfig } from "@softure-ai/core";
4
+ import { formatMessage, type Locale, selectMessages, selectPlural, type SoftureConfig } from "@softure-ai/core";
5
5
  import { getSoftureConfig } from "@softure-ai/core/next";
6
6
  import type { OutgoingMail } from "@softure-ai/mailing";
7
7
  import { sendMail } from "@softure-ai/mailing/server";
@@ -49,7 +49,7 @@ export function renderPasswordResetMail(messages: AuthMessages, locale: Locale,
49
49
  /** The app's auth dictionary for `locale`, with its overrides applied. */
50
50
  function getMessages(config: SoftureConfig, locale: Locale): AuthMessages {
51
51
  // The module factory merged the dictionaries; their shape is the module's own.
52
- return getAuthModule(config).messages[locale] as AuthMessages;
52
+ return selectMessages(getAuthModule(config).messages, locale) as AuthMessages;
53
53
  }
54
54
 
55
55
  /**
@@ -1,9 +1,8 @@
1
1
  import type { AuthFormErrorCode } from "../contract.js";
2
2
  import { en } from "./en.js";
3
- import { pl } from "./pl.js";
4
3
 
5
- /** Complete default dictionaries; apps pass partial overrides per locale. */
6
- export const authMessages = { en, pl };
4
+ /** The built-in English dictionary; an app passes partial overrides or its own translation per locale. */
5
+ export const authMessages = { en };
7
6
 
8
7
  export type AuthMessages = typeof en;
9
8
 
@@ -1,9 +1,9 @@
1
- import type { SoftureConfig } from "@softure-ai/core";
1
+ import { selectMessages, type SoftureConfig } from "@softure-ai/core";
2
2
  import type { AuthMessages } from "../messages/index.js";
3
3
  import { getAuthModule } from "../server/options.js";
4
4
 
5
5
  /** The module's copy in the app's locale, with the app's overrides applied. */
6
6
  export function getAuthMessages(config: SoftureConfig): AuthMessages {
7
7
  // The module factory merged the dictionaries; their shape is the module's own.
8
- return getAuthModule(config).messages[config.locale] as AuthMessages;
8
+ return selectMessages(getAuthModule(config).messages, config.locale) as AuthMessages;
9
9
  }
@@ -32,9 +32,11 @@ export interface AuthGuardOptions {
32
32
  */
33
33
  readonly trustedOrigins?: readonly string[];
34
34
  /**
35
- * `"absolute"` (default): the login URL is built on the resolved origin (above). `"relative"`: the `Location` is
36
- * the path only (`/login?next=…`), so the browser stays on whatever host and port it used; for a stack served on
37
- * ports or hosts the config cannot list (an integration run on a random port).
35
+ * `"absolute"` (default): the login URL is built on the resolved origin (above). `"relative"`: it is built on the
36
+ * request URL's own origin, which Next's proxy sends to the browser as the path only (`/login?next=…`), so the
37
+ * browser stays on whatever host and port it used; for a stack served on ports or hosts the config cannot list (an
38
+ * integration run on a random port). Outside Next the `Location` stays absolute on that origin, which behind a
39
+ * reverse proxy is the internal one: keep the default there.
38
40
  */
39
41
  readonly redirect?: "absolute" | "relative";
40
42
  }
@@ -76,13 +78,35 @@ export function createAuthGuard(config: SoftureConfig, options: AuthGuardOptions
76
78
  // Built on appOrigin, or on the request's public origin when the app trusts it: behind a proxy
77
79
  // the request URL carries an internal host, and request headers alone are never trusted.
78
80
  const login = new URL(routes.login, resolveAppOrigin(config, request, { trustedOrigins }));
79
- login.searchParams.set("next", `${url.pathname}${url.search}`);
81
+ login.searchParams.set("next", getReturnPath(url));
80
82
  if (options.redirect !== "relative") return Response.redirect(login, 307);
81
- // A path-only Location reads no request header at all; `Response.redirect` would need an absolute URL.
82
- return new Response(null, { status: 307, headers: { location: `${login.pathname}${login.search}` } });
83
+ // On the origin the request URL names, reading no request header. Next's proxy needs an absolute Location
84
+ // (a path-only one is a 500) and sends a same-host one to the browser path-only (#452).
85
+ return Response.redirect(new URL(`${login.pathname}${login.search}`, url.origin), 307);
83
86
  };
84
87
  }
85
88
 
89
+ /** Next's client-navigation cache key: meaningless to the page, so it never belongs in a return address. */
90
+ const NEXT_CACHE_KEY = "_rsc";
91
+
92
+ /**
93
+ * The path and query to come back to after sign-in, without Next's `_rsc`. The raw query segments are
94
+ * filtered rather than rebuilt, so every other parameter keeps the spelling the request gave it.
95
+ */
96
+ function getReturnPath(url: URL): string {
97
+ const segments = url.search.slice(1).split("&").filter((segment) => segment !== "" && !isNextCacheKey(segment));
98
+ return segments.length === 0 ? url.pathname : `${url.pathname}?${segments.join("&")}`;
99
+ }
100
+
101
+ function isNextCacheKey(segment: string): boolean {
102
+ const name = segment.split("=", 1)[0] ?? "";
103
+ try {
104
+ return decodeURIComponent(name) === NEXT_CACHE_KEY;
105
+ } catch {
106
+ return false;
107
+ }
108
+ }
109
+
86
110
  function normalizePrefix(prefix: string, kind: "protected" | "excluded"): string {
87
111
  if (!prefix.startsWith("/")) {
88
112
  throw new Error(`createAuthGuard: ${kind} path "${prefix}" must start with /`);
@@ -1,3 +0,0 @@
1
- import type { en } from "./en.js";
2
- export declare const pl: typeof en;
3
- //# sourceMappingURL=pl.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"pl.d.ts","sourceRoot":"","sources":["../../src/messages/pl.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAAE,EAAE,MAAM,SAAS,CAAC;AAElC,eAAO,MAAM,EAAE,EAAE,OAAO,EA0FvB,CAAC"}
@@ -1,92 +0,0 @@
1
- export const pl = {
2
- fields: {
3
- email: "E-mail",
4
- password: "Hasło",
5
- currentPassword: "Obecne hasło",
6
- newPassword: "Nowe hasło",
7
- newPasswordHint: "Co najmniej {minLength} znaków.",
8
- consent: "Akceptuję regulamin i politykę prywatności.",
9
- },
10
- login: {
11
- title: "Zaloguj się",
12
- lead: "Witaj ponownie.",
13
- submit: "Zaloguj się",
14
- pending: "Logowanie…",
15
- noAccount: "Nie masz jeszcze konta?",
16
- registerLink: "Załóż je",
17
- forgotPassword: "Nie pamiętasz hasła?",
18
- },
19
- register: {
20
- title: "Załóż konto",
21
- lead: "To zajmie chwilę.",
22
- submit: "Załóż konto",
23
- pending: "Zakładanie…",
24
- hasAccount: "Masz już konto?",
25
- loginLink: "Zaloguj się",
26
- closedTitle: "Rejestracja jest zamknięta",
27
- closedBody: "Nie można teraz założyć nowego konta. Spróbuj ponownie później.",
28
- },
29
- changePassword: {
30
- title: "Zmień hasło",
31
- lead: "Wszystkie inne urządzenia, na których jesteś zalogowany, zostaną wylogowane.",
32
- submit: "Zmień hasło",
33
- pending: "Zapisywanie…",
34
- success: "Hasło zostało zmienione.",
35
- },
36
- forgotPassword: {
37
- title: "Zresetuj hasło",
38
- lead: "Podaj e-mail swojego konta, a wyślemy Ci link do ustawienia nowego hasła.",
39
- submit: "Wyślij link",
40
- pending: "Wysyłanie…",
41
- sent: "Jeśli istnieje konto z tym adresem, wysłaliśmy na niego link do zmiany hasła. Link działa przez {ttlMinutes} minut.",
42
- backToLogin: "Wróć do logowania",
43
- },
44
- resetPassword: {
45
- title: "Ustaw nowe hasło",
46
- lead: "Zostaniesz wylogowany na wszystkich urządzeniach.",
47
- submit: "Ustaw hasło",
48
- pending: "Zapisywanie…",
49
- success: "Hasło zostało zmienione. Zaloguj się nowym hasłem.",
50
- invalidTitle: "Ten link nie działa",
51
- invalidBody: "Link wygasł albo został już użyty. Poproś o nowy.",
52
- requestNew: "Wyślij nowy link",
53
- },
54
- resetMail: {
55
- subject: "Zresetuj hasło",
56
- greeting: "Dzień dobry,",
57
- intro: "Otrzymaliśmy prośbę o zresetowanie hasła do Twojego konta. Otwórz ten link, aby ustawić nowe:",
58
- action: "Ustaw nowe hasło",
59
- expiry: "Link działa przez {duration} i tylko raz.",
60
- minutes: { one: "{count} minutę", few: "{count} minuty", many: "{count} minut", other: "{count} minuty" },
61
- ignore: "Jeśli to nie Ty, zignoruj tę wiadomość: Twoje hasło się nie zmieni.",
62
- },
63
- logout: {
64
- submit: "Wyloguj się",
65
- },
66
- errors: {
67
- auth: {
68
- invalid_credentials: "Nieprawidłowy e-mail lub hasło.",
69
- email_invalid: "Podaj prawidłowy adres e-mail.",
70
- email_taken: "Konto z tym adresem e-mail już istnieje.",
71
- password_too_short: "Hasło jest za krótkie.",
72
- password_too_long: "Hasło jest za długie.",
73
- consent_required: "Aby założyć konto, zaakceptuj regulamin.",
74
- registration_closed: "Rejestracja jest zamknięta.",
75
- current_password_invalid: "Obecne hasło jest nieprawidłowe.",
76
- password_unchanged: "Nowe hasło musi różnić się od obecnego.",
77
- unauthenticated: "Sesja wygasła. Zaloguj się ponownie.",
78
- forbidden: "Nie masz dostępu do tej funkcji.",
79
- reset_token_invalid: "Ten link wygasł albo został już użyty. Poproś o nowy.",
80
- password_reset_unavailable: "Reset hasła jest niedostępny.",
81
- },
82
- security: {
83
- rate_limited: "Zbyt wiele prób. Odczekaj kilka minut i spróbuj ponownie.",
84
- client_unidentified: "Nie udało się ustalić, skąd przyszło to żądanie. Spróbuj ponownie później.",
85
- },
86
- core: {
87
- database_failed: "Coś poszło nie tak po naszej stronie. Spróbuj ponownie za chwilę.",
88
- unexpected: "Coś poszło nie tak po naszej stronie. Spróbuj ponownie za chwilę.",
89
- },
90
- },
91
- };
92
- //# sourceMappingURL=pl.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"pl.js","sourceRoot":"","sources":["../../src/messages/pl.ts"],"names":[],"mappings":"AAEA,MAAM,CAAC,MAAM,EAAE,GAAc;IAC3B,MAAM,EAAE;QACN,KAAK,EAAE,QAAQ;QACf,QAAQ,EAAE,OAAO;QACjB,eAAe,EAAE,cAAc;QAC/B,WAAW,EAAE,YAAY;QACzB,eAAe,EAAE,iCAAiC;QAClD,OAAO,EAAE,6CAA6C;KACvD;IACD,KAAK,EAAE;QACL,KAAK,EAAE,aAAa;QACpB,IAAI,EAAE,iBAAiB;QACvB,MAAM,EAAE,aAAa;QACrB,OAAO,EAAE,YAAY;QACrB,SAAS,EAAE,yBAAyB;QACpC,YAAY,EAAE,UAAU;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YACtD,aAAa,EAAE,gCAAgC;YAC/C,WAAW,EAAE,0CAA0C;YACvD,kBAAkB,EAAE,wBAAwB;YAC5C,iBAAiB,EAAE,uBAAuB;YAC1C,gBAAgB,EAAE,0CAA0C;YAC5D,mBAAmB,EAAE,6BAA6B;YAClD,wBAAwB,EAAE,kCAAkC;YAC5D,kBAAkB,EAAE,yCAAyC;YAC7D,eAAe,EAAE,sCAAsC;YACvD,SAAS,EAAE,kCAAkC;YAC7C,mBAAmB,EAAE,uDAAuD;YAC5E,0BAA0B,EAAE,+BAA+B;SAC5D;QACD,QAAQ,EAAE;YACR,YAAY,EAAE,2DAA2D;YACzE,mBAAmB,EAAE,4EAA4E;SAClG;QACD,IAAI,EAAE;YACJ,eAAe,EAAE,mEAAmE;YACpF,UAAU,EAAE,mEAAmE;SAChF;KACF;CACF,CAAC"}
@@ -1,93 +0,0 @@
1
- import type { en } from "./en.js";
2
-
3
- export const pl: typeof en = {
4
- fields: {
5
- email: "E-mail",
6
- password: "Hasło",
7
- currentPassword: "Obecne hasło",
8
- newPassword: "Nowe hasło",
9
- newPasswordHint: "Co najmniej {minLength} znaków.",
10
- consent: "Akceptuję regulamin i politykę prywatności.",
11
- },
12
- login: {
13
- title: "Zaloguj się",
14
- lead: "Witaj ponownie.",
15
- submit: "Zaloguj się",
16
- pending: "Logowanie…",
17
- noAccount: "Nie masz jeszcze konta?",
18
- registerLink: "Załóż je",
19
- forgotPassword: "Nie pamiętasz hasła?",
20
- },
21
- register: {
22
- title: "Załóż konto",
23
- lead: "To zajmie chwilę.",
24
- submit: "Załóż konto",
25
- pending: "Zakładanie…",
26
- hasAccount: "Masz już konto?",
27
- loginLink: "Zaloguj się",
28
- closedTitle: "Rejestracja jest zamknięta",
29
- closedBody: "Nie można teraz założyć nowego konta. Spróbuj ponownie później.",
30
- },
31
- changePassword: {
32
- title: "Zmień hasło",
33
- lead: "Wszystkie inne urządzenia, na których jesteś zalogowany, zostaną wylogowane.",
34
- submit: "Zmień hasło",
35
- pending: "Zapisywanie…",
36
- success: "Hasło zostało zmienione.",
37
- },
38
- forgotPassword: {
39
- title: "Zresetuj hasło",
40
- lead: "Podaj e-mail swojego konta, a wyślemy Ci link do ustawienia nowego hasła.",
41
- submit: "Wyślij link",
42
- pending: "Wysyłanie…",
43
- sent: "Jeśli istnieje konto z tym adresem, wysłaliśmy na niego link do zmiany hasła. Link działa przez {ttlMinutes} minut.",
44
- backToLogin: "Wróć do logowania",
45
- },
46
- resetPassword: {
47
- title: "Ustaw nowe hasło",
48
- lead: "Zostaniesz wylogowany na wszystkich urządzeniach.",
49
- submit: "Ustaw hasło",
50
- pending: "Zapisywanie…",
51
- success: "Hasło zostało zmienione. Zaloguj się nowym hasłem.",
52
- invalidTitle: "Ten link nie działa",
53
- invalidBody: "Link wygasł albo został już użyty. Poproś o nowy.",
54
- requestNew: "Wyślij nowy link",
55
- },
56
- resetMail: {
57
- subject: "Zresetuj hasło",
58
- greeting: "Dzień dobry,",
59
- intro: "Otrzymaliśmy prośbę o zresetowanie hasła do Twojego konta. Otwórz ten link, aby ustawić nowe:",
60
- action: "Ustaw nowe hasło",
61
- expiry: "Link działa przez {duration} i tylko raz.",
62
- minutes: { one: "{count} minutę", few: "{count} minuty", many: "{count} minut", other: "{count} minuty" },
63
- ignore: "Jeśli to nie Ty, zignoruj tę wiadomość: Twoje hasło się nie zmieni.",
64
- },
65
- logout: {
66
- submit: "Wyloguj się",
67
- },
68
- errors: {
69
- auth: {
70
- invalid_credentials: "Nieprawidłowy e-mail lub hasło.",
71
- email_invalid: "Podaj prawidłowy adres e-mail.",
72
- email_taken: "Konto z tym adresem e-mail już istnieje.",
73
- password_too_short: "Hasło jest za krótkie.",
74
- password_too_long: "Hasło jest za długie.",
75
- consent_required: "Aby założyć konto, zaakceptuj regulamin.",
76
- registration_closed: "Rejestracja jest zamknięta.",
77
- current_password_invalid: "Obecne hasło jest nieprawidłowe.",
78
- password_unchanged: "Nowe hasło musi różnić się od obecnego.",
79
- unauthenticated: "Sesja wygasła. Zaloguj się ponownie.",
80
- forbidden: "Nie masz dostępu do tej funkcji.",
81
- reset_token_invalid: "Ten link wygasł albo został już użyty. Poproś o nowy.",
82
- password_reset_unavailable: "Reset hasła jest niedostępny.",
83
- },
84
- security: {
85
- rate_limited: "Zbyt wiele prób. Odczekaj kilka minut i spróbuj ponownie.",
86
- client_unidentified: "Nie udało się ustalić, skąd przyszło to żądanie. Spróbuj ponownie później.",
87
- },
88
- core: {
89
- database_failed: "Coś poszło nie tak po naszej stronie. Spróbuj ponownie za chwilę.",
90
- unexpected: "Coś poszło nie tak po naszej stronie. Spróbuj ponownie za chwilę.",
91
- },
92
- },
93
- };