@jskit-ai/auth-web 0.2.11 → 0.2.13

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.
@@ -12,15 +12,14 @@
12
12
  <v-card
13
13
  class="auth-card"
14
14
  :class="{ 'auth-card--mobile': isMobileViewport }"
15
- :rounded="isMobileViewport ? false : 'lg'"
15
+ :rounded="isMobileViewport ? false : undefined"
16
16
  :elevation="isMobileViewport ? 0 : 1"
17
- :border="!isMobileViewport"
18
17
  >
19
18
  <v-card-text class="auth-content" :class="{ 'auth-content--mobile': isMobileViewport }">
20
19
  <div v-if="authTitle || authSubtitle" class="auth-header mb-5">
21
20
  <div>
22
- <h1 v-if="authTitle" class="auth-title">{{ authTitle }}</h1>
23
- <p v-if="authSubtitle" class="text-medium-emphasis mb-0">{{ authSubtitle }}</p>
21
+ <h1 v-if="authTitle" class="auth-title text-headline-medium">{{ authTitle }}</h1>
22
+ <p v-if="authSubtitle" class="on-surface-variant mb-0">{{ authSubtitle }}</p>
24
23
  </div>
25
24
  </div>
26
25
 
@@ -29,7 +28,7 @@
29
28
  data-testid="auth-mode-sign-in"
30
29
  class="text-none"
31
30
  :variant="isLogin ? 'flat' : 'text'"
32
- :color="isLogin ? 'primary' : undefined"
31
+ :color="isLogin ? 'secondary-container' : undefined"
33
32
  @click="switchMode('login')"
34
33
  >
35
34
  {{ t("jskit.auth.login.mode.signIn") }}
@@ -39,7 +38,7 @@
39
38
  data-testid="auth-mode-register"
40
39
  class="text-none"
41
40
  :variant="isRegister ? 'flat' : 'text'"
42
- :color="isRegister ? 'primary' : undefined"
41
+ :color="isRegister ? 'secondary-container' : undefined"
43
42
  @click="switchMode('register')"
44
43
  >
45
44
  {{ t("jskit.auth.login.mode.register") }}
@@ -49,11 +48,50 @@
49
48
  <v-form @submit.prevent="submitAuth" novalidate>
50
49
  <template v-if="isEmailConfirmationPending">
51
50
  <div class="email-confirmation-state mb-5">
52
- <p class="email-confirmation-message mb-0">
51
+ <p class="email-confirmation-message text-body-medium mb-0">
53
52
  {{ emailConfirmationMessage }}
54
53
  </p>
55
54
  </div>
56
55
 
56
+ <div v-if="confirmationUrl" class="email-confirmation-dev-link mb-5" data-testid="auth-confirmation-dev-link">
57
+ <p class="text-body-medium on-surface-variant mb-2">{{ t("jskit.auth.login.confirmEmail.devLink") }}</p>
58
+ <p class="email-confirmation-url text-body-small mb-3">{{ confirmationUrl }}</p>
59
+ <v-btn
60
+ class="text-none"
61
+ variant="flat"
62
+ color="primary"
63
+ data-testid="auth-confirmation-dev-confirm"
64
+ :loading="registrationConfirmPending"
65
+ @click="confirmRegistrationFromLink"
66
+ >
67
+ {{ t("jskit.auth.login.confirmEmail.useDevLink") }}
68
+ </v-btn>
69
+ </div>
70
+
71
+ <div v-if="canEnterConfirmationCode" class="email-confirmation-code d-flex align-start ga-2 mb-5">
72
+ <v-text-field
73
+ v-model="confirmationCode"
74
+ data-testid="auth-confirmation-code"
75
+ :label="t('jskit.auth.login.field.confirmationCode')"
76
+ variant="outlined"
77
+ density="comfortable"
78
+ autocomplete="off"
79
+ hide-details="auto"
80
+ />
81
+ <v-btn
82
+ class="text-none mt-1"
83
+ variant="tonal"
84
+ color="primary"
85
+ size="large"
86
+ type="submit"
87
+ data-testid="auth-confirmation-submit"
88
+ :disabled="!confirmationCode.trim()"
89
+ :loading="registrationConfirmPending"
90
+ >
91
+ {{ t("jskit.auth.login.confirmEmail.confirm") }}
92
+ </v-btn>
93
+ </div>
94
+
57
95
  <div class="switch-row d-flex align-center justify-space-between ga-3">
58
96
  <v-btn class="text-none" variant="tonal" color="primary" @click="goToMainScreen">
59
97
  {{ t("jskit.auth.login.confirmEmail.goToMainScreen") }}
@@ -80,16 +118,33 @@
80
118
  class="remembered-account d-flex align-center justify-space-between ga-3 mb-4"
81
119
  >
82
120
  <div class="remembered-copy flex-grow-1">
83
- <p class="remembered-title">
121
+ <p class="remembered-title text-title-small">
84
122
  {{ t("jskit.auth.login.rememberedAccount.welcomeBack", { name: rememberedAccountDisplayName }) }}
85
123
  </p>
86
- <p class="remembered-email">{{ rememberedAccountMaskedEmail }}</p>
124
+ <p class="remembered-email text-body-small">{{ rememberedAccountMaskedEmail }}</p>
87
125
  </div>
88
126
  <v-btn variant="text" color="secondary" class="text-none" @click="switchAccount">
89
127
  {{ rememberedAccountSwitchLabel }}
90
128
  </v-btn>
91
129
  </div>
92
130
 
131
+ <div
132
+ v-if="isRegister && needsFirstAccountSetupCode"
133
+ class="first-account-setup mb-4"
134
+ data-testid="auth-first-account-setup"
135
+ >
136
+ <p class="text-body-medium mb-3">{{ t("jskit.auth.login.firstAccount.explain") }}</p>
137
+ <v-text-field
138
+ v-model="setupCode"
139
+ :label="t('jskit.auth.login.field.setupCode')"
140
+ variant="outlined"
141
+ density="comfortable"
142
+ autocomplete="off"
143
+ spellcheck="false"
144
+ hide-details="auto"
145
+ />
146
+ </div>
147
+
93
148
  <v-text-field
94
149
  v-if="!isLogin || canUsePasswordLogin"
95
150
  v-model="email"
@@ -112,7 +167,7 @@
112
167
  density="comfortable"
113
168
  :autocomplete="isRegister ? 'new-password' : 'current-password'"
114
169
  :error-messages="passwordErrorMessages"
115
- :append-inner-icon="showPassword ? mdiEyeOff : mdiEye"
170
+ :append-inner-icon="showPassword ? '$visibilityOff' : '$visibility'"
116
171
  @click:append-inner="togglePasswordVisibility"
117
172
  @blur="passwordTouched = true"
118
173
  class="mb-3"
@@ -127,7 +182,7 @@
127
182
  density="comfortable"
128
183
  autocomplete="new-password"
129
184
  :error-messages="confirmPasswordErrorMessages"
130
- :append-inner-icon="showConfirmPassword ? mdiEyeOff : mdiEye"
185
+ :append-inner-icon="showConfirmPassword ? '$visibilityOff' : '$visibility'"
131
186
  @click:append-inner="toggleConfirmPasswordVisibility"
132
187
  @blur="confirmPasswordTouched = true"
133
188
  class="mb-3"
@@ -209,21 +264,21 @@
209
264
  </v-btn>
210
265
 
211
266
  <div v-if="isRegister" class="switch-row mt-4 d-flex align-center justify-space-between ga-3">
212
- <span class="text-medium-emphasis">{{ t("jskit.auth.login.hasAccount") }}</span>
267
+ <span class="on-surface-variant">{{ t("jskit.auth.login.hasAccount") }}</span>
213
268
  <v-btn variant="text" color="secondary" @click="switchMode('login')">
214
269
  {{ t("jskit.auth.login.backToSignIn") }}
215
270
  </v-btn>
216
271
  </div>
217
272
 
218
273
  <div v-else-if="isForgot" class="switch-row mt-4 d-flex align-center justify-space-between ga-3">
219
- <span class="text-medium-emphasis">{{ t("jskit.auth.login.rememberedPassword") }}</span>
274
+ <span class="on-surface-variant">{{ t("jskit.auth.login.rememberedPassword") }}</span>
220
275
  <v-btn variant="text" color="secondary" @click="switchMode('login')">
221
276
  {{ t("jskit.auth.login.backToSignIn") }}
222
277
  </v-btn>
223
278
  </div>
224
279
 
225
280
  <div v-else-if="isOtp" class="switch-row mt-4 d-flex align-center justify-space-between ga-3">
226
- <span class="text-medium-emphasis">{{ t("jskit.auth.login.otherMethod") }}</span>
281
+ <span class="on-surface-variant">{{ t("jskit.auth.login.otherMethod") }}</span>
227
282
  <v-btn variant="text" color="secondary" @click="switchMode('login')">
228
283
  {{ t("jskit.auth.login.backToSignIn") }}
229
284
  </v-btn>
@@ -237,7 +292,6 @@
237
292
  </template>
238
293
 
239
294
  <script setup>
240
- import { mdiEye, mdiEyeOff } from "@mdi/js";
241
295
  import { useDisplay } from "vuetify";
242
296
  import { useLoginView } from "../runtime/useLoginView.js";
243
297
  import { useJskitText } from "../i18n.js";
@@ -259,6 +313,13 @@ const {
259
313
  canUseOtp,
260
314
  canUseOAuth,
261
315
  canResendEmailConfirmation,
316
+ canEnterConfirmationCode,
317
+ needsFirstAccountSetupCode,
318
+ setupCode,
319
+ confirmationUrl,
320
+ confirmationCode,
321
+ registrationConfirmPending,
322
+ confirmRegistrationFromLink,
262
323
  emailConfirmationMessage,
263
324
  showRememberedAccount,
264
325
  switchMode,
@@ -314,12 +375,11 @@ function toggleConfirmPasswordVisibility() {
314
375
  z-index: 1;
315
376
  overflow-y: auto;
316
377
  min-height: var(--auth-screen-height);
317
- background-color: rgb(var(--v-theme-background));
318
- background-image: radial-gradient(circle at 15% 12%, rgba(var(--v-theme-primary), 0.14), transparent 32%);
378
+ background-color: rgb(var(--v-theme-surface-container));
319
379
  }
320
380
 
321
381
  .login-screen--mobile {
322
- background-image: none;
382
+ background-color: rgb(var(--v-theme-surface));
323
383
  }
324
384
 
325
385
  .login-shell {
@@ -350,33 +410,45 @@ function toggleConfirmPasswordVisibility() {
350
410
 
351
411
  .auth-title {
352
412
  margin: 0 0 8px;
353
- font-size: clamp(28px, 3vw, 32px);
354
- line-height: 1.2;
355
413
  color: rgb(var(--v-theme-on-surface));
356
414
  }
357
415
 
358
416
  .mode-switch {
417
+ border-radius: 9999px;
418
+ background-color: rgb(var(--v-theme-surface-container-highest));
419
+ }
420
+
421
+ .email-confirmation-state,
422
+ .remembered-account {
359
423
  border-radius: 12px;
360
- background-color: rgba(var(--v-theme-on-surface), 0.06);
424
+ background: rgb(var(--v-theme-secondary-container));
425
+ color: rgb(var(--v-theme-on-secondary-container));
361
426
  }
362
427
 
363
428
  .email-confirmation-state {
429
+ padding: 16px;
430
+ }
431
+
432
+ .first-account-setup {
364
433
  border-radius: 12px;
365
- border: 1px solid rgba(var(--v-theme-primary), 0.34);
366
- background: rgba(var(--v-theme-primary), 0.12);
434
+ background: rgb(var(--v-theme-warning-container));
435
+ color: rgb(var(--v-theme-on-warning-container));
367
436
  padding: 16px;
368
437
  }
369
438
 
370
- .email-confirmation-message {
371
- color: rgb(var(--v-theme-on-surface));
372
- line-height: 1.5;
439
+ .email-confirmation-dev-link {
440
+ border-radius: 12px;
441
+ background: rgb(var(--v-theme-surface-container-highest));
442
+ padding: 16px;
443
+ }
444
+
445
+ .email-confirmation-url {
446
+ font-family: monospace;
447
+ overflow-wrap: anywhere;
373
448
  }
374
449
 
375
450
  .remembered-account {
376
- border-radius: 12px;
377
- border: 1px solid rgba(var(--v-theme-primary), 0.34);
378
- background: rgba(var(--v-theme-primary), 0.12);
379
- padding: 12px 14px;
451
+ padding: 12px 16px;
380
452
  }
381
453
 
382
454
  .remembered-copy {
@@ -385,24 +457,13 @@ function toggleConfirmPasswordVisibility() {
385
457
 
386
458
  .remembered-title {
387
459
  margin: 0;
388
- font-size: 14px;
389
- font-weight: 600;
390
- color: rgb(var(--v-theme-on-surface));
391
460
  }
392
461
 
393
462
  .remembered-email {
394
463
  margin: 2px 0 0;
395
- font-size: 12px;
396
- color: rgba(var(--v-theme-on-surface), 0.72);
397
464
  }
398
465
 
399
466
  .oauth-provider-button {
400
467
  justify-content: center;
401
468
  }
402
-
403
- @media (max-width: 959px) {
404
- .auth-title {
405
- font-size: 26px;
406
- }
407
- }
408
469
  </style>
@@ -39,7 +39,7 @@
39
39
  variant="outlined"
40
40
  density="comfortable"
41
41
  autocomplete="new-password"
42
- :append-inner-icon="showPassword ? mdiEyeOff : mdiEye"
42
+ :append-inner-icon="showPassword ? '$visibilityOff' : '$visibility'"
43
43
  :error-messages="passwordError"
44
44
  class="mb-3"
45
45
  @click:append-inner="showPassword = !showPassword"
@@ -51,7 +51,7 @@
51
51
  variant="outlined"
52
52
  density="comfortable"
53
53
  autocomplete="new-password"
54
- :append-inner-icon="showConfirmPassword ? mdiEyeOff : mdiEye"
54
+ :append-inner-icon="showConfirmPassword ? '$visibilityOff' : '$visibility'"
55
55
  :error-messages="confirmPasswordError"
56
56
  class="mb-4"
57
57
  @click:append-inner="showConfirmPassword = !showConfirmPassword"
@@ -73,7 +73,6 @@
73
73
  </template>
74
74
 
75
75
  <script setup>
76
- import { mdiEye, mdiEyeOff } from "@mdi/js";
77
76
  import { useDisplay } from "vuetify";
78
77
  import { useDefaultResetPasswordView } from "../composables/useDefaultResetPasswordView.js";
79
78
  import { useJskitText } from "../i18n.js";
@@ -1,15 +1,15 @@
1
1
  <template>
2
2
  <v-main class="signout-main">
3
3
  <v-container class="fill-height d-flex align-center justify-center py-8">
4
- <v-card class="signout-card" rounded="lg" elevation="1" border>
4
+ <v-card class="signout-card">
5
5
  <v-card-text class="pa-7">
6
- <h1 class="text-h5 mb-3">{{ t("jskit.auth.signOut.title") }}</h1>
6
+ <h1 class="text-headline-small mb-3">{{ t("jskit.auth.signOut.title") }}</h1>
7
7
 
8
- <p v-if="status === 'pending'" class="text-medium-emphasis mb-4">
8
+ <p v-if="status === 'pending'" class="on-surface-variant mb-4">
9
9
  {{ t("jskit.auth.signOut.pending") }}
10
10
  </p>
11
11
 
12
- <p v-if="status === 'error'" class="text-body-1 text-medium-emphasis mb-4">
12
+ <p v-if="status === 'error'" class="text-body-large on-surface-variant mb-4">
13
13
  {{ errorMessage || t("jskit.auth.signOut.failedTryAgain") }}
14
14
  </p>
15
15
 
@@ -50,8 +50,7 @@ const { status, errorMessage, retrySignOut, goToLogin } = useDefaultSignOutView(
50
50
 
51
51
  <style scoped>
52
52
  .signout-main {
53
- background-color: rgb(var(--v-theme-background));
54
- background-image: radial-gradient(circle at 15% 12%, rgba(var(--v-theme-primary), 0.14), transparent 32%);
53
+ background-color: rgb(var(--v-theme-surface-container));
55
54
  }
56
55
 
57
56
  .signout-card {
@@ -6,6 +6,7 @@ const AuthWebFeature = defineFeature({
6
6
  domain: "auth",
7
7
  requires: {
8
8
  authService: "auth.service",
9
+ config: "runtime.config",
9
10
  env: "runtime.env",
10
11
  http: "runtime.http"
11
12
  },
@@ -15,11 +16,12 @@ const AuthWebFeature = defineFeature({
15
16
  /**
16
17
  * @param {object} capabilities
17
18
  * @param {import("@jskit-ai/auth-core/server/types").AuthService} capabilities.authService
19
+ * @param {import("@jskit-ai/kernel/server/types").RuntimeConfig} capabilities.config
18
20
  * @param {import("@jskit-ai/kernel/server/types").RuntimeEnv} capabilities.env
19
21
  * @param {import("@jskit-ai/kernel/server/types").RuntimeHttp} capabilities.http
20
22
  */
21
- setup({ authService, env, http }) {
22
- const authWeb = createAuthWeb({ authService, env });
23
+ setup({ authService, config, env, http }) {
24
+ const authWeb = createAuthWeb({ authService, env, config });
23
25
  for (const route of authWeb.routes) {
24
26
  http.router.register(route.method, route.path, route, route.handler);
25
27
  }
@@ -0,0 +1,59 @@
1
+ import { isRecord } from "@jskit-ai/kernel/shared/support/normalize";
2
+
3
+ /**
4
+ * The auth routes' default rate limits, per client address. Sign-in also limits
5
+ * failed attempts per account, in the provider; these limits bound how fast one
6
+ * address can try anything at all.
7
+ */
8
+ const DEFAULT_AUTH_RATE_LIMITS = Object.freeze({
9
+ register: Object.freeze({ max: 10, timeWindow: "1 minute" }),
10
+ registerConfirmationResend: Object.freeze({ max: 5, timeWindow: "1 minute" }),
11
+ registerConfirm: Object.freeze({ max: 10, timeWindow: "1 minute" }),
12
+ login: Object.freeze({ max: 10, timeWindow: "1 minute" }),
13
+ loginOtpRequest: Object.freeze({ max: 10, timeWindow: "1 minute" }),
14
+ loginOtpVerify: Object.freeze({ max: 10, timeWindow: "1 minute" }),
15
+ oauthStart: Object.freeze({ max: 20, timeWindow: "1 minute" }),
16
+ oauthComplete: Object.freeze({ max: 20, timeWindow: "1 minute" }),
17
+ devLoginAs: Object.freeze({ max: 30, timeWindow: "1 minute" }),
18
+ passwordForgot: Object.freeze({ max: 5, timeWindow: "1 minute" }),
19
+ passwordRecovery: Object.freeze({ max: 20, timeWindow: "1 minute" }),
20
+ passwordReset: Object.freeze({ max: 20, timeWindow: "1 minute" })
21
+ });
22
+
23
+ /**
24
+ * Each auth route's rate limit: its default, with the fields the application's
25
+ * `config.auth.rateLimits.<route>` gives over it, or none when that is false.
26
+ * A route name the defaults do not have stops startup, so a misspelt override
27
+ * is never silently ignored.
28
+ * @param {import("@jskit-ai/kernel/server/types").RuntimeConfig} config
29
+ * @returns {Readonly<Record<keyof typeof DEFAULT_AUTH_RATE_LIMITS, { max: number, timeWindow: string | number } | null>>}
30
+ */
31
+ function resolveAuthRateLimits(config) {
32
+ const configured = isRecord(config.auth) && config.auth.rateLimits !== undefined ? config.auth.rateLimits : {};
33
+ if (!isRecord(configured)) {
34
+ throw new Error("config.auth.rateLimits must be an object of route names.");
35
+ }
36
+ for (const name of Object.keys(configured)) {
37
+ if (!Object.hasOwn(DEFAULT_AUTH_RATE_LIMITS, name)) {
38
+ throw new Error(
39
+ `config.auth.rateLimits.${name} names no auth route. Use one of: ${Object.keys(DEFAULT_AUTH_RATE_LIMITS).join(", ")}.`
40
+ );
41
+ }
42
+ }
43
+ const limits = {};
44
+ for (const [name, defaultLimit] of Object.entries(DEFAULT_AUTH_RATE_LIMITS)) {
45
+ const override = configured[name];
46
+ if (override === false) {
47
+ limits[name] = null;
48
+ } else if (override === undefined) {
49
+ limits[name] = defaultLimit;
50
+ } else if (isRecord(override)) {
51
+ limits[name] = Object.freeze({ ...defaultLimit, ...override });
52
+ } else {
53
+ throw new Error(`config.auth.rateLimits.${name} must be { max, timeWindow } or false.`);
54
+ }
55
+ }
56
+ return Object.freeze(limits);
57
+ }
58
+
59
+ export { DEFAULT_AUTH_RATE_LIMITS, resolveAuthRateLimits };
@@ -1,4 +1,5 @@
1
1
  import { isDevAuthBootstrapEnabled, resolveDevAuthPolicyFromEnv } from "@jskit-ai/auth-core/server/devAuth";
2
+ import { resolveAuthRateLimits } from "./authRateLimits.js";
2
3
  import { AuthController } from "./controllers/AuthController.js";
3
4
  import { buildRoutes } from "./routes/authRoutes.js";
4
5
  import { AuthWebService } from "./services/AuthWebService.js";
@@ -11,15 +12,17 @@ import { AuthWebService } from "./services/AuthWebService.js";
11
12
  * @param {object} dependencies
12
13
  * @param {import("@jskit-ai/auth-core/server/types").AuthService} dependencies.authService
13
14
  * @param {import("@jskit-ai/kernel/server/types").RuntimeEnv} dependencies.env
15
+ * @param {import("@jskit-ai/kernel/server/types").RuntimeConfig} dependencies.config
14
16
  */
15
- function createAuthWeb({ authService, env }) {
17
+ function createAuthWeb({ authService, env, config }) {
16
18
  const service = new AuthWebService({
17
19
  authService,
18
20
  devAuthBootstrapEnabled: isDevAuthBootstrapEnabled(resolveDevAuthPolicyFromEnv(env))
19
21
  });
20
22
  const controller = new AuthController({ service });
21
23
  const routes = buildRoutes(controller, {
22
- includeDevLoginAs: service.isDevLoginAsAvailable()
24
+ includeDevLoginAs: service.isDevLoginAsAvailable(),
25
+ rateLimits: resolveAuthRateLimits(config)
23
26
  });
24
27
  return Object.freeze({
25
28
  controller,
@@ -1,6 +1,7 @@
1
1
  const AUTH_ACTION_IDS = Object.freeze({
2
2
  REGISTER: "auth.register",
3
3
  REGISTER_CONFIRMATION_RESEND: "auth.register.confirmation.resend",
4
+ REGISTER_CONFIRM: "auth.register.confirm",
4
5
  LOGIN_PASSWORD: "auth.login.password",
5
6
  LOGIN_OTP_REQUEST: "auth.login.otp.request",
6
7
  LOGIN_OTP_VERIFY: "auth.login.otp.verify",
@@ -26,7 +26,9 @@ class AuthController {
26
26
  requiresEmailConfirmation: true,
27
27
  message: "Check your email to confirm the account before logging in.",
28
28
  messageCode: "auth.register.confirmEmail",
29
- messageParams: {}
29
+ messageParams: {},
30
+ // In development without an email sender, the link to open instead.
31
+ ...(result.confirmationUrl ? { confirmationUrl: result.confirmationUrl } : {})
30
32
  });
31
33
  return;
32
34
  }
@@ -44,6 +46,21 @@ class AuthController {
44
46
  reply.code(200).send(result);
45
47
  }
46
48
 
49
+ /** Creates the account a registration waited to create, and signs the person in. */
50
+ async confirmRegistration(request, reply) {
51
+ const payload = request.body || {};
52
+ const result = await this.service.confirmRegistration(request, payload);
53
+ this.service.writeSessionCookies(reply, result.session);
54
+ reply.code(200).send({
55
+ ok: true,
56
+ email: result.actor.email,
57
+ username: result.actor.displayName,
58
+ message: "Your email is confirmed.",
59
+ messageCode: "auth.register.confirmed",
60
+ messageParams: {}
61
+ });
62
+ }
63
+
47
64
  async login(request, reply) {
48
65
  const payload = request.body || {};
49
66
  const result = await this.service.login(request, payload);
@@ -2,6 +2,7 @@ import { withStandardErrorResponses } from "@jskit-ai/http-runtime/shared/valida
2
2
  import {
3
3
  authRegisterCommand,
4
4
  authRegisterConfirmationResendCommand,
5
+ authRegisterConfirmCommand,
5
6
  authLoginPasswordCommand,
6
7
  authLoginOtpRequestCommand,
7
8
  authLoginOtpVerifyCommand,
@@ -15,12 +16,18 @@ import {
15
16
  authSessionReadCommand
16
17
  } from "@jskit-ai/auth-core/shared/commands";
17
18
  import { AUTH_PATHS } from "@jskit-ai/auth-core/shared/authPaths";
19
+ import { DEFAULT_AUTH_RATE_LIMITS } from "../authRateLimits.js";
18
20
 
19
21
  /**
22
+ * The auth routes, each limited per client address by its entry in
23
+ * `rateLimits` (none when that entry is null).
20
24
  * @param {import("../controllers/AuthController.js").AuthController} controller
21
- * @param {{ includeDevLoginAs?: boolean }} [options]
25
+ * @param {{
26
+ * includeDevLoginAs?: boolean,
27
+ * rateLimits?: ReturnType<typeof import("../authRateLimits.js").resolveAuthRateLimits>
28
+ * }} [options]
22
29
  */
23
- function buildRoutes(controller, { includeDevLoginAs = false } = {}) {
30
+ function buildRoutes(controller, { includeDevLoginAs = false, rateLimits = DEFAULT_AUTH_RATE_LIMITS } = {}) {
24
31
  return [
25
32
  {
26
33
  path: AUTH_PATHS.REGISTER,
@@ -37,10 +44,7 @@ function buildRoutes(controller, { includeDevLoginAs = false } = {}) {
37
44
  },
38
45
  { includeValidation400: true }
39
46
  ),
40
- rateLimit: {
41
- max: 10,
42
- timeWindow: "1 minute"
43
- },
47
+ rateLimit: rateLimits.register,
44
48
  handler: (request, reply) => controller.register(request, reply)
45
49
  },
46
50
  {
@@ -58,12 +62,27 @@ function buildRoutes(controller, { includeDevLoginAs = false } = {}) {
58
62
  },
59
63
  { includeValidation400: true }
60
64
  ),
61
- rateLimit: {
62
- max: 5,
63
- timeWindow: "1 minute"
64
- },
65
+ rateLimit: rateLimits.registerConfirmationResend,
65
66
  handler: (request, reply) => controller.resendRegisterConfirmation(request, reply)
66
67
  },
68
+ {
69
+ path: AUTH_PATHS.REGISTER_CONFIRM,
70
+ method: "POST",
71
+ auth: "public",
72
+ meta: {
73
+ tags: ["auth"],
74
+ summary: "Confirm a registration's email with the code from its link"
75
+ },
76
+ body: authRegisterConfirmCommand.operation.body,
77
+ responses: withStandardErrorResponses(
78
+ {
79
+ 200: authRegisterConfirmCommand.operation.response
80
+ },
81
+ { includeValidation400: true }
82
+ ),
83
+ rateLimit: rateLimits.registerConfirm,
84
+ handler: (request, reply) => controller.confirmRegistration(request, reply)
85
+ },
67
86
  {
68
87
  path: AUTH_PATHS.LOGIN,
69
88
  method: "POST",
@@ -79,10 +98,7 @@ function buildRoutes(controller, { includeDevLoginAs = false } = {}) {
79
98
  },
80
99
  { includeValidation400: true }
81
100
  ),
82
- rateLimit: {
83
- max: 10,
84
- timeWindow: "1 minute"
85
- },
101
+ rateLimit: rateLimits.login,
86
102
  handler: (request, reply) => controller.login(request, reply)
87
103
  },
88
104
  {
@@ -100,10 +116,7 @@ function buildRoutes(controller, { includeDevLoginAs = false } = {}) {
100
116
  },
101
117
  { includeValidation400: true }
102
118
  ),
103
- rateLimit: {
104
- max: 10,
105
- timeWindow: "1 minute"
106
- },
119
+ rateLimit: rateLimits.loginOtpRequest,
107
120
  handler: (request, reply) => controller.requestOtpLogin(request, reply)
108
121
  },
109
122
  {
@@ -121,10 +134,7 @@ function buildRoutes(controller, { includeDevLoginAs = false } = {}) {
121
134
  },
122
135
  { includeValidation400: true }
123
136
  ),
124
- rateLimit: {
125
- max: 10,
126
- timeWindow: "1 minute"
127
- },
137
+ rateLimit: rateLimits.loginOtpVerify,
128
138
  handler: (request, reply) => controller.verifyOtpLogin(request, reply)
129
139
  },
130
140
  {
@@ -144,10 +154,7 @@ function buildRoutes(controller, { includeDevLoginAs = false } = {}) {
144
154
  },
145
155
  { includeValidation400: true }
146
156
  ),
147
- rateLimit: {
148
- max: 20,
149
- timeWindow: "1 minute"
150
- },
157
+ rateLimit: rateLimits.oauthStart,
151
158
  handler: (request, reply) => controller.oauthStart(request, reply)
152
159
  },
153
160
  {
@@ -165,10 +172,7 @@ function buildRoutes(controller, { includeDevLoginAs = false } = {}) {
165
172
  },
166
173
  { includeValidation400: true }
167
174
  ),
168
- rateLimit: {
169
- max: 20,
170
- timeWindow: "1 minute"
171
- },
175
+ rateLimit: rateLimits.oauthComplete,
172
176
  handler: (request, reply) => controller.oauthComplete(request, reply)
173
177
  },
174
178
  ...(includeDevLoginAs ? [{
@@ -186,10 +190,7 @@ function buildRoutes(controller, { includeDevLoginAs = false } = {}) {
186
190
  },
187
191
  { includeValidation400: true }
188
192
  ),
189
- rateLimit: {
190
- max: 30,
191
- timeWindow: "1 minute"
192
- },
193
+ rateLimit: rateLimits.devLoginAs,
193
194
  handler: (request, reply) => controller.devLoginAs(request, reply)
194
195
  }] : []),
195
196
  {
@@ -207,10 +208,7 @@ function buildRoutes(controller, { includeDevLoginAs = false } = {}) {
207
208
  },
208
209
  { includeValidation400: true }
209
210
  ),
210
- rateLimit: {
211
- max: 5,
212
- timeWindow: "1 minute"
213
- },
211
+ rateLimit: rateLimits.passwordForgot,
214
212
  handler: (request, reply) => controller.requestPasswordReset(request, reply)
215
213
  },
216
214
  {
@@ -228,10 +226,7 @@ function buildRoutes(controller, { includeDevLoginAs = false } = {}) {
228
226
  },
229
227
  { includeValidation400: true }
230
228
  ),
231
- rateLimit: {
232
- max: 20,
233
- timeWindow: "1 minute"
234
- },
229
+ rateLimit: rateLimits.passwordRecovery,
235
230
  handler: (request, reply) => controller.completePasswordRecovery(request, reply)
236
231
  },
237
232
  {
@@ -249,10 +244,7 @@ function buildRoutes(controller, { includeDevLoginAs = false } = {}) {
249
244
  },
250
245
  { includeValidation400: true }
251
246
  ),
252
- rateLimit: {
253
- max: 20,
254
- timeWindow: "1 minute"
255
- },
247
+ rateLimit: rateLimits.passwordReset,
256
248
  handler: (request, reply) => controller.resetPassword(request, reply)
257
249
  },
258
250
  {