@techelusive/nest-auth 0.0.0-stage → 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 +64 -0
- package/LICENSE +21 -0
- package/README.md +204 -2
- package/api/openapi.json +4399 -0
- package/api/techelusive-authentication.postman_collection.json +3178 -0
- package/dist/auth-options.d.ts +156 -0
- package/dist/auth-options.js +3 -0
- package/dist/auth-options.js.map +1 -0
- package/dist/auth-options.validation.d.ts +9 -0
- package/dist/auth-options.validation.js +74 -0
- package/dist/auth-options.validation.js.map +1 -0
- package/dist/auth.module.d.ts +38 -0
- package/dist/auth.module.js +173 -0
- package/dist/auth.module.js.map +1 -0
- package/dist/common/auth-error.d.ts +16 -0
- package/dist/common/auth-error.js +23 -0
- package/dist/common/auth-error.js.map +1 -0
- package/dist/common/auth-exception.filter.d.ts +24 -0
- package/dist/common/auth-exception.filter.js +66 -0
- package/dist/common/auth-exception.filter.js.map +1 -0
- package/dist/common/crypto/jwt.d.ts +89 -0
- package/dist/common/crypto/jwt.js +144 -0
- package/dist/common/crypto/jwt.js.map +1 -0
- package/dist/common/crypto/random-secrets.d.ts +78 -0
- package/dist/common/crypto/random-secrets.js +113 -0
- package/dist/common/crypto/random-secrets.js.map +1 -0
- package/dist/common/crypto/remote-public-keys.d.ts +49 -0
- package/dist/common/crypto/remote-public-keys.js +105 -0
- package/dist/common/crypto/remote-public-keys.js.map +1 -0
- package/dist/common/crypto/totp.d.ts +68 -0
- package/dist/common/crypto/totp.js +148 -0
- package/dist/common/crypto/totp.js.map +1 -0
- package/dist/common/encryption.service.d.ts +36 -0
- package/dist/common/encryption.service.js +111 -0
- package/dist/common/encryption.service.js.map +1 -0
- package/dist/common/identifiers.d.ts +48 -0
- package/dist/common/identifiers.js +89 -0
- package/dist/common/identifiers.js.map +1 -0
- package/dist/common/network-safety.d.ts +19 -0
- package/dist/common/network-safety.js +72 -0
- package/dist/common/network-safety.js.map +1 -0
- package/dist/common/rate-limiter.service.d.ts +63 -0
- package/dist/common/rate-limiter.service.js +158 -0
- package/dist/common/rate-limiter.service.js.map +1 -0
- package/dist/common/refresh-token-cookie.d.ts +78 -0
- package/dist/common/refresh-token-cookie.js +185 -0
- package/dist/common/refresh-token-cookie.js.map +1 -0
- package/dist/common/request-context.d.ts +14 -0
- package/dist/common/request-context.js +22 -0
- package/dist/common/request-context.js.map +1 -0
- package/dist/common/strict-validation.pipe.d.ts +8 -0
- package/dist/common/strict-validation.pipe.js +16 -0
- package/dist/common/strict-validation.pipe.js.map +1 -0
- package/dist/common/time.d.ts +15 -0
- package/dist/common/time.js +34 -0
- package/dist/common/time.js.map +1 -0
- package/dist/constants.d.ts +1326 -0
- package/dist/constants.js +1142 -0
- package/dist/constants.js.map +1 -0
- package/dist/database/create-auth-tables.migration.d.ts +26 -0
- package/dist/database/create-auth-tables.migration.js +291 -0
- package/dist/database/create-auth-tables.migration.js.map +1 -0
- package/dist/database/email-change-and-retention.migration.d.ts +25 -0
- package/dist/database/email-change-and-retention.migration.js +54 -0
- package/dist/database/email-change-and-retention.migration.js.map +1 -0
- package/dist/database/entities/api-key.entity.d.ts +17 -0
- package/dist/database/entities/api-key.entity.js +80 -0
- package/dist/database/entities/api-key.entity.js.map +1 -0
- package/dist/database/entities/audit-log.entity.d.ts +13 -0
- package/dist/database/entities/audit-log.entity.js +64 -0
- package/dist/database/entities/audit-log.entity.js.map +1 -0
- package/dist/database/entities/backup-code.entity.d.ts +9 -0
- package/dist/database/entities/backup-code.entity.js +52 -0
- package/dist/database/entities/backup-code.entity.js.map +1 -0
- package/dist/database/entities/index.d.ts +43 -0
- package/dist/database/entities/index.js +82 -0
- package/dist/database/entities/index.js.map +1 -0
- package/dist/database/entities/json-object.d.ts +12 -0
- package/dist/database/entities/json-object.js +3 -0
- package/dist/database/entities/json-object.js.map +1 -0
- package/dist/database/entities/link-token.entity.d.ts +15 -0
- package/dist/database/entities/link-token.entity.js +64 -0
- package/dist/database/entities/link-token.entity.js.map +1 -0
- package/dist/database/entities/one-time-code.entity.d.ts +16 -0
- package/dist/database/entities/one-time-code.entity.js +69 -0
- package/dist/database/entities/one-time-code.entity.js.map +1 -0
- package/dist/database/entities/organization-invitation.entity.d.ts +14 -0
- package/dist/database/entities/organization-invitation.entity.js +73 -0
- package/dist/database/entities/organization-invitation.entity.js.map +1 -0
- package/dist/database/entities/organization-member.entity.d.ts +9 -0
- package/dist/database/entities/organization-member.entity.js +48 -0
- package/dist/database/entities/organization-member.entity.js.map +1 -0
- package/dist/database/entities/organization.entity.d.ts +12 -0
- package/dist/database/entities/organization.entity.js +58 -0
- package/dist/database/entities/organization.entity.js.map +1 -0
- package/dist/database/entities/passkey.entity.d.ts +19 -0
- package/dist/database/entities/passkey.entity.js +78 -0
- package/dist/database/entities/passkey.entity.js.map +1 -0
- package/dist/database/entities/password.entity.d.ts +6 -0
- package/dist/database/entities/password.entity.js +36 -0
- package/dist/database/entities/password.entity.js.map +1 -0
- package/dist/database/entities/refresh-token.entity.d.ts +9 -0
- package/dist/database/entities/refresh-token.entity.js +53 -0
- package/dist/database/entities/refresh-token.entity.js.map +1 -0
- package/dist/database/entities/session.entity.d.ts +20 -0
- package/dist/database/entities/session.entity.js +87 -0
- package/dist/database/entities/session.entity.js.map +1 -0
- package/dist/database/entities/settings.entity.d.ts +7 -0
- package/dist/database/entities/settings.entity.js +41 -0
- package/dist/database/entities/settings.entity.js.map +1 -0
- package/dist/database/entities/sign-in-challenge.entity.d.ts +23 -0
- package/dist/database/entities/sign-in-challenge.entity.js +80 -0
- package/dist/database/entities/sign-in-challenge.entity.js.map +1 -0
- package/dist/database/entities/signing-key.entity.d.ts +11 -0
- package/dist/database/entities/signing-key.entity.js +54 -0
- package/dist/database/entities/signing-key.entity.js.map +1 -0
- package/dist/database/entities/social-account.entity.d.ts +13 -0
- package/dist/database/entities/social-account.entity.js +54 -0
- package/dist/database/entities/social-account.entity.js.map +1 -0
- package/dist/database/entities/two-factor-secret.entity.d.ts +10 -0
- package/dist/database/entities/two-factor-secret.entity.js +48 -0
- package/dist/database/entities/two-factor-secret.entity.js.map +1 -0
- package/dist/database/entities/user.entity.d.ts +34 -0
- package/dist/database/entities/user.entity.js +129 -0
- package/dist/database/entities/user.entity.js.map +1 -0
- package/dist/database/entities/webhook-delivery.entity.d.ts +17 -0
- package/dist/database/entities/webhook-delivery.entity.js +79 -0
- package/dist/database/entities/webhook-delivery.entity.js.map +1 -0
- package/dist/database/entities/webhook.entity.d.ts +12 -0
- package/dist/database/entities/webhook.entity.js +58 -0
- package/dist/database/entities/webhook.entity.js.map +1 -0
- package/dist/database/typeorm-row.d.ts +21 -0
- package/dist/database/typeorm-row.js +29 -0
- package/dist/database/typeorm-row.js.map +1 -0
- package/dist/features/account/account.controller.d.ts +259 -0
- package/dist/features/account/account.controller.js +372 -0
- package/dist/features/account/account.controller.js.map +1 -0
- package/dist/features/account/account.dto.d.ts +16 -0
- package/dist/features/account/account.dto.js +61 -0
- package/dist/features/account/account.dto.js.map +1 -0
- package/dist/features/account/data-export.service.d.ts +85 -0
- package/dist/features/account/data-export.service.js +125 -0
- package/dist/features/account/data-export.service.js.map +1 -0
- package/dist/features/account/health.service.d.ts +30 -0
- package/dist/features/account/health.service.js +59 -0
- package/dist/features/account/health.service.js.map +1 -0
- package/dist/features/admin/admin.controller.d.ts +382 -0
- package/dist/features/admin/admin.controller.js +623 -0
- package/dist/features/admin/admin.controller.js.map +1 -0
- package/dist/features/admin/admin.dto.d.ts +61 -0
- package/dist/features/admin/admin.dto.js +253 -0
- package/dist/features/admin/admin.dto.js.map +1 -0
- package/dist/features/admin/admin.service.d.ts +142 -0
- package/dist/features/admin/admin.service.js +227 -0
- package/dist/features/admin/admin.service.js.map +1 -0
- package/dist/features/api-keys/api-keys.service.d.ts +67 -0
- package/dist/features/api-keys/api-keys.service.js +144 -0
- package/dist/features/api-keys/api-keys.service.js.map +1 -0
- package/dist/features/email-change/email-change.controller.d.ts +38 -0
- package/dist/features/email-change/email-change.controller.js +85 -0
- package/dist/features/email-change/email-change.controller.js.map +1 -0
- package/dist/features/email-change/email-change.dto.d.ts +10 -0
- package/dist/features/email-change/email-change.dto.js +43 -0
- package/dist/features/email-change/email-change.dto.js.map +1 -0
- package/dist/features/email-change/email-change.service.d.ts +74 -0
- package/dist/features/email-change/email-change.service.js +179 -0
- package/dist/features/email-change/email-change.service.js.map +1 -0
- package/dist/features/email-links/email-verification.service.d.ts +46 -0
- package/dist/features/email-links/email-verification.service.js +94 -0
- package/dist/features/email-links/email-verification.service.js.map +1 -0
- package/dist/features/email-links/link-tokens.service.d.ts +44 -0
- package/dist/features/email-links/link-tokens.service.js +122 -0
- package/dist/features/email-links/link-tokens.service.js.map +1 -0
- package/dist/features/events/auth-events.service.d.ts +52 -0
- package/dist/features/events/auth-events.service.js +117 -0
- package/dist/features/events/auth-events.service.js.map +1 -0
- package/dist/features/maintenance/data-retention.service.d.ts +60 -0
- package/dist/features/maintenance/data-retention.service.js +182 -0
- package/dist/features/maintenance/data-retention.service.js.map +1 -0
- package/dist/features/notifications/notifications.service.d.ts +40 -0
- package/dist/features/notifications/notifications.service.js +94 -0
- package/dist/features/notifications/notifications.service.js.map +1 -0
- package/dist/features/one-time-codes/one-time-codes.service.d.ts +40 -0
- package/dist/features/one-time-codes/one-time-codes.service.js +102 -0
- package/dist/features/one-time-codes/one-time-codes.service.js.map +1 -0
- package/dist/features/organizations/organizations.controller.d.ts +220 -0
- package/dist/features/organizations/organizations.controller.js +337 -0
- package/dist/features/organizations/organizations.controller.js.map +1 -0
- package/dist/features/organizations/organizations.dto.d.ts +31 -0
- package/dist/features/organizations/organizations.dto.js +100 -0
- package/dist/features/organizations/organizations.dto.js.map +1 -0
- package/dist/features/organizations/organizations.service.d.ts +274 -0
- package/dist/features/organizations/organizations.service.js +481 -0
- package/dist/features/organizations/organizations.service.js.map +1 -0
- package/dist/features/passkeys/passkeys.controller.d.ts +92 -0
- package/dist/features/passkeys/passkeys.controller.js +183 -0
- package/dist/features/passkeys/passkeys.controller.js.map +1 -0
- package/dist/features/passkeys/passkeys.dto.d.ts +13 -0
- package/dist/features/passkeys/passkeys.dto.js +50 -0
- package/dist/features/passkeys/passkeys.dto.js.map +1 -0
- package/dist/features/passkeys/passkeys.service.d.ts +159 -0
- package/dist/features/passkeys/passkeys.service.js +350 -0
- package/dist/features/passkeys/passkeys.service.js.map +1 -0
- package/dist/features/passwordless/passwordless-auth.service.d.ts +152 -0
- package/dist/features/passwordless/passwordless-auth.service.js +304 -0
- package/dist/features/passwordless/passwordless-auth.service.js.map +1 -0
- package/dist/features/passwordless/passwordless.controller.d.ts +75 -0
- package/dist/features/passwordless/passwordless.controller.js +163 -0
- package/dist/features/passwordless/passwordless.controller.js.map +1 -0
- package/dist/features/passwordless/passwordless.dto.d.ts +29 -0
- package/dist/features/passwordless/passwordless.dto.js +101 -0
- package/dist/features/passwordless/passwordless.dto.js.map +1 -0
- package/dist/features/passwords/password-auth.service.d.ts +154 -0
- package/dist/features/passwords/password-auth.service.js +317 -0
- package/dist/features/passwords/password-auth.service.js.map +1 -0
- package/dist/features/passwords/password-policy.service.d.ts +63 -0
- package/dist/features/passwords/password-policy.service.js +175 -0
- package/dist/features/passwords/password-policy.service.js.map +1 -0
- package/dist/features/passwords/password.controller.d.ts +95 -0
- package/dist/features/passwords/password.controller.js +193 -0
- package/dist/features/passwords/password.controller.js.map +1 -0
- package/dist/features/passwords/password.dto.d.ts +36 -0
- package/dist/features/passwords/password.dto.js +140 -0
- package/dist/features/passwords/password.dto.js.map +1 -0
- package/dist/features/sessions/session.service.d.ts +132 -0
- package/dist/features/sessions/session.service.js +308 -0
- package/dist/features/sessions/session.service.js.map +1 -0
- package/dist/features/sessions/session.types.d.ts +34 -0
- package/dist/features/sessions/session.types.js +3 -0
- package/dist/features/sessions/session.types.js.map +1 -0
- package/dist/features/settings/settings.defaults.d.ts +2 -0
- package/dist/features/settings/settings.defaults.js +7 -0
- package/dist/features/settings/settings.defaults.js.map +1 -0
- package/dist/features/settings/settings.service.d.ts +44 -0
- package/dist/features/settings/settings.service.js +112 -0
- package/dist/features/settings/settings.service.js.map +1 -0
- package/dist/features/settings/settings.types.d.ts +133 -0
- package/dist/features/settings/settings.types.js +3 -0
- package/dist/features/settings/settings.types.js.map +1 -0
- package/dist/features/settings/settings.validation.d.ts +33 -0
- package/dist/features/settings/settings.validation.js +614 -0
- package/dist/features/settings/settings.validation.js.map +1 -0
- package/dist/features/sign-in/sign-in-challenges.service.d.ts +54 -0
- package/dist/features/sign-in/sign-in-challenges.service.js +104 -0
- package/dist/features/sign-in/sign-in-challenges.service.js.map +1 -0
- package/dist/features/sign-in/sign-in.service.d.ts +127 -0
- package/dist/features/sign-in/sign-in.service.js +248 -0
- package/dist/features/sign-in/sign-in.service.js.map +1 -0
- package/dist/features/sign-in/sign-in.types.d.ts +22 -0
- package/dist/features/sign-in/sign-in.types.js +3 -0
- package/dist/features/sign-in/sign-in.types.js.map +1 -0
- package/dist/features/signing-keys/jwks.controller.d.ts +17 -0
- package/dist/features/signing-keys/jwks.controller.js +51 -0
- package/dist/features/signing-keys/jwks.controller.js.map +1 -0
- package/dist/features/signing-keys/signing-keys.service.d.ts +67 -0
- package/dist/features/signing-keys/signing-keys.service.js +142 -0
- package/dist/features/signing-keys/signing-keys.service.js.map +1 -0
- package/dist/features/social/social-auth.service.d.ts +100 -0
- package/dist/features/social/social-auth.service.js +232 -0
- package/dist/features/social/social-auth.service.js.map +1 -0
- package/dist/features/social/social-providers.service.d.ts +97 -0
- package/dist/features/social/social-providers.service.js +214 -0
- package/dist/features/social/social-providers.service.js.map +1 -0
- package/dist/features/social/social.controller.d.ts +54 -0
- package/dist/features/social/social.controller.js +124 -0
- package/dist/features/social/social.controller.js.map +1 -0
- package/dist/features/social/social.dto.d.ts +11 -0
- package/dist/features/social/social.dto.js +38 -0
- package/dist/features/social/social.dto.js.map +1 -0
- package/dist/features/two-factor/two-factor.controller.d.ts +84 -0
- package/dist/features/two-factor/two-factor.controller.js +174 -0
- package/dist/features/two-factor/two-factor.controller.js.map +1 -0
- package/dist/features/two-factor/two-factor.dto.d.ts +10 -0
- package/dist/features/two-factor/two-factor.dto.js +37 -0
- package/dist/features/two-factor/two-factor.dto.js.map +1 -0
- package/dist/features/two-factor/two-factor.service.d.ts +171 -0
- package/dist/features/two-factor/two-factor.service.js +348 -0
- package/dist/features/two-factor/two-factor.service.js.map +1 -0
- package/dist/features/users/sign-in-methods.service.d.ts +40 -0
- package/dist/features/users/sign-in-methods.service.js +81 -0
- package/dist/features/users/sign-in-methods.service.js.map +1 -0
- package/dist/features/users/sign-up-rules.d.ts +12 -0
- package/dist/features/users/sign-up-rules.js +29 -0
- package/dist/features/users/sign-up-rules.js.map +1 -0
- package/dist/features/users/users.service.d.ts +246 -0
- package/dist/features/users/users.service.js +509 -0
- package/dist/features/users/users.service.js.map +1 -0
- package/dist/features/users/users.types.d.ts +24 -0
- package/dist/features/users/users.types.js +3 -0
- package/dist/features/users/users.types.js.map +1 -0
- package/dist/features/webhooks/webhook-delivery.worker.d.ts +55 -0
- package/dist/features/webhooks/webhook-delivery.worker.js +175 -0
- package/dist/features/webhooks/webhook-delivery.worker.js.map +1 -0
- package/dist/features/webhooks/webhook-signature.d.ts +28 -0
- package/dist/features/webhooks/webhook-signature.js +85 -0
- package/dist/features/webhooks/webhook-signature.js.map +1 -0
- package/dist/features/webhooks/webhooks.service.d.ts +144 -0
- package/dist/features/webhooks/webhooks.service.js +238 -0
- package/dist/features/webhooks/webhooks.service.js.map +1 -0
- package/dist/guards/auth.decorators.d.ts +65 -0
- package/dist/guards/auth.decorators.js +68 -0
- package/dist/guards/auth.decorators.js.map +1 -0
- package/dist/guards/auth.guard.d.ts +47 -0
- package/dist/guards/auth.guard.js +132 -0
- package/dist/guards/auth.guard.js.map +1 -0
- package/dist/index.d.ts +38 -0
- package/dist/index.js +95 -0
- package/dist/index.js.map +1 -0
- package/dist/integrations/console-email-sender.d.ts +15 -0
- package/dist/integrations/console-email-sender.js +26 -0
- package/dist/integrations/console-email-sender.js.map +1 -0
- package/dist/integrations/msg91-sms-sender.d.ts +28 -0
- package/dist/integrations/msg91-sms-sender.js +46 -0
- package/dist/integrations/msg91-sms-sender.js.map +1 -0
- package/docs/README.md +39 -0
- package/docs/admin-api-keys-webhooks.md +147 -0
- package/docs/api-reference.md +175 -0
- package/docs/architecture.md +119 -0
- package/docs/client-integration.md +192 -0
- package/docs/code-walkthrough.md +273 -0
- package/docs/configuration.md +229 -0
- package/docs/endpoints/README.md +151 -0
- package/docs/endpoints/account.md +363 -0
- package/docs/endpoints/admin.md +422 -0
- package/docs/endpoints/email-password.md +261 -0
- package/docs/endpoints/organizations.md +192 -0
- package/docs/endpoints/passkeys.md +195 -0
- package/docs/endpoints/passwordless.md +214 -0
- package/docs/endpoints/social.md +116 -0
- package/docs/endpoints/two-factor.md +146 -0
- package/docs/error-codes.md +100 -0
- package/docs/events.md +83 -0
- package/docs/getting-started.md +139 -0
- package/docs/manual-testing.md +215 -0
- package/docs/organizations.md +86 -0
- package/docs/production-checklist.md +60 -0
- package/docs/protecting-routes.md +147 -0
- package/docs/security.md +61 -0
- package/docs/sign-in-flows.md +294 -0
- package/package.json +92 -4
|
@@ -0,0 +1,363 @@
|
|
|
1
|
+
# Account and sessions
|
|
2
|
+
|
|
3
|
+
Shared formats, the sign-in result and the user object are described in [Endpoints](README.md).
|
|
4
|
+
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
## POST /auth/refresh
|
|
8
|
+
|
|
9
|
+
Swaps a refresh token for a new access token **and a new refresh token**. Each refresh token works once. Always store the new one, and never run two refreshes at the same time; see [Client integration](../client-integration.md#refreshing-tokens).
|
|
10
|
+
|
|
11
|
+
| | |
|
|
12
|
+
|---|---|
|
|
13
|
+
| Auth | Public |
|
|
14
|
+
| Rate limit | 120 per IP per minute |
|
|
15
|
+
|
|
16
|
+
**Request**
|
|
17
|
+
|
|
18
|
+
```json
|
|
19
|
+
{ "refreshToken": "rt_Q2x4bWZkY2V0ZXN0dG9rZW5leGFtcGxlMTIzNDU2Nzg5MDE" }
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
With [cookie mode](../client-integration.md#web-apps-refresh-token-in-a-cookie), web apps send `{}` instead (with `credentials: 'include'`): the token comes from the HttpOnly cookie, the request must come from one of `refreshTokenCookie.allowedOrigins` (otherwise `403 FORBIDDEN`), and the response carries `"refreshTokenInCookie": true` instead of `refreshToken`.
|
|
23
|
+
|
|
24
|
+
**Response `200`**
|
|
25
|
+
|
|
26
|
+
```json
|
|
27
|
+
{
|
|
28
|
+
"success": true,
|
|
29
|
+
"accessToken": "eyJhbGciOiJFUzI1NiIs...",
|
|
30
|
+
"expiresIn": 900,
|
|
31
|
+
"refreshToken": "rt_TmV3UmVmcmVzaFRva2VuRXhhbXBsZTEyMzQ1Njc4OTAxMjM",
|
|
32
|
+
"refreshTokenExpiresAt": "2026-11-19T06:45:00.000Z",
|
|
33
|
+
"sessionId": "8c1e2f4a-3b6d-4e8f-9a1b-2c3d4e5f6a7b"
|
|
34
|
+
}
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
**Errors**
|
|
38
|
+
|
|
39
|
+
| Status | `code` | When |
|
|
40
|
+
|---|---|---|
|
|
41
|
+
| 401 | `INVALID_TOKEN` | Unknown, expired or already used (a reused token also ends the session), the session ended, or the account isn't `ACTIVE`. Send the user to sign-in |
|
|
42
|
+
|
|
43
|
+
---
|
|
44
|
+
|
|
45
|
+
## POST /auth/logout
|
|
46
|
+
|
|
47
|
+
Signs out the device that sends the request. Auth: User. No body.
|
|
48
|
+
|
|
49
|
+
**Response `200`**
|
|
50
|
+
|
|
51
|
+
```json
|
|
52
|
+
{ "success": true, "message": "You have been signed out." }
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
## POST /auth/logout-all
|
|
56
|
+
|
|
57
|
+
Signs out every device of the user, including this one. Auth: User. No body.
|
|
58
|
+
|
|
59
|
+
**Response `200`**
|
|
60
|
+
|
|
61
|
+
```json
|
|
62
|
+
{ "success": true, "message": "You have been signed out on all devices.", "endedSessions": 3 }
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
---
|
|
66
|
+
|
|
67
|
+
## GET /auth/me
|
|
68
|
+
|
|
69
|
+
| | |
|
|
70
|
+
|---|---|
|
|
71
|
+
| Auth | User, session checked live |
|
|
72
|
+
|
|
73
|
+
**Response `200`**
|
|
74
|
+
|
|
75
|
+
```json
|
|
76
|
+
{ "success": true, "user": { "id": "5f0c...", "email": "asha@example.com", "status": "ACTIVE", "...": "see the user object" } }
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
## PATCH /auth/me
|
|
80
|
+
|
|
81
|
+
Changes the user's own name and app fields. Users can't change their roles, status, email or phone here.
|
|
82
|
+
|
|
83
|
+
| | |
|
|
84
|
+
|---|---|
|
|
85
|
+
| Auth | User, session checked live |
|
|
86
|
+
|
|
87
|
+
**Request** (all fields optional):
|
|
88
|
+
|
|
89
|
+
```json
|
|
90
|
+
{ "firstName": "Asha", "lastName": "Rao-Mehta", "metadata": { "preferredLanguage": "hi" } }
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
| Field | Type | Rules |
|
|
94
|
+
|---|---|---|
|
|
95
|
+
| `firstName` | string | up to 100 characters |
|
|
96
|
+
| `lastName` | string | up to 100 characters |
|
|
97
|
+
| `metadata` | object | replaces the whole object |
|
|
98
|
+
|
|
99
|
+
**Response `200`:** `{ "success": true, "user": { ... } }`
|
|
100
|
+
|
|
101
|
+
---
|
|
102
|
+
|
|
103
|
+
## GET /auth/sign-in-methods
|
|
104
|
+
|
|
105
|
+
How the user can sign in, for a "Sign-in methods" screen. Auth: User.
|
|
106
|
+
|
|
107
|
+
**Response `200`**
|
|
108
|
+
|
|
109
|
+
```json
|
|
110
|
+
{
|
|
111
|
+
"success": true,
|
|
112
|
+
"signInMethods": {
|
|
113
|
+
"hasPassword": true,
|
|
114
|
+
"canUseEmailCode": true,
|
|
115
|
+
"canUsePhoneCode": false,
|
|
116
|
+
"socialAccounts": [{ "provider": "google", "email": "asha@gmail.com", "linkedAt": "2026-10-02T10:00:00.000Z" }],
|
|
117
|
+
"passkeyCount": 1
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
---
|
|
123
|
+
|
|
124
|
+
## GET /auth/sessions
|
|
125
|
+
|
|
126
|
+
The user's signed-in devices. Auth: User.
|
|
127
|
+
|
|
128
|
+
**Response `200`**
|
|
129
|
+
|
|
130
|
+
```json
|
|
131
|
+
{
|
|
132
|
+
"success": true,
|
|
133
|
+
"sessions": [
|
|
134
|
+
{
|
|
135
|
+
"id": "8c1e2f4a-3b6d-4e8f-9a1b-2c3d4e5f6a7b",
|
|
136
|
+
"isCurrentDevice": true,
|
|
137
|
+
"signInMethod": "password",
|
|
138
|
+
"ipAddress": "203.0.113.10",
|
|
139
|
+
"userAgent": "Mozilla/5.0 (iPhone; CPU iPhone OS 18_0 like Mac OS X) ...",
|
|
140
|
+
"createdAt": "2026-10-20T06:30:00.000Z",
|
|
141
|
+
"lastUsedAt": "2026-10-20T07:10:00.000Z"
|
|
142
|
+
}
|
|
143
|
+
]
|
|
144
|
+
}
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
`signInMethod` is one of `password`, `email_otp`, `magic_link`, `phone_otp`, `google`, `apple`, `facebook`, `passkey`.
|
|
148
|
+
|
|
149
|
+
## DELETE /auth/sessions/:sessionId
|
|
150
|
+
|
|
151
|
+
Signs out one of the user's devices. Auth: User. No body.
|
|
152
|
+
|
|
153
|
+
**Response `200`:** `{ "success": true }`. Errors: `404 NOT_FOUND` (not this user's, or already signed out).
|
|
154
|
+
|
|
155
|
+
---
|
|
156
|
+
|
|
157
|
+
## POST /auth/deactivate
|
|
158
|
+
|
|
159
|
+
Switches the account off and signs out everywhere. Signing in later offers reactivation.
|
|
160
|
+
|
|
161
|
+
| | |
|
|
162
|
+
|---|---|
|
|
163
|
+
| Auth | User, session checked live |
|
|
164
|
+
|
|
165
|
+
**Request:** no body.
|
|
166
|
+
|
|
167
|
+
**Response `200`**
|
|
168
|
+
|
|
169
|
+
```json
|
|
170
|
+
{ "success": true, "message": "Your account has been deactivated. Sign in again at any time to reactivate it." }
|
|
171
|
+
```
|
|
172
|
+
|
|
173
|
+
**Errors:** `403 ACCOUNT_SUSPENDED` (a suspended account can't deactivate itself).
|
|
174
|
+
|
|
175
|
+
## POST /auth/reactivate
|
|
176
|
+
|
|
177
|
+
After a sign-in returned `ACCOUNT_DEACTIVATED`, switches the account back on and signs in.
|
|
178
|
+
|
|
179
|
+
| | |
|
|
180
|
+
|---|---|
|
|
181
|
+
| Auth | Public |
|
|
182
|
+
|
|
183
|
+
**Request**
|
|
184
|
+
|
|
185
|
+
```json
|
|
186
|
+
{ "reactivationToken": "ch_cmVhY3RpdmF0aW9uZXhhbXBsZXRva2VuMTIzNDU2Nzg5MA" }
|
|
187
|
+
```
|
|
188
|
+
|
|
189
|
+
**Response `200`:** the [sign-in result](README.md#sign-in-result) (it may be `two_factor_required`).
|
|
190
|
+
|
|
191
|
+
**Errors**
|
|
192
|
+
|
|
193
|
+
| Status | `code` | When |
|
|
194
|
+
|---|---|---|
|
|
195
|
+
| 400 | `INVALID_TOKEN` | Unknown, used or expired (10 minutes) |
|
|
196
|
+
| 409 | `ACCOUNT_NOT_DEACTIVATED` | The account isn't deactivated |
|
|
197
|
+
|
|
198
|
+
---
|
|
199
|
+
|
|
200
|
+
## POST /auth/email/change
|
|
201
|
+
|
|
202
|
+
Starts changing the account's email: sends a confirmation link to the **new** address. Nothing changes until the link is used.
|
|
203
|
+
|
|
204
|
+
| | |
|
|
205
|
+
|---|---|
|
|
206
|
+
| Auth | User, session checked live |
|
|
207
|
+
| Rate limit | 5 per user per hour |
|
|
208
|
+
|
|
209
|
+
**Request**
|
|
210
|
+
|
|
211
|
+
```json
|
|
212
|
+
{ "newEmail": "asha.new@example.com", "currentPassword": "correct horse battery" }
|
|
213
|
+
```
|
|
214
|
+
|
|
215
|
+
| Field | Rules |
|
|
216
|
+
|---|---|
|
|
217
|
+
| `newEmail` | required; must pass `registration.allowedEmailDomains` |
|
|
218
|
+
| `currentPassword` | required when the account has a password. Accounts without one (signed up with a code, link, Google or passkey) leave it out, but must have signed in within the last 10 minutes |
|
|
219
|
+
|
|
220
|
+
**Response `200`** (the same whether or not the new address already belongs to another account, so it can't be used to find out who has an account; a taken address simply gets no link):
|
|
221
|
+
|
|
222
|
+
```json
|
|
223
|
+
{ "success": true, "message": "If this email can be used, a confirmation link is on its way to it." }
|
|
224
|
+
```
|
|
225
|
+
|
|
226
|
+
The new address receives an email of type `confirm_email_change` with a `token`. A newer request cancels the older link.
|
|
227
|
+
|
|
228
|
+
**Errors**
|
|
229
|
+
|
|
230
|
+
| Status | `code` | When |
|
|
231
|
+
|---|---|---|
|
|
232
|
+
| 400 | `INVALID_EMAIL` | Not an email address |
|
|
233
|
+
| 400 | `EMAIL_UNCHANGED` | It's already the account's email |
|
|
234
|
+
| 400 | `EMAIL_DOMAIN_NOT_ALLOWED` | Outside `registration.allowedEmailDomains` |
|
|
235
|
+
| 401 | `INVALID_CREDENTIALS` | Wrong or missing `currentPassword` |
|
|
236
|
+
| 403 | `RECENT_SIGN_IN_REQUIRED` | No password, and the sign-in was more than 10 minutes ago: sign in again, then retry |
|
|
237
|
+
| 429 | `TOO_MANY_REQUESTS` | Rate limit |
|
|
238
|
+
|
|
239
|
+
## POST /auth/email/change/confirm
|
|
240
|
+
|
|
241
|
+
Uses the link from the `confirm_email_change` email. Switches the email, marks it verified, cancels links sent to the old address, and emails the **old** address a `email_changed` notice (with the new address masked) so an unwanted change gets noticed. Devices stay signed in.
|
|
242
|
+
|
|
243
|
+
| | |
|
|
244
|
+
|---|---|
|
|
245
|
+
| Auth | Public (the link may be opened on another device) |
|
|
246
|
+
|
|
247
|
+
**Request**
|
|
248
|
+
|
|
249
|
+
```json
|
|
250
|
+
{ "token": "ec_U2FtcGxlRW1haWxDaGFuZ2VUb2tlbkV4YW1wbGUxMjM0NTY" }
|
|
251
|
+
```
|
|
252
|
+
|
|
253
|
+
**Response `200`**
|
|
254
|
+
|
|
255
|
+
```json
|
|
256
|
+
{
|
|
257
|
+
"success": true,
|
|
258
|
+
"message": "Your email has been changed.",
|
|
259
|
+
"user": { "id": "bb306e8b-ff08-4932-859d-eaa38aa8c77c", "email": "asha.new@example.com", "isEmailVerified": true, "...": "the user object" }
|
|
260
|
+
}
|
|
261
|
+
```
|
|
262
|
+
|
|
263
|
+
**Errors**
|
|
264
|
+
|
|
265
|
+
| Status | `code` | When |
|
|
266
|
+
|---|---|---|
|
|
267
|
+
| 400 | `INVALID_TOKEN` | Unknown, expired (`emailChange.linkExpiresInMinutes`, 60 by default), cancelled by a newer request, or already used |
|
|
268
|
+
| 409 | `EMAIL_IN_USE` | Another account took the address after the link was sent |
|
|
269
|
+
|
|
270
|
+
Events: `user.email_change_requested`, then `user.email_changed`.
|
|
271
|
+
|
|
272
|
+
---
|
|
273
|
+
|
|
274
|
+
## GET /auth/me/export
|
|
275
|
+
|
|
276
|
+
"Download my data", for privacy laws such as India's DPDP Act and the GDPR: everything this library stores about the user. Never includes password hashes, 2FA secrets, backup codes, tokens or keys. Add your app's own data next to it in your own export.
|
|
277
|
+
|
|
278
|
+
| | |
|
|
279
|
+
|---|---|
|
|
280
|
+
| Auth | User, session checked live |
|
|
281
|
+
| Rate limit | 5 per user per hour |
|
|
282
|
+
|
|
283
|
+
**Response `200`** (shortened)
|
|
284
|
+
|
|
285
|
+
```json
|
|
286
|
+
{
|
|
287
|
+
"success": true,
|
|
288
|
+
"exportedAt": "2026-10-20T09:36:59.793Z",
|
|
289
|
+
"profile": {
|
|
290
|
+
"id": "bb306e8b-ff08-4932-859d-eaa38aa8c77c",
|
|
291
|
+
"email": "asha.new@example.com",
|
|
292
|
+
"...": "the user object, plus:",
|
|
293
|
+
"termsAcceptedAt": "2026-10-20T09:36:59.277Z",
|
|
294
|
+
"privacyPolicyAcceptedAt": "2026-10-20T09:36:59.277Z",
|
|
295
|
+
"onboardingCompletedAt": null,
|
|
296
|
+
"updatedAt": "2026-10-20T09:36:59.767Z"
|
|
297
|
+
},
|
|
298
|
+
"signInMethods": { "hasPassword": true, "canUseEmailCode": true, "canUsePhoneCode": false, "socialAccounts": [], "passkeyCount": 0 },
|
|
299
|
+
"linkedAccounts": [{ "provider": "google", "email": "asha@gmail.com", "linkedAt": "2026-10-20T09:40:00.000Z" }],
|
|
300
|
+
"passkeys": [{ "name": "MacBook", "createdAt": "2026-10-20T09:41:00.000Z", "lastUsedAt": null }],
|
|
301
|
+
"devices": [
|
|
302
|
+
{ "signInMethod": "password", "ipAddress": "203.0.113.10", "userAgent": "Mozilla/5.0 ...", "signedInAt": "2026-10-20T09:36:59.558Z", "lastUsedAt": "2026-10-20T09:36:59.558Z", "endedAt": null }
|
|
303
|
+
],
|
|
304
|
+
"organizations": [{ "name": "Acme Travels", "role": "owner", "joinedAt": "2026-10-20T09:42:00.000Z" }],
|
|
305
|
+
"securityHistory": [
|
|
306
|
+
{ "event": "user.email_changed", "ipAddress": "203.0.113.10", "userAgent": "Mozilla/5.0 ...", "details": { "newEmail": "a***@example.com", "previousEmail": "a***@example.com" }, "at": "2026-10-20T09:36:59.770Z" }
|
|
307
|
+
]
|
|
308
|
+
}
|
|
309
|
+
```
|
|
310
|
+
|
|
311
|
+
`devices` includes ended sessions until the data-retention cleanup removes them; `securityHistory` is the newest 1,000 audit entries.
|
|
312
|
+
|
|
313
|
+
## GET /auth/health
|
|
314
|
+
|
|
315
|
+
For load balancers and uptime monitors. Checks only what the library needs: PostgreSQL, and Redis when `redisUrl` is set. Says nothing about users.
|
|
316
|
+
|
|
317
|
+
| | |
|
|
318
|
+
|---|---|
|
|
319
|
+
| Auth | Public |
|
|
320
|
+
|
|
321
|
+
**Response `200`**
|
|
322
|
+
|
|
323
|
+
```json
|
|
324
|
+
{ "success": true, "status": "ok", "checks": { "database": "ok", "redis": "not_used" } }
|
|
325
|
+
```
|
|
326
|
+
|
|
327
|
+
**Response `503`** when a check fails (each check takes at most 2 seconds):
|
|
328
|
+
|
|
329
|
+
```json
|
|
330
|
+
{ "success": false, "status": "error", "checks": { "database": "ok", "redis": "error" } }
|
|
331
|
+
```
|
|
332
|
+
|
|
333
|
+
---
|
|
334
|
+
|
|
335
|
+
## DELETE /auth/me
|
|
336
|
+
|
|
337
|
+
Deletes the account permanently. Personal data and every way to sign in are wiped, and all devices are signed out. Ask the user to confirm in your UI first.
|
|
338
|
+
|
|
339
|
+
| | |
|
|
340
|
+
|---|---|
|
|
341
|
+
| Auth | User, session checked live |
|
|
342
|
+
|
|
343
|
+
**Request:** no body.
|
|
344
|
+
|
|
345
|
+
**Response `200`**
|
|
346
|
+
|
|
347
|
+
```json
|
|
348
|
+
{ "success": true, "message": "Your account has been deleted." }
|
|
349
|
+
```
|
|
350
|
+
|
|
351
|
+
## GET /.well-known/jwks.json
|
|
352
|
+
|
|
353
|
+
The public keys that verify access tokens, for your other services. Public; cached 5 minutes.
|
|
354
|
+
|
|
355
|
+
**Response `200`**
|
|
356
|
+
|
|
357
|
+
```json
|
|
358
|
+
{
|
|
359
|
+
"keys": [
|
|
360
|
+
{ "kty": "EC", "crv": "P-256", "x": "f83OJ3D2xF1Bg8vub9tLe1gHMzV76e8Tus9uPHvRVEU", "y": "x_FEzRu9m36HLN_tue659LNpXW6pCyStikYjKIWI5a0", "kid": "NzbLsXh8uDCcd-6MNwXF4W_7noWXFZAfHkxZsRGC9Xs", "alg": "ES256", "use": "sig" }
|
|
361
|
+
]
|
|
362
|
+
}
|
|
363
|
+
```
|