@gatwech/auth 1.0.0-beta.18
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/README.md +31 -0
- package/dist/access-BO2g7QVe.mjs +45 -0
- package/dist/access-C6O_osEz.mjs +79 -0
- package/dist/access-DT1f6l5k.mjs +51 -0
- package/dist/adapter-factory-BZ2Qiqpn.mjs +640 -0
- package/dist/adapters/drizzle-adapter/index.d.mts +47 -0
- package/dist/adapters/drizzle-adapter/index.mjs +208 -0
- package/dist/adapters/index.d.mts +132 -0
- package/dist/adapters/index.mjs +18 -0
- package/dist/adapters/kysely-adapter/index.d.mts +47 -0
- package/dist/adapters/kysely-adapter/index.mjs +11 -0
- package/dist/adapters/memory-adapter/index.d.mts +14 -0
- package/dist/adapters/memory-adapter/index.mjs +154 -0
- package/dist/adapters/mongodb-adapter/index.d.mts +35 -0
- package/dist/adapters/mongodb-adapter/index.mjs +315 -0
- package/dist/adapters/prisma-adapter/index.d.mts +34 -0
- package/dist/adapters/prisma-adapter/index.mjs +159 -0
- package/dist/adapters/test.d.mts +81 -0
- package/dist/adapters/test.mjs +793 -0
- package/dist/admin-Bcq53Nwj.mjs +743 -0
- package/dist/admin-DtfO1PLg.d.mts +1689 -0
- package/dist/anonymous-CRt1imBW.mjs +107 -0
- package/dist/api/index.d.mts +6 -0
- package/dist/api/index.mjs +17 -0
- package/dist/api-0pR_I-Nx.mjs +3139 -0
- package/dist/auth-CBUoBX6o.mjs +233 -0
- package/dist/bearer-Djf_awfo.mjs +63 -0
- package/dist/bun-sqlite-dialect-CeNvMaZz.mjs +155 -0
- package/dist/captcha-BqaMxlKC.mjs +178 -0
- package/dist/chunk-BK_LfMhE.mjs +40 -0
- package/dist/client/index.d.mts +186 -0
- package/dist/client/index.mjs +7 -0
- package/dist/client/plugins/index.d.mts +949 -0
- package/dist/client/plugins/index.mjs +539 -0
- package/dist/client/react/index.d.mts +179 -0
- package/dist/client/react/index.mjs +69 -0
- package/dist/client-BOX93C3d.d.mts +1250 -0
- package/dist/client-CNY0tn9g.d.mts +628 -0
- package/dist/client-CygJhqeB.mjs +29 -0
- package/dist/client-WiN43tAS.mjs +17 -0
- package/dist/client-aExCkfwm.mjs +30 -0
- package/dist/cookies/index.d.mts +7 -0
- package/dist/cookies/index.mjs +7 -0
- package/dist/cookies-cJObLwn1.mjs +597 -0
- package/dist/crypto/index.d.mts +44 -0
- package/dist/crypto/index.mjs +4 -0
- package/dist/crypto-Bb42eMrH.mjs +70 -0
- package/dist/custom-session-L3t7ecsd.mjs +67 -0
- package/dist/date-Cx2yCiC4.mjs +115 -0
- package/dist/db/index.d.mts +7 -0
- package/dist/db/index.mjs +15 -0
- package/dist/db-BrstmDhc.mjs +1124 -0
- package/dist/device-authorization-V4s3h4Mj.mjs +557 -0
- package/dist/dialect-CeddeGHf.mjs +72 -0
- package/dist/email-otp-BtDHSw14.mjs +592 -0
- package/dist/esm-C-QicDNz.mjs +4090 -0
- package/dist/generic-oauth-CL5X27ZI.mjs +445 -0
- package/dist/get-request-ip-DSjrEpGo.mjs +27 -0
- package/dist/get-tables-BQP7YW9c.mjs +249 -0
- package/dist/has-permission-BpAr7uCn.mjs +14 -0
- package/dist/haveibeenpwned-cMpJvmzI.mjs +43 -0
- package/dist/helper-tmxW3BHj.d.mts +21 -0
- package/dist/index-34ONrP8l.d.mts +503 -0
- package/dist/index-65G5U5DB-DSdjzreF.d.mts +2543 -0
- package/dist/index-B-XKqFvY.d.mts +30 -0
- package/dist/index-B3n8e37d.d.mts +165 -0
- package/dist/index-BBm8nQ9Q.d.mts +42 -0
- package/dist/index-BHoQlf7a.d.mts +7699 -0
- package/dist/index-BYMI9r_d.d.mts +257 -0
- package/dist/index-BqhKCbPH.d.mts +36 -0
- package/dist/index-Buhn3hkR.d.mts +433 -0
- package/dist/index-C-u1h_WX.d.mts +174 -0
- package/dist/index-C7fQuk-V.d.mts +41 -0
- package/dist/index-CM-CFWwr.d.mts +1919 -0
- package/dist/index-CuFzhoS6.d.mts +359 -0
- package/dist/index-Cxi7TbLE.d.mts +11347 -0
- package/dist/index-DB7t8whN.d.mts +1 -0
- package/dist/index-DKNNV1kb.d.mts +626 -0
- package/dist/index-DR0xXno9.d.mts +113 -0
- package/dist/index-D_k662QG.d.mts +833 -0
- package/dist/index-DaBcikv9.d.mts +118 -0
- package/dist/index-DlaMq1nb.d.mts +955 -0
- package/dist/index-DoXZYQpq.d.mts +290 -0
- package/dist/index-G6V0Z_Mn.d.mts +125 -0
- package/dist/index-z0KSvE5i.d.mts +246 -0
- package/dist/index-zjjNBRY2.d.mts +95 -0
- package/dist/index.d.mts +12 -0
- package/dist/index.mjs +33 -0
- package/dist/integrations/next-js.d.mts +21 -0
- package/dist/integrations/next-js.mjs +62 -0
- package/dist/integrations/node.d.mts +15 -0
- package/dist/integrations/node.mjs +15 -0
- package/dist/integrations/react-start.d.mts +15 -0
- package/dist/integrations/react-start.mjs +46 -0
- package/dist/json-D0TBLy4q.mjs +24 -0
- package/dist/jwt-CmxZAGe2.mjs +94 -0
- package/dist/jwt-lHV4QHpD.mjs +387 -0
- package/dist/kysely-adapter-DpzYO8Yf.mjs +181 -0
- package/dist/magic-link-Bk-ueorR.mjs +176 -0
- package/dist/misc-beA1w3XV.mjs +7 -0
- package/dist/multi-session-DRrLKrg9.mjs +144 -0
- package/dist/node-sqlite-dialect-BcKxBQnm.mjs +155 -0
- package/dist/oauth-proxy-D1sWh9B_.mjs +133 -0
- package/dist/oauth2/index.d.mts +60 -0
- package/dist/oauth2/index.mjs +19 -0
- package/dist/one-tap-DMswkTEc.mjs +113 -0
- package/dist/organization-BArHO_5v.mjs +3857 -0
- package/dist/parser-DcrIEuXE.mjs +73 -0
- package/dist/passkey-CcD4CnhM.mjs +558 -0
- package/dist/password-sVC4nePO.mjs +25 -0
- package/dist/permission-DLYUF3cW.mjs +15 -0
- package/dist/phone-number-rHDIlh-2.mjs +485 -0
- package/dist/plugin-helper-4L-lzsjZ.mjs +16 -0
- package/dist/plugins/access/index.d.mts +3 -0
- package/dist/plugins/access/index.mjs +3 -0
- package/dist/plugins/admin/access/index.d.mts +116 -0
- package/dist/plugins/admin/access/index.mjs +4 -0
- package/dist/plugins/admin/index.d.mts +9 -0
- package/dist/plugins/admin/index.mjs +22 -0
- package/dist/plugins/anonymous/index.d.mts +7 -0
- package/dist/plugins/anonymous/index.mjs +18 -0
- package/dist/plugins/bearer/index.d.mts +2 -0
- package/dist/plugins/bearer/index.mjs +8 -0
- package/dist/plugins/captcha/index.d.mts +2 -0
- package/dist/plugins/captcha/index.mjs +4 -0
- package/dist/plugins/custom-session/index.d.mts +7 -0
- package/dist/plugins/custom-session/index.mjs +19 -0
- package/dist/plugins/device-authorization/index.d.mts +4 -0
- package/dist/plugins/device-authorization/index.mjs +18 -0
- package/dist/plugins/email-otp/index.d.mts +3 -0
- package/dist/plugins/email-otp/index.mjs +19 -0
- package/dist/plugins/generic-oauth/index.d.mts +7 -0
- package/dist/plugins/generic-oauth/index.mjs +18 -0
- package/dist/plugins/haveibeenpwned/index.d.mts +2 -0
- package/dist/plugins/haveibeenpwned/index.mjs +18 -0
- package/dist/plugins/index.d.mts +139 -0
- package/dist/plugins/index.mjs +47 -0
- package/dist/plugins/jwt/index.d.mts +7 -0
- package/dist/plugins/jwt/index.mjs +18 -0
- package/dist/plugins/magic-link/index.d.mts +2 -0
- package/dist/plugins/magic-link/index.mjs +18 -0
- package/dist/plugins/multi-session/index.d.mts +3 -0
- package/dist/plugins/multi-session/index.mjs +18 -0
- package/dist/plugins/oauth-proxy/index.d.mts +2 -0
- package/dist/plugins/oauth-proxy/index.mjs +18 -0
- package/dist/plugins/one-tap/index.d.mts +2 -0
- package/dist/plugins/one-tap/index.mjs +18 -0
- package/dist/plugins/one-time-token/index.d.mts +7 -0
- package/dist/plugins/one-time-token/index.mjs +47 -0
- package/dist/plugins/organization/access/index.d.mts +4 -0
- package/dist/plugins/organization/access/index.mjs +4 -0
- package/dist/plugins/organization/index.d.mts +9 -0
- package/dist/plugins/organization/index.mjs +22 -0
- package/dist/plugins/passkey/index.d.mts +7 -0
- package/dist/plugins/passkey/index.mjs +18 -0
- package/dist/plugins/phone-number/index.d.mts +7 -0
- package/dist/plugins/phone-number/index.mjs +18 -0
- package/dist/plugins/two-factor/index.d.mts +7 -0
- package/dist/plugins/two-factor/index.mjs +20 -0
- package/dist/plugins/username/index.d.mts +4 -0
- package/dist/plugins/username/index.mjs +18 -0
- package/dist/plugins-3jfNste3.mjs +1544 -0
- package/dist/plugins-hFZT3hmK.d.mts +14 -0
- package/dist/promise-8rrEHRXd.mjs +23154 -0
- package/dist/proxy-CL9PZXJA.mjs +441 -0
- package/dist/session-Dgp133Yt.mjs +413 -0
- package/dist/social-providers/index.d.mts +1 -0
- package/dist/social-providers/index.mjs +3 -0
- package/dist/src/adapters/adapter-factory/index.d.ts +10 -0
- package/dist/src/adapters/adapter-factory/types.d.ts +124 -0
- package/dist/src/adapters/create-test-suite.d.ts +97 -0
- package/dist/src/adapters/drizzle-adapter/drizzle-adapter.d.ts +43 -0
- package/dist/src/adapters/drizzle-adapter/index.d.ts +1 -0
- package/dist/src/adapters/drizzle-adapter/test/generate-schema.d.ts +12 -0
- package/dist/src/adapters/index.d.ts +21 -0
- package/dist/src/adapters/kysely-adapter/bun-sqlite-dialect.d.ts +58 -0
- package/dist/src/adapters/kysely-adapter/dialect.d.ts +13 -0
- package/dist/src/adapters/kysely-adapter/index.d.ts +3 -0
- package/dist/src/adapters/kysely-adapter/kysely-adapter.d.ts +32 -0
- package/dist/src/adapters/kysely-adapter/node-sqlite-dialect.d.ts +58 -0
- package/dist/src/adapters/kysely-adapter/types.d.ts +1 -0
- package/dist/src/adapters/memory-adapter/index.d.ts +1 -0
- package/dist/src/adapters/memory-adapter/memory-adapter.d.ts +9 -0
- package/dist/src/adapters/mongodb-adapter/index.d.ts +1 -0
- package/dist/src/adapters/mongodb-adapter/mongodb-adapter.d.ts +31 -0
- package/dist/src/adapters/prisma-adapter/index.d.ts +1 -0
- package/dist/src/adapters/prisma-adapter/prisma-adapter.d.ts +32 -0
- package/dist/src/adapters/prisma-adapter/test/auth.d.ts +3 -0
- package/dist/src/adapters/prisma-adapter/test/generate-auth-config.d.ts +2 -0
- package/dist/src/adapters/prisma-adapter/test/generate-prisma-schema.d.ts +3 -0
- package/dist/src/adapters/prisma-adapter/test/get-prisma-client.d.ts +7 -0
- package/dist/src/adapters/prisma-adapter/test/push-prisma-schema.d.ts +1 -0
- package/dist/src/adapters/test-adapter.d.ts +61 -0
- package/dist/src/adapters/test.d.ts +78 -0
- package/dist/src/adapters/tests/auth-flow.d.ts +22 -0
- package/dist/src/adapters/tests/index.d.ts +5 -0
- package/dist/src/adapters/tests/normal.d.ts +87 -0
- package/dist/src/adapters/tests/number-id.d.ts +17 -0
- package/dist/src/adapters/tests/performance.d.ts +24 -0
- package/dist/src/adapters/tests/transactions.d.ts +20 -0
- package/dist/src/adapters/utils.d.ts +3 -0
- package/dist/src/api/index.d.ts +7150 -0
- package/dist/src/api/middlewares/index.d.ts +2 -0
- package/dist/src/api/middlewares/oauth.d.ts +15 -0
- package/dist/src/api/middlewares/origin-check.d.ts +8 -0
- package/dist/src/api/rate-limiter/index.d.ts +13 -0
- package/dist/src/api/routes/account.d.ts +623 -0
- package/dist/src/api/routes/callback.d.ts +68 -0
- package/dist/src/api/routes/email-verification.d.ts +266 -0
- package/dist/src/api/routes/error.d.ts +51 -0
- package/dist/src/api/routes/index.d.ts +11 -0
- package/dist/src/api/routes/ok.d.ts +61 -0
- package/dist/src/api/routes/reset-password.d.ts +203 -0
- package/dist/src/api/routes/session.d.ts +586 -0
- package/dist/src/api/routes/sign-in.d.ts +298 -0
- package/dist/src/api/routes/sign-out.d.ts +59 -0
- package/dist/src/api/routes/sign-up.d.ts +625 -0
- package/dist/src/api/routes/update-user.d.ts +862 -0
- package/dist/src/api/to-auth-endpoints.d.ts +3 -0
- package/dist/src/auth.d.ts +25 -0
- package/dist/src/client/broadcast-channel.d.ts +12 -0
- package/dist/src/client/config.d.ts +85 -0
- package/dist/src/client/fetch-plugins.d.ts +14 -0
- package/dist/src/client/index.d.ts +15 -0
- package/dist/src/client/parser.d.ts +12 -0
- package/dist/src/client/path-to-object.d.ts +63 -0
- package/dist/src/client/plugins/index.d.ts +21 -0
- package/dist/src/client/plugins/infer-plugin.d.ts +11 -0
- package/dist/src/client/proxy.d.ts +8 -0
- package/dist/src/client/query.d.ts +16 -0
- package/dist/src/client/react/index.d.ts +130 -0
- package/dist/src/client/react/react-store.d.ts +43 -0
- package/dist/src/client/session-atom.d.ts +18 -0
- package/dist/src/client/session-refresh.d.ts +17 -0
- package/dist/src/client/test-plugin.d.ts +147 -0
- package/dist/src/client/types.d.ts +49 -0
- package/dist/src/client/vanilla.d.ts +124 -0
- package/dist/src/cookies/check-cookies.d.ts +4 -0
- package/dist/src/cookies/cookie-utils.d.ts +16 -0
- package/dist/src/cookies/index.d.ts +56 -0
- package/dist/src/cookies/session-store.d.ts +43 -0
- package/dist/src/crypto/buffer.d.ts +4 -0
- package/dist/src/crypto/index.d.ts +14 -0
- package/dist/src/crypto/jwt.d.ts +4 -0
- package/dist/src/crypto/password.d.ts +5 -0
- package/dist/src/crypto/random.d.ts +1 -0
- package/dist/src/db/field.d.ts +97 -0
- package/dist/src/db/get-migration.d.ts +18 -0
- package/dist/src/db/get-schema.d.ts +6 -0
- package/dist/src/db/get-tables.d.ts +3 -0
- package/dist/src/db/index.d.ts +10 -0
- package/dist/src/db/internal-adapter.d.ts +9 -0
- package/dist/src/db/schema.d.ts +76 -0
- package/dist/src/db/to-zod.d.ts +31 -0
- package/dist/src/db/utils.d.ts +6 -0
- package/dist/src/db/with-hooks.d.ts +27 -0
- package/dist/src/index.d.ts +14 -0
- package/dist/src/init.d.ts +2 -0
- package/dist/src/integrations/next-js.d.ts +15 -0
- package/dist/src/integrations/node.d.ts +6 -0
- package/dist/src/integrations/react-start.d.ts +9 -0
- package/dist/src/oauth2/index.d.ts +4 -0
- package/dist/src/oauth2/link-account.d.ts +41 -0
- package/dist/src/oauth2/state.d.ts +21 -0
- package/dist/src/oauth2/utils.d.ts +3 -0
- package/dist/src/plugins/access/access.d.ts +25 -0
- package/dist/src/plugins/access/index.d.ts +2 -0
- package/dist/src/plugins/access/types.d.ts +14 -0
- package/dist/src/plugins/additional-fields/client.d.ts +91 -0
- package/dist/src/plugins/admin/access/index.d.ts +1 -0
- package/dist/src/plugins/admin/access/statement.d.ts +110 -0
- package/dist/src/plugins/admin/admin.d.ts +1570 -0
- package/dist/src/plugins/admin/client.d.ts +62 -0
- package/dist/src/plugins/admin/error-codes.d.ts +21 -0
- package/dist/src/plugins/admin/has-permission.d.ts +21 -0
- package/dist/src/plugins/admin/index.d.ts +2 -0
- package/dist/src/plugins/admin/schema.d.ts +36 -0
- package/dist/src/plugins/admin/types.d.ts +77 -0
- package/dist/src/plugins/anonymous/client.d.ts +8 -0
- package/dist/src/plugins/anonymous/index.d.ts +159 -0
- package/dist/src/plugins/api-key/client.d.ts +11 -0
- package/dist/src/plugins/api-key/index.d.ts +1431 -0
- package/dist/src/plugins/api-key/rate-limit.d.ts +20 -0
- package/dist/src/plugins/api-key/routes/create-api-key.d.ts +244 -0
- package/dist/src/plugins/api-key/routes/delete-all-expired-api-keys.d.ts +45 -0
- package/dist/src/plugins/api-key/routes/delete-api-key.d.ts +112 -0
- package/dist/src/plugins/api-key/routes/get-api-key.d.ts +234 -0
- package/dist/src/plugins/api-key/routes/index.d.ts +1136 -0
- package/dist/src/plugins/api-key/routes/list-api-keys.d.ts +231 -0
- package/dist/src/plugins/api-key/routes/update-api-key.d.ts +235 -0
- package/dist/src/plugins/api-key/routes/verify-api-key.d.ts +80 -0
- package/dist/src/plugins/api-key/schema.d.ts +188 -0
- package/dist/src/plugins/api-key/types.d.ts +285 -0
- package/dist/src/plugins/bearer/index.d.ts +31 -0
- package/dist/src/plugins/captcha/constants.d.ts +9 -0
- package/dist/src/plugins/captcha/error-codes.d.ts +9 -0
- package/dist/src/plugins/captcha/index.d.ts +7 -0
- package/dist/src/plugins/captcha/types.d.ts +23 -0
- package/dist/src/plugins/captcha/utils.d.ts +1 -0
- package/dist/src/plugins/captcha/verify-handlers/captchafox.d.ts +11 -0
- package/dist/src/plugins/captcha/verify-handlers/cloudflare-turnstile.d.ts +10 -0
- package/dist/src/plugins/captcha/verify-handlers/google-recaptcha.d.ts +11 -0
- package/dist/src/plugins/captcha/verify-handlers/h-captcha.d.ts +11 -0
- package/dist/src/plugins/captcha/verify-handlers/index.d.ts +4 -0
- package/dist/src/plugins/custom-session/client.d.ts +12 -0
- package/dist/src/plugins/custom-session/index.d.ts +89 -0
- package/dist/src/plugins/device-authorization/client.d.ts +12 -0
- package/dist/src/plugins/device-authorization/index.d.ts +568 -0
- package/dist/src/plugins/device-authorization/schema.d.ts +56 -0
- package/dist/src/plugins/email-otp/client.d.ts +9 -0
- package/dist/src/plugins/email-otp/index.d.ts +826 -0
- package/dist/src/plugins/email-otp/utils.d.ts +2 -0
- package/dist/src/plugins/generic-oauth/client.d.ts +5 -0
- package/dist/src/plugins/generic-oauth/index.d.ts +428 -0
- package/dist/src/plugins/haveibeenpwned/index.d.ts +25 -0
- package/dist/src/plugins/index.d.ts +28 -0
- package/dist/src/plugins/jwt/adapter.d.ts +8 -0
- package/dist/src/plugins/jwt/client.d.ts +5 -0
- package/dist/src/plugins/jwt/index.d.ts +276 -0
- package/dist/src/plugins/jwt/schema.d.ts +18 -0
- package/dist/src/plugins/jwt/sign.d.ts +8 -0
- package/dist/src/plugins/jwt/types.d.ts +175 -0
- package/dist/src/plugins/jwt/utils.d.ts +46 -0
- package/dist/src/plugins/last-login-method/client.d.ts +34 -0
- package/dist/src/plugins/last-login-method/index.d.ts +103 -0
- package/dist/src/plugins/magic-link/client.d.ts +5 -0
- package/dist/src/plugins/magic-link/index.d.ts +253 -0
- package/dist/src/plugins/magic-link/utils.d.ts +1 -0
- package/dist/src/plugins/multi-session/client.d.ts +9 -0
- package/dist/src/plugins/multi-session/index.d.ts +284 -0
- package/dist/src/plugins/oauth-proxy/index.d.ts +119 -0
- package/dist/src/plugins/one-tap/client.d.ts +81 -0
- package/dist/src/plugins/one-tap/index.d.ts +114 -0
- package/dist/src/plugins/one-time-token/client.d.ts +5 -0
- package/dist/src/plugins/one-time-token/index.d.ts +170 -0
- package/dist/src/plugins/one-time-token/utils.d.ts +1 -0
- package/dist/src/plugins/organization/access/index.d.ts +1 -0
- package/dist/src/plugins/organization/access/statement.d.ts +241 -0
- package/dist/src/plugins/organization/adapter.d.ts +685 -0
- package/dist/src/plugins/organization/call.d.ts +55 -0
- package/dist/src/plugins/organization/client.d.ts +344 -0
- package/dist/src/plugins/organization/error-codes.d.ts +58 -0
- package/dist/src/plugins/organization/has-permission.d.ts +13 -0
- package/dist/src/plugins/organization/index.d.ts +4 -0
- package/dist/src/plugins/organization/organization.d.ts +412 -0
- package/dist/src/plugins/organization/permission.d.ts +27 -0
- package/dist/src/plugins/organization/routes/crud-access-control.d.ts +701 -0
- package/dist/src/plugins/organization/routes/crud-invites.d.ts +1522 -0
- package/dist/src/plugins/organization/routes/crud-members.d.ts +1220 -0
- package/dist/src/plugins/organization/routes/crud-org.d.ts +1399 -0
- package/dist/src/plugins/organization/routes/crud-team.d.ts +1323 -0
- package/dist/src/plugins/organization/schema.d.ts +366 -0
- package/dist/src/plugins/organization/types.d.ts +737 -0
- package/dist/src/plugins/passkey/client.d.ts +190 -0
- package/dist/src/plugins/passkey/error-codes.d.ts +9 -0
- package/dist/src/plugins/passkey/index.d.ts +838 -0
- package/dist/src/plugins/passkey/schema.d.ts +50 -0
- package/dist/src/plugins/passkey/types.d.ts +69 -0
- package/dist/src/plugins/passkey/utils.d.ts +2 -0
- package/dist/src/plugins/phone-number/client.d.ts +9 -0
- package/dist/src/plugins/phone-number/index.d.ts +622 -0
- package/dist/src/plugins/phone-number/phone-number-error.d.ts +10 -0
- package/dist/src/plugins/two-factor/backup-codes/index.d.ts +387 -0
- package/dist/src/plugins/two-factor/client.d.ts +28 -0
- package/dist/src/plugins/two-factor/constant.d.ts +2 -0
- package/dist/src/plugins/two-factor/error-code.d.ts +11 -0
- package/dist/src/plugins/two-factor/index.d.ts +1014 -0
- package/dist/src/plugins/two-factor/otp/index.d.ts +282 -0
- package/dist/src/plugins/two-factor/schema.d.ts +35 -0
- package/dist/src/plugins/two-factor/totp/index.d.ts +298 -0
- package/dist/src/plugins/two-factor/types.d.ts +50 -0
- package/dist/src/plugins/two-factor/utils.d.ts +1 -0
- package/dist/src/plugins/two-factor/verify-two-factor.d.ts +59 -0
- package/dist/src/plugins/username/client.d.ts +5 -0
- package/dist/src/plugins/username/error-codes.d.ts +10 -0
- package/dist/src/plugins/username/index.d.ts +313 -0
- package/dist/src/plugins/username/schema.d.ts +27 -0
- package/dist/src/social-providers/index.d.ts +1 -0
- package/dist/src/test-utils/headers.d.ts +5 -0
- package/dist/src/test-utils/index.d.ts +2 -0
- package/dist/src/test-utils/test-instance.d.ts +17849 -0
- package/dist/src/types/adapter.d.ts +21 -0
- package/dist/src/types/api.d.ts +29 -0
- package/dist/src/types/helper.d.ts +32 -0
- package/dist/src/types/index.d.ts +7 -0
- package/dist/src/types/models.d.ts +13 -0
- package/dist/src/types/plugins.d.ts +14 -0
- package/dist/src/utils/await-object.d.ts +3 -0
- package/dist/src/utils/boolean.d.ts +1 -0
- package/dist/src/utils/clone.d.ts +1 -0
- package/dist/src/utils/constants.d.ts +1 -0
- package/dist/src/utils/date.d.ts +1 -0
- package/dist/src/utils/ensure-utc.d.ts +1 -0
- package/dist/src/utils/get-request-ip.d.ts +2 -0
- package/dist/src/utils/hashing.d.ts +6 -0
- package/dist/src/utils/hide-metadata.d.ts +3 -0
- package/dist/src/utils/id.d.ts +1 -0
- package/dist/src/utils/import-util.d.ts +1 -0
- package/dist/src/utils/index.d.ts +5 -0
- package/dist/src/utils/is-atom.d.ts +2 -0
- package/dist/src/utils/is-promise.d.ts +1 -0
- package/dist/src/utils/json.d.ts +1 -0
- package/dist/src/utils/merger.d.ts +1 -0
- package/dist/src/utils/middleware-response.d.ts +8 -0
- package/dist/src/utils/misc.d.ts +1 -0
- package/dist/src/utils/password.d.ts +6 -0
- package/dist/src/utils/plugin-helper.d.ts +5 -0
- package/dist/src/utils/shim.d.ts +3 -0
- package/dist/src/utils/time.d.ts +4 -0
- package/dist/src/utils/url.d.ts +4 -0
- package/dist/src/utils/wildcard.d.ts +45 -0
- package/dist/test-utils/index.d.mts +17870 -0
- package/dist/test-utils/index.mjs +272 -0
- package/dist/two-factor-ClUXxom2.mjs +914 -0
- package/dist/types/index.d.mts +6 -0
- package/dist/types/index.mjs +3 -0
- package/dist/types-B1OL7hyf.d.mts +4 -0
- package/dist/types-Bjn15Uy6.mjs +1 -0
- package/dist/url-VB2gAbTI.mjs +59 -0
- package/dist/username-DiGklOGl.mjs +278 -0
- package/dist/utils-SOMB4Px5.mjs +132 -0
- package/package.json +447 -0
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import "../helper-tmxW3BHj.mjs";
|
|
2
|
+
import { A as Where, B as InferPluginsFromClient, C as AdapterInstance, D as DBAdapterSchemaCreation, E as DBAdapterInstance, F as ClientStore, G as PayvoAuthClientPlugin, H as InferUserFromClient, I as InferActions, K as SessionQueryParams, L as InferAdditionalFromClient, M as AtomListener, N as ClientAtomListener, O as DBTransactionAdapter, P as ClientOptions, R as InferClientAPI, S as Adapter, T as DBAdapter, U as IsSignal, V as InferSessionFromClient, W as PayvoAuthClientOptions, _ as Verification, a as PayvoAuthRateLimitOptions, b as InferAPI, c as AdditionalSessionFieldsOutput, d as InferPluginTypes, f as InferSession, g as User, h as Session, i as PayvoAuthPlugin, j as init, k as TransactionAdapter, l as AdditionalUserFieldsInput, m as RateLimit, n as PayvoAuthCookies, o as Account, p as InferUser, q as Store, r as PayvoAuthOptions, s as AdditionalSessionFieldsInput, t as PayvoAuthAdvancedOptions, u as AdditionalUserFieldsOutput, v as FilterActions, w as AdapterSchemaCreation, x as InferSessionAPI, y as FilteredAPI, z as InferErrorCodes } from "../index-Cxi7TbLE.mjs";
|
|
3
|
+
import "../types-B1OL7hyf.mjs";
|
|
4
|
+
import "../index-65G5U5DB-DSdjzreF.mjs";
|
|
5
|
+
import { n as InferPluginErrorCodes, t as InferOptionSchema } from "../plugins-hFZT3hmK.mjs";
|
|
6
|
+
export { Account, Adapter, AdapterInstance, AdapterSchemaCreation, AdditionalSessionFieldsInput, AdditionalSessionFieldsOutput, AdditionalUserFieldsInput, AdditionalUserFieldsOutput, AtomListener, ClientAtomListener, ClientOptions, ClientStore, DBAdapter, DBAdapterInstance, DBAdapterSchemaCreation, DBTransactionAdapter, FilterActions, FilteredAPI, InferAPI, InferActions, InferAdditionalFromClient, InferClientAPI, InferErrorCodes, InferOptionSchema, InferPluginErrorCodes, InferPluginTypes, InferPluginsFromClient, InferSession, InferSessionAPI, InferSessionFromClient, InferUser, InferUserFromClient, IsSignal, PayvoAuthAdvancedOptions, PayvoAuthClientOptions, PayvoAuthClientPlugin, PayvoAuthCookies, PayvoAuthOptions, PayvoAuthPlugin, PayvoAuthRateLimitOptions, RateLimit, Session, SessionQueryParams, Store, TransactionAdapter, User, Verification, Where, init };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { };
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { env } from "@gatwech/core/env";
|
|
2
|
+
import { PayvoAuthError } from "@gatwech/core/error";
|
|
3
|
+
|
|
4
|
+
//#region src/utils/url.ts
|
|
5
|
+
function checkHasPath(url) {
|
|
6
|
+
try {
|
|
7
|
+
return (new URL(url).pathname.replace(/\/+$/, "") || "/") !== "/";
|
|
8
|
+
} catch (error) {
|
|
9
|
+
throw new PayvoAuthError(`Invalid base URL: ${url}. Please provide a valid base URL.`);
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
function withPath(url, path = "/api/auth") {
|
|
13
|
+
if (checkHasPath(url)) return url;
|
|
14
|
+
const trimmedUrl = url.replace(/\/+$/, "");
|
|
15
|
+
if (!path || path === "/") return trimmedUrl;
|
|
16
|
+
path = path.startsWith("/") ? path : `/${path}`;
|
|
17
|
+
return `${trimmedUrl}${path}`;
|
|
18
|
+
}
|
|
19
|
+
function getBaseURL(url, path, request, loadEnv) {
|
|
20
|
+
if (url) return withPath(url, path);
|
|
21
|
+
if (loadEnv !== false) {
|
|
22
|
+
const fromEnv = env.PAYVO_AUTH_URL || env.NEXT_PUBLIC_PAYVO_AUTH_URL || env.PUBLIC_PAYVO_AUTH_URL || env.NUXT_PUBLIC_PAYVO_AUTH_URL || env.NUXT_PUBLIC_AUTH_URL || (env.BASE_URL !== "/" ? env.BASE_URL : void 0);
|
|
23
|
+
if (fromEnv) return withPath(fromEnv, path);
|
|
24
|
+
}
|
|
25
|
+
const fromRequest = request?.headers.get("x-forwarded-host");
|
|
26
|
+
const fromRequestProto = request?.headers.get("x-forwarded-proto");
|
|
27
|
+
if (fromRequest && fromRequestProto) return withPath(`${fromRequestProto}://${fromRequest}`, path);
|
|
28
|
+
if (request) {
|
|
29
|
+
const url$1 = getOrigin(request.url);
|
|
30
|
+
if (!url$1) throw new PayvoAuthError("Could not get origin from request. Please provide a valid base URL.");
|
|
31
|
+
return withPath(url$1, path);
|
|
32
|
+
}
|
|
33
|
+
if (typeof window !== "undefined" && window.location) return withPath(window.location.origin, path);
|
|
34
|
+
}
|
|
35
|
+
function getOrigin(url) {
|
|
36
|
+
try {
|
|
37
|
+
const parsedUrl = new URL(url);
|
|
38
|
+
return parsedUrl.origin === "null" ? null : parsedUrl.origin;
|
|
39
|
+
} catch (error) {
|
|
40
|
+
return null;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
function getProtocol(url) {
|
|
44
|
+
try {
|
|
45
|
+
return new URL(url).protocol;
|
|
46
|
+
} catch (error) {
|
|
47
|
+
return null;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
function getHost(url) {
|
|
51
|
+
try {
|
|
52
|
+
return new URL(url).host;
|
|
53
|
+
} catch (error) {
|
|
54
|
+
return null;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
//#endregion
|
|
59
|
+
export { getProtocol as i, getHost as n, getOrigin as r, getBaseURL as t };
|
|
@@ -0,0 +1,278 @@
|
|
|
1
|
+
import { C as createEmailVerificationToken } from "./api-0pR_I-Nx.mjs";
|
|
2
|
+
import { c as setSessionCookie } from "./cookies-cJObLwn1.mjs";
|
|
3
|
+
import { n as mergeSchema } from "./date-Cx2yCiC4.mjs";
|
|
4
|
+
import { BASE_ERROR_CODES } from "@gatwech/core/error";
|
|
5
|
+
import { defineErrorCodes } from "@gatwech/core/utils";
|
|
6
|
+
import { APIError } from "better-call";
|
|
7
|
+
import { createAuthEndpoint, createAuthMiddleware } from "@gatwech/core/api";
|
|
8
|
+
import * as z$1 from "zod";
|
|
9
|
+
|
|
10
|
+
//#region src/plugins/username/error-codes.ts
|
|
11
|
+
const USERNAME_ERROR_CODES = defineErrorCodes({
|
|
12
|
+
INVALID_USERNAME_OR_PASSWORD: "Invalid username or password",
|
|
13
|
+
EMAIL_NOT_VERIFIED: "Email not verified",
|
|
14
|
+
UNEXPECTED_ERROR: "Unexpected error",
|
|
15
|
+
USERNAME_IS_ALREADY_TAKEN: "Username is already taken. Please try another.",
|
|
16
|
+
USERNAME_TOO_SHORT: "Username is too short",
|
|
17
|
+
USERNAME_TOO_LONG: "Username is too long",
|
|
18
|
+
INVALID_USERNAME: "Username is invalid",
|
|
19
|
+
INVALID_DISPLAY_USERNAME: "Display username is invalid"
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
//#endregion
|
|
23
|
+
//#region src/plugins/username/schema.ts
|
|
24
|
+
const getSchema = (normalizer) => {
|
|
25
|
+
return { user: { fields: {
|
|
26
|
+
username: {
|
|
27
|
+
type: "string",
|
|
28
|
+
required: false,
|
|
29
|
+
sortable: true,
|
|
30
|
+
unique: true,
|
|
31
|
+
returned: true,
|
|
32
|
+
transform: { input(value) {
|
|
33
|
+
return typeof value !== "string" ? value : normalizer.username(value);
|
|
34
|
+
} }
|
|
35
|
+
},
|
|
36
|
+
displayUsername: {
|
|
37
|
+
type: "string",
|
|
38
|
+
required: false,
|
|
39
|
+
transform: { input(value) {
|
|
40
|
+
return typeof value !== "string" ? value : normalizer.displayUsername(value);
|
|
41
|
+
} }
|
|
42
|
+
}
|
|
43
|
+
} } };
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
//#endregion
|
|
47
|
+
//#region src/plugins/username/index.ts
|
|
48
|
+
function defaultUsernameValidator(username$1) {
|
|
49
|
+
return /^[a-zA-Z0-9_.]+$/.test(username$1);
|
|
50
|
+
}
|
|
51
|
+
const username = (options) => {
|
|
52
|
+
const normalizer = (username$1) => {
|
|
53
|
+
if (options?.usernameNormalization === false) return username$1;
|
|
54
|
+
if (options?.usernameNormalization) return options.usernameNormalization(username$1);
|
|
55
|
+
return username$1.toLowerCase();
|
|
56
|
+
};
|
|
57
|
+
const displayUsernameNormalizer = (displayUsername) => {
|
|
58
|
+
return options?.displayUsernameNormalization ? options.displayUsernameNormalization(displayUsername) : displayUsername;
|
|
59
|
+
};
|
|
60
|
+
return {
|
|
61
|
+
id: "username",
|
|
62
|
+
init(ctx) {
|
|
63
|
+
return { options: { databaseHooks: { user: {
|
|
64
|
+
create: { async before(user, context) {
|
|
65
|
+
const username$1 = "username" in user ? user.username : null;
|
|
66
|
+
const displayUsername = "displayUsername" in user ? user.displayUsername : null;
|
|
67
|
+
return { data: {
|
|
68
|
+
...user,
|
|
69
|
+
...username$1 ? { username: normalizer(username$1) } : {},
|
|
70
|
+
...displayUsername ? { displayUsername: displayUsernameNormalizer(displayUsername) } : {}
|
|
71
|
+
} };
|
|
72
|
+
} },
|
|
73
|
+
update: { async before(user, context) {
|
|
74
|
+
const username$1 = "username" in user ? user.username : null;
|
|
75
|
+
const displayUsername = "displayUsername" in user ? user.displayUsername : null;
|
|
76
|
+
return { data: {
|
|
77
|
+
...user,
|
|
78
|
+
...username$1 ? { username: normalizer(username$1) } : {},
|
|
79
|
+
...displayUsername ? { displayUsername: displayUsernameNormalizer(displayUsername) } : {}
|
|
80
|
+
} };
|
|
81
|
+
} }
|
|
82
|
+
} } } };
|
|
83
|
+
},
|
|
84
|
+
endpoints: {
|
|
85
|
+
signInUsername: createAuthEndpoint("/sign-in/username", {
|
|
86
|
+
method: "POST",
|
|
87
|
+
body: z$1.object({
|
|
88
|
+
username: z$1.string().meta({ description: "The username of the user" }),
|
|
89
|
+
password: z$1.string().meta({ description: "The password of the user" }),
|
|
90
|
+
rememberMe: z$1.boolean().meta({ description: "Remember the user session" }).optional(),
|
|
91
|
+
callbackURL: z$1.string().meta({ description: "The URL to redirect to after email verification" }).optional()
|
|
92
|
+
}),
|
|
93
|
+
metadata: { openapi: {
|
|
94
|
+
summary: "Sign in with username",
|
|
95
|
+
description: "Sign in with username",
|
|
96
|
+
responses: {
|
|
97
|
+
200: {
|
|
98
|
+
description: "Success",
|
|
99
|
+
content: { "application/json": { schema: {
|
|
100
|
+
type: "object",
|
|
101
|
+
properties: {
|
|
102
|
+
token: {
|
|
103
|
+
type: "string",
|
|
104
|
+
description: "Session token for the authenticated session"
|
|
105
|
+
},
|
|
106
|
+
user: { $ref: "#/components/schemas/User" }
|
|
107
|
+
},
|
|
108
|
+
required: ["token", "user"]
|
|
109
|
+
} } }
|
|
110
|
+
},
|
|
111
|
+
422: {
|
|
112
|
+
description: "Unprocessable Entity. Validation error",
|
|
113
|
+
content: { "application/json": { schema: {
|
|
114
|
+
type: "object",
|
|
115
|
+
properties: { message: { type: "string" } }
|
|
116
|
+
} } }
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
} }
|
|
120
|
+
}, async (ctx) => {
|
|
121
|
+
if (!ctx.body.username || !ctx.body.password) {
|
|
122
|
+
ctx.context.logger.error("Username or password not found");
|
|
123
|
+
throw new APIError("UNAUTHORIZED", { message: USERNAME_ERROR_CODES.INVALID_USERNAME_OR_PASSWORD });
|
|
124
|
+
}
|
|
125
|
+
const username$1 = options?.validationOrder?.username === "pre-normalization" ? normalizer(ctx.body.username) : ctx.body.username;
|
|
126
|
+
const minUsernameLength = options?.minUsernameLength || 3;
|
|
127
|
+
const maxUsernameLength = options?.maxUsernameLength || 30;
|
|
128
|
+
if (username$1.length < minUsernameLength) {
|
|
129
|
+
ctx.context.logger.error("Username too short", { username: username$1 });
|
|
130
|
+
throw new APIError("UNPROCESSABLE_ENTITY", { message: USERNAME_ERROR_CODES.USERNAME_TOO_SHORT });
|
|
131
|
+
}
|
|
132
|
+
if (username$1.length > maxUsernameLength) {
|
|
133
|
+
ctx.context.logger.error("Username too long", { username: username$1 });
|
|
134
|
+
throw new APIError("UNPROCESSABLE_ENTITY", { message: USERNAME_ERROR_CODES.USERNAME_TOO_LONG });
|
|
135
|
+
}
|
|
136
|
+
if (!(options?.usernameValidator || defaultUsernameValidator)(username$1)) throw new APIError("UNPROCESSABLE_ENTITY", { message: USERNAME_ERROR_CODES.INVALID_USERNAME });
|
|
137
|
+
const user = await ctx.context.adapter.findOne({
|
|
138
|
+
model: "user",
|
|
139
|
+
where: [{
|
|
140
|
+
field: "username",
|
|
141
|
+
value: normalizer(username$1)
|
|
142
|
+
}]
|
|
143
|
+
});
|
|
144
|
+
if (!user) {
|
|
145
|
+
await ctx.context.password.hash(ctx.body.password);
|
|
146
|
+
ctx.context.logger.error("User not found", { username: username$1 });
|
|
147
|
+
throw new APIError("UNAUTHORIZED", { message: USERNAME_ERROR_CODES.INVALID_USERNAME_OR_PASSWORD });
|
|
148
|
+
}
|
|
149
|
+
const account = await ctx.context.adapter.findOne({
|
|
150
|
+
model: "account",
|
|
151
|
+
where: [{
|
|
152
|
+
field: "userId",
|
|
153
|
+
value: user.id
|
|
154
|
+
}, {
|
|
155
|
+
field: "providerId",
|
|
156
|
+
value: "credential"
|
|
157
|
+
}]
|
|
158
|
+
});
|
|
159
|
+
if (!account) throw new APIError("UNAUTHORIZED", { message: USERNAME_ERROR_CODES.INVALID_USERNAME_OR_PASSWORD });
|
|
160
|
+
const currentPassword = account?.password;
|
|
161
|
+
if (!currentPassword) {
|
|
162
|
+
ctx.context.logger.error("Password not found", { username: username$1 });
|
|
163
|
+
throw new APIError("UNAUTHORIZED", { message: USERNAME_ERROR_CODES.INVALID_USERNAME_OR_PASSWORD });
|
|
164
|
+
}
|
|
165
|
+
if (!await ctx.context.password.verify({
|
|
166
|
+
hash: currentPassword,
|
|
167
|
+
password: ctx.body.password
|
|
168
|
+
})) {
|
|
169
|
+
ctx.context.logger.error("Invalid password");
|
|
170
|
+
throw new APIError("UNAUTHORIZED", { message: USERNAME_ERROR_CODES.INVALID_USERNAME_OR_PASSWORD });
|
|
171
|
+
}
|
|
172
|
+
if (ctx.context.options?.emailAndPassword?.requireEmailVerification && !user.emailVerified) {
|
|
173
|
+
if (!ctx.context.options?.emailVerification?.sendVerificationEmail) throw new APIError("FORBIDDEN", { message: USERNAME_ERROR_CODES.EMAIL_NOT_VERIFIED });
|
|
174
|
+
if (ctx.context.options?.emailVerification?.sendOnSignIn) {
|
|
175
|
+
const token = await createEmailVerificationToken(ctx.context.secret, user.email, void 0, ctx.context.options.emailVerification?.expiresIn);
|
|
176
|
+
const url = `${ctx.context.baseURL}/verify-email?token=${token}&callbackURL=${ctx.body.callbackURL || "/"}`;
|
|
177
|
+
await ctx.context.options.emailVerification.sendVerificationEmail({
|
|
178
|
+
user,
|
|
179
|
+
url,
|
|
180
|
+
token
|
|
181
|
+
}, ctx.request);
|
|
182
|
+
}
|
|
183
|
+
throw new APIError("FORBIDDEN", { message: USERNAME_ERROR_CODES.EMAIL_NOT_VERIFIED });
|
|
184
|
+
}
|
|
185
|
+
const session = await ctx.context.internalAdapter.createSession(user.id, ctx.body.rememberMe === false);
|
|
186
|
+
if (!session) return ctx.json(null, {
|
|
187
|
+
status: 500,
|
|
188
|
+
body: { message: BASE_ERROR_CODES.FAILED_TO_CREATE_SESSION }
|
|
189
|
+
});
|
|
190
|
+
await setSessionCookie(ctx, {
|
|
191
|
+
session,
|
|
192
|
+
user
|
|
193
|
+
}, ctx.body.rememberMe === false);
|
|
194
|
+
return ctx.json({
|
|
195
|
+
token: session.token,
|
|
196
|
+
user: {
|
|
197
|
+
id: user.id,
|
|
198
|
+
email: user.email,
|
|
199
|
+
emailVerified: user.emailVerified,
|
|
200
|
+
username: user.username,
|
|
201
|
+
displayUsername: user.displayUsername,
|
|
202
|
+
name: user.name,
|
|
203
|
+
image: user.image,
|
|
204
|
+
createdAt: user.createdAt,
|
|
205
|
+
updatedAt: user.updatedAt
|
|
206
|
+
}
|
|
207
|
+
});
|
|
208
|
+
}),
|
|
209
|
+
isUsernameAvailable: createAuthEndpoint("/is-username-available", {
|
|
210
|
+
method: "POST",
|
|
211
|
+
body: z$1.object({ username: z$1.string().meta({ description: "The username to check" }) })
|
|
212
|
+
}, async (ctx) => {
|
|
213
|
+
const username$1 = ctx.body.username;
|
|
214
|
+
if (!username$1) throw new APIError("UNPROCESSABLE_ENTITY", { message: USERNAME_ERROR_CODES.INVALID_USERNAME });
|
|
215
|
+
const minUsernameLength = options?.minUsernameLength || 3;
|
|
216
|
+
const maxUsernameLength = options?.maxUsernameLength || 30;
|
|
217
|
+
if (username$1.length < minUsernameLength) throw new APIError("UNPROCESSABLE_ENTITY", { message: USERNAME_ERROR_CODES.USERNAME_TOO_SHORT });
|
|
218
|
+
if (username$1.length > maxUsernameLength) throw new APIError("UNPROCESSABLE_ENTITY", { message: USERNAME_ERROR_CODES.USERNAME_TOO_LONG });
|
|
219
|
+
if (!await (options?.usernameValidator || defaultUsernameValidator)(username$1)) throw new APIError("UNPROCESSABLE_ENTITY", { message: USERNAME_ERROR_CODES.INVALID_USERNAME });
|
|
220
|
+
if (await ctx.context.adapter.findOne({
|
|
221
|
+
model: "user",
|
|
222
|
+
where: [{
|
|
223
|
+
field: "username",
|
|
224
|
+
value: normalizer(username$1)
|
|
225
|
+
}]
|
|
226
|
+
})) return ctx.json({ available: false });
|
|
227
|
+
return ctx.json({ available: true });
|
|
228
|
+
})
|
|
229
|
+
},
|
|
230
|
+
schema: mergeSchema(getSchema({
|
|
231
|
+
username: normalizer,
|
|
232
|
+
displayUsername: displayUsernameNormalizer
|
|
233
|
+
}), options?.schema),
|
|
234
|
+
hooks: { before: [{
|
|
235
|
+
matcher(context) {
|
|
236
|
+
return context.path === "/sign-up/email" || context.path === "/update-user";
|
|
237
|
+
},
|
|
238
|
+
handler: createAuthMiddleware(async (ctx) => {
|
|
239
|
+
const username$1 = typeof ctx.body.username === "string" && options?.validationOrder?.username === "post-normalization" ? normalizer(ctx.body.username) : ctx.body.username;
|
|
240
|
+
if (username$1 !== void 0 && typeof username$1 === "string") {
|
|
241
|
+
const minUsernameLength = options?.minUsernameLength || 3;
|
|
242
|
+
const maxUsernameLength = options?.maxUsernameLength || 30;
|
|
243
|
+
if (username$1.length < minUsernameLength) throw new APIError("BAD_REQUEST", { message: USERNAME_ERROR_CODES.USERNAME_TOO_SHORT });
|
|
244
|
+
if (username$1.length > maxUsernameLength) throw new APIError("BAD_REQUEST", { message: USERNAME_ERROR_CODES.USERNAME_TOO_LONG });
|
|
245
|
+
if (!await (options?.usernameValidator || defaultUsernameValidator)(username$1)) throw new APIError("BAD_REQUEST", { message: USERNAME_ERROR_CODES.INVALID_USERNAME });
|
|
246
|
+
const user = await ctx.context.adapter.findOne({
|
|
247
|
+
model: "user",
|
|
248
|
+
where: [{
|
|
249
|
+
field: "username",
|
|
250
|
+
value: username$1
|
|
251
|
+
}]
|
|
252
|
+
});
|
|
253
|
+
const blockChangeSignUp = ctx.path === "/sign-up/email" && user;
|
|
254
|
+
const blockChangeUpdateUser = ctx.path === "/update-user" && user && ctx.context.session && user.id !== ctx.context.session.session.userId;
|
|
255
|
+
if (blockChangeSignUp || blockChangeUpdateUser) throw new APIError("BAD_REQUEST", { message: USERNAME_ERROR_CODES.USERNAME_IS_ALREADY_TAKEN });
|
|
256
|
+
}
|
|
257
|
+
const displayUsername = typeof ctx.body.displayUsername === "string" && options?.validationOrder?.displayUsername === "post-normalization" ? displayUsernameNormalizer(ctx.body.displayUsername) : ctx.body.displayUsername;
|
|
258
|
+
if (displayUsername !== void 0 && typeof displayUsername === "string") {
|
|
259
|
+
if (options?.displayUsernameValidator) {
|
|
260
|
+
if (!await options.displayUsernameValidator(displayUsername)) throw new APIError("BAD_REQUEST", { message: USERNAME_ERROR_CODES.INVALID_DISPLAY_USERNAME });
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
})
|
|
264
|
+
}, {
|
|
265
|
+
matcher(context) {
|
|
266
|
+
return context.path === "/sign-up/email" || context.path === "/update-user";
|
|
267
|
+
},
|
|
268
|
+
handler: createAuthMiddleware(async (ctx) => {
|
|
269
|
+
if (ctx.body.username && !ctx.body.displayUsername) ctx.body.displayUsername = ctx.body.username;
|
|
270
|
+
if (ctx.body.displayUsername && !ctx.body.username) ctx.body.username = ctx.body.displayUsername;
|
|
271
|
+
})
|
|
272
|
+
}] },
|
|
273
|
+
$ERROR_CODES: USERNAME_ERROR_CODES
|
|
274
|
+
};
|
|
275
|
+
};
|
|
276
|
+
|
|
277
|
+
//#endregion
|
|
278
|
+
export { USERNAME_ERROR_CODES as n, username as t };
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
import { n as symmetricEncrypt, r as generateRandomString, t as symmetricDecrypt } from "./crypto-Bb42eMrH.mjs";
|
|
2
|
+
import { defineRequestState } from "@gatwech/core/context";
|
|
3
|
+
import { APIError } from "better-call";
|
|
4
|
+
import * as z$1 from "zod";
|
|
5
|
+
import { createRandomStringGenerator } from "@gatwech/utils/random";
|
|
6
|
+
|
|
7
|
+
//#region src/api/middlewares/oauth.ts
|
|
8
|
+
const { get: getOAuthState, set: setOAuthState } = defineRequestState();
|
|
9
|
+
|
|
10
|
+
//#endregion
|
|
11
|
+
//#region src/oauth2/state.ts
|
|
12
|
+
async function generateState(c, link, additionalData) {
|
|
13
|
+
const callbackURL = c.body?.callbackURL || c.context.options.baseURL;
|
|
14
|
+
if (!callbackURL) throw new APIError("BAD_REQUEST", { message: "callbackURL is required" });
|
|
15
|
+
const codeVerifier = generateRandomString(128);
|
|
16
|
+
const state = generateRandomString(32);
|
|
17
|
+
const storeStateStrategy = c.context.oauthConfig?.storeStateStrategy || "cookie";
|
|
18
|
+
const stateData = {
|
|
19
|
+
...additionalData ? additionalData : {},
|
|
20
|
+
callbackURL,
|
|
21
|
+
codeVerifier,
|
|
22
|
+
errorURL: c.body?.errorCallbackURL,
|
|
23
|
+
newUserURL: c.body?.newUserCallbackURL,
|
|
24
|
+
link,
|
|
25
|
+
expiresAt: Date.now() + 600 * 1e3,
|
|
26
|
+
requestSignUp: c.body?.requestSignUp
|
|
27
|
+
};
|
|
28
|
+
await setOAuthState(stateData);
|
|
29
|
+
if (storeStateStrategy === "cookie") {
|
|
30
|
+
const encryptedData = await symmetricEncrypt({
|
|
31
|
+
key: c.context.secret,
|
|
32
|
+
data: JSON.stringify(stateData)
|
|
33
|
+
});
|
|
34
|
+
const stateCookie$1 = c.context.createAuthCookie("oauth_state", { maxAge: 600 * 1e3 });
|
|
35
|
+
c.setCookie(stateCookie$1.name, encryptedData, stateCookie$1.attributes);
|
|
36
|
+
return {
|
|
37
|
+
state,
|
|
38
|
+
codeVerifier
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
const stateCookie = c.context.createAuthCookie("state", { maxAge: 300 * 1e3 });
|
|
42
|
+
await c.setSignedCookie(stateCookie.name, state, c.context.secret, stateCookie.attributes);
|
|
43
|
+
const expiresAt = /* @__PURE__ */ new Date();
|
|
44
|
+
expiresAt.setMinutes(expiresAt.getMinutes() + 10);
|
|
45
|
+
const verification = await c.context.internalAdapter.createVerificationValue({
|
|
46
|
+
value: JSON.stringify(stateData),
|
|
47
|
+
identifier: state,
|
|
48
|
+
expiresAt
|
|
49
|
+
});
|
|
50
|
+
if (!verification) {
|
|
51
|
+
c.context.logger.error("Unable to create verification. Make sure the database adapter is properly working and there is a verification table in the database");
|
|
52
|
+
throw new APIError("INTERNAL_SERVER_ERROR", { message: "Unable to create verification" });
|
|
53
|
+
}
|
|
54
|
+
return {
|
|
55
|
+
state: verification.identifier,
|
|
56
|
+
codeVerifier
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
async function parseState(c) {
|
|
60
|
+
const state = c.query.state || c.body.state;
|
|
61
|
+
const storeStateStrategy = c.context.oauthConfig.storeStateStrategy || "cookie";
|
|
62
|
+
const stateDataSchema = z$1.object({
|
|
63
|
+
callbackURL: z$1.string(),
|
|
64
|
+
codeVerifier: z$1.string(),
|
|
65
|
+
errorURL: z$1.string().optional(),
|
|
66
|
+
newUserURL: z$1.string().optional(),
|
|
67
|
+
expiresAt: z$1.number(),
|
|
68
|
+
link: z$1.object({
|
|
69
|
+
email: z$1.string(),
|
|
70
|
+
userId: z$1.coerce.string()
|
|
71
|
+
}).optional(),
|
|
72
|
+
requestSignUp: z$1.boolean().optional()
|
|
73
|
+
}).passthrough();
|
|
74
|
+
let parsedData;
|
|
75
|
+
if (storeStateStrategy === "cookie") {
|
|
76
|
+
const stateCookie = c.context.createAuthCookie("oauth_state");
|
|
77
|
+
const encryptedData = c.getCookie(stateCookie.name);
|
|
78
|
+
if (!encryptedData) {
|
|
79
|
+
c.context.logger.error("State Mismatch. OAuth state cookie not found", { state });
|
|
80
|
+
const errorURL = c.context.options.onAPIError?.errorURL || `${c.context.baseURL}/error`;
|
|
81
|
+
throw c.redirect(`${errorURL}?error=please_restart_the_process`);
|
|
82
|
+
}
|
|
83
|
+
try {
|
|
84
|
+
const decryptedData = await symmetricDecrypt({
|
|
85
|
+
key: c.context.secret,
|
|
86
|
+
data: encryptedData
|
|
87
|
+
});
|
|
88
|
+
parsedData = stateDataSchema.parse(JSON.parse(decryptedData));
|
|
89
|
+
} catch (error) {
|
|
90
|
+
c.context.logger.error("Failed to decrypt or parse OAuth state cookie", { error });
|
|
91
|
+
const errorURL = c.context.options.onAPIError?.errorURL || `${c.context.baseURL}/error`;
|
|
92
|
+
throw c.redirect(`${errorURL}?error=please_restart_the_process`);
|
|
93
|
+
}
|
|
94
|
+
c.setCookie(stateCookie.name, "", { maxAge: 0 });
|
|
95
|
+
} else {
|
|
96
|
+
const data = await c.context.internalAdapter.findVerificationValue(state);
|
|
97
|
+
if (!data) {
|
|
98
|
+
c.context.logger.error("State Mismatch. Verification not found", { state });
|
|
99
|
+
const errorURL = c.context.options.onAPIError?.errorURL || `${c.context.baseURL}/error`;
|
|
100
|
+
throw c.redirect(`${errorURL}?error=please_restart_the_process`);
|
|
101
|
+
}
|
|
102
|
+
parsedData = stateDataSchema.parse(JSON.parse(data.value));
|
|
103
|
+
const stateCookie = c.context.createAuthCookie("state");
|
|
104
|
+
const stateCookieValue = await c.getSignedCookie(stateCookie.name, c.context.secret);
|
|
105
|
+
if (!c.context.oauthConfig?.skipStateCookieCheck && (!stateCookieValue || stateCookieValue !== state)) {
|
|
106
|
+
const errorURL = c.context.options.onAPIError?.errorURL || `${c.context.baseURL}/error`;
|
|
107
|
+
throw c.redirect(`${errorURL}?error=state_mismatch`);
|
|
108
|
+
}
|
|
109
|
+
c.setCookie(stateCookie.name, "", { maxAge: 0 });
|
|
110
|
+
await c.context.internalAdapter.deleteVerificationValue(data.id);
|
|
111
|
+
}
|
|
112
|
+
if (!parsedData.errorURL) parsedData.errorURL = c.context.options.onAPIError?.errorURL || `${c.context.baseURL}/error`;
|
|
113
|
+
if (parsedData.expiresAt < Date.now()) {
|
|
114
|
+
const errorURL = c.context.options.onAPIError?.errorURL || `${c.context.baseURL}/error`;
|
|
115
|
+
throw c.redirect(`${errorURL}?error=please_restart_the_process`);
|
|
116
|
+
}
|
|
117
|
+
if (parsedData) await setOAuthState(parsedData);
|
|
118
|
+
return parsedData;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
//#endregion
|
|
122
|
+
//#region src/utils/hide-metadata.ts
|
|
123
|
+
const HIDE_METADATA = { isAction: false };
|
|
124
|
+
|
|
125
|
+
//#endregion
|
|
126
|
+
//#region src/utils/id.ts
|
|
127
|
+
const generateId = (size) => {
|
|
128
|
+
return createRandomStringGenerator("a-z", "A-Z", "0-9")(size || 32);
|
|
129
|
+
};
|
|
130
|
+
|
|
131
|
+
//#endregion
|
|
132
|
+
export { getOAuthState as a, parseState as i, HIDE_METADATA as n, generateState as r, generateId as t };
|