better-auth 1.7.0-beta.3 → 1.7.0-beta.4
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/dist/_virtual/_rolldown/runtime.mjs +10 -1
- package/dist/api/index.d.mts +18 -46
- package/dist/api/routes/account.d.mts +4 -23
- package/dist/api/routes/account.mjs +100 -74
- package/dist/api/routes/callback.mjs +35 -15
- package/dist/api/routes/email-verification.d.mts +1 -0
- package/dist/api/routes/email-verification.mjs +4 -3
- package/dist/api/routes/password.mjs +1 -1
- package/dist/api/routes/session.mjs +15 -10
- package/dist/api/routes/sign-in.d.mts +3 -0
- package/dist/api/routes/sign-in.mjs +7 -3
- package/dist/api/routes/sign-up.d.mts +1 -0
- package/dist/api/routes/sign-up.mjs +9 -7
- package/dist/api/routes/update-user.mjs +8 -8
- package/dist/client/fetch-plugins.mjs +2 -1
- package/dist/client/index.d.mts +2 -2
- package/dist/client/parser.mjs +0 -1
- package/dist/client/plugins/index.d.mts +3 -17
- package/dist/client/plugins/index.mjs +1 -4
- package/dist/client/proxy.mjs +2 -1
- package/dist/context/create-context.mjs +10 -14
- package/dist/context/helpers.mjs +3 -2
- package/dist/cookies/cookie-utils.d.mts +24 -1
- package/dist/cookies/cookie-utils.mjs +85 -22
- package/dist/cookies/index.d.mts +2 -3
- package/dist/cookies/index.mjs +39 -11
- package/dist/cookies/session-store.mjs +4 -23
- package/dist/db/get-migration.mjs +4 -4
- package/dist/db/index.d.mts +2 -2
- package/dist/db/index.mjs +3 -2
- package/dist/db/internal-adapter.mjs +115 -21
- package/dist/db/schema.d.mts +14 -1
- package/dist/db/schema.mjs +26 -1
- package/dist/db/with-hooks.d.mts +1 -0
- package/dist/db/with-hooks.mjs +58 -1
- package/dist/index.d.mts +2 -2
- package/dist/index.mjs +2 -2
- package/dist/node_modules/.pnpm/clipboardy@4.0.0/node_modules/clipboardy/index.mjs +32 -0
- package/dist/node_modules/.pnpm/clipboardy@4.0.0/node_modules/clipboardy/lib/linux.mjs +55 -0
- package/dist/node_modules/.pnpm/clipboardy@4.0.0/node_modules/clipboardy/lib/macos.mjs +26 -0
- package/dist/node_modules/.pnpm/clipboardy@4.0.0/node_modules/clipboardy/lib/termux.mjs +39 -0
- package/dist/node_modules/.pnpm/clipboardy@4.0.0/node_modules/clipboardy/lib/windows.mjs +19 -0
- package/dist/node_modules/.pnpm/consola@3.4.2/node_modules/consola/dist/chunks/prompt.mjs +845 -0
- package/dist/node_modules/.pnpm/consola@3.4.2/node_modules/consola/dist/core.mjs +386 -0
- package/dist/node_modules/.pnpm/consola@3.4.2/node_modules/consola/dist/index.mjs +320 -0
- package/dist/node_modules/.pnpm/consola@3.4.2/node_modules/consola/dist/shared/consola.DRwqZj3T.mjs +62 -0
- package/dist/node_modules/.pnpm/consola@3.4.2/node_modules/consola/dist/shared/consola.DXBYu-KD.mjs +190 -0
- package/dist/node_modules/.pnpm/consola@3.4.2/node_modules/consola/dist/utils.mjs +2 -0
- package/dist/node_modules/.pnpm/cross-spawn@7.0.6/node_modules/cross-spawn/index.mjs +29 -0
- package/dist/node_modules/.pnpm/cross-spawn@7.0.6/node_modules/cross-spawn/lib/enoent.mjs +42 -0
- package/dist/node_modules/.pnpm/cross-spawn@7.0.6/node_modules/cross-spawn/lib/parse.mjs +67 -0
- package/dist/node_modules/.pnpm/cross-spawn@7.0.6/node_modules/cross-spawn/lib/util/escape.mjs +23 -0
- package/dist/node_modules/.pnpm/cross-spawn@7.0.6/node_modules/cross-spawn/lib/util/readShebang.mjs +22 -0
- package/dist/node_modules/.pnpm/cross-spawn@7.0.6/node_modules/cross-spawn/lib/util/resolveCommand.mjs +36 -0
- package/dist/node_modules/.pnpm/crossws@0.3.5/node_modules/crossws/dist/adapters/node.d.mts +292 -0
- package/dist/node_modules/.pnpm/crossws@0.3.5/node_modules/crossws/dist/adapters/node.mjs +127 -0
- package/dist/node_modules/.pnpm/crossws@0.3.5/node_modules/crossws/dist/index.d.mts +145 -0
- package/dist/node_modules/.pnpm/crossws@0.3.5/node_modules/crossws/dist/shared/crossws.BQXMA5bH.d.mts +298 -0
- package/dist/node_modules/.pnpm/crossws@0.3.5/node_modules/crossws/dist/shared/crossws.By9qWDAI.mjs +9 -0
- package/dist/node_modules/.pnpm/crossws@0.3.5/node_modules/crossws/dist/shared/crossws.CipVM6lf.mjs +3549 -0
- package/dist/node_modules/.pnpm/crossws@0.3.5/node_modules/crossws/dist/shared/crossws.D9ehKjSh.mjs +66 -0
- package/dist/node_modules/.pnpm/crossws@0.3.5/node_modules/crossws/dist/shared/crossws.DfCzGthR.mjs +227 -0
- package/dist/node_modules/.pnpm/execa@8.0.1/node_modules/execa/index.mjs +224 -0
- package/dist/node_modules/.pnpm/execa@8.0.1/node_modules/execa/lib/command.mjs +52 -0
- package/dist/node_modules/.pnpm/execa@8.0.1/node_modules/execa/lib/error.mjs +54 -0
- package/dist/node_modules/.pnpm/execa@8.0.1/node_modules/execa/lib/kill.mjs +62 -0
- package/dist/node_modules/.pnpm/execa@8.0.1/node_modules/execa/lib/pipe.mjs +26 -0
- package/dist/node_modules/.pnpm/execa@8.0.1/node_modules/execa/lib/promise.mjs +32 -0
- package/dist/node_modules/.pnpm/execa@8.0.1/node_modules/execa/lib/stdio.mjs +19 -0
- package/dist/node_modules/.pnpm/execa@8.0.1/node_modules/execa/lib/stream.mjs +98 -0
- package/dist/node_modules/.pnpm/execa@8.0.1/node_modules/execa/lib/verbose.mjs +15 -0
- package/dist/node_modules/.pnpm/get-port-please@3.2.0/node_modules/get-port-please/dist/index.d.mts +15 -0
- package/dist/node_modules/.pnpm/get-port-please@3.2.0/node_modules/get-port-please/dist/index.mjs +220 -0
- package/dist/node_modules/.pnpm/get-stream@8.0.1/node_modules/get-stream/source/array-buffer.mjs +54 -0
- package/dist/node_modules/.pnpm/get-stream@8.0.1/node_modules/get-stream/source/array.mjs +2 -0
- package/dist/node_modules/.pnpm/get-stream@8.0.1/node_modules/get-stream/source/buffer.mjs +14 -0
- package/dist/node_modules/.pnpm/get-stream@8.0.1/node_modules/get-stream/source/contents.mjs +76 -0
- package/dist/node_modules/.pnpm/get-stream@8.0.1/node_modules/get-stream/source/index.mjs +6 -0
- package/dist/node_modules/.pnpm/get-stream@8.0.1/node_modules/get-stream/source/string.mjs +35 -0
- package/dist/node_modules/.pnpm/get-stream@8.0.1/node_modules/get-stream/source/utils.mjs +10 -0
- package/dist/node_modules/.pnpm/http-shutdown@1.2.2/node_modules/http-shutdown/index.mjs +76 -0
- package/dist/node_modules/.pnpm/human-signals@5.0.0/node_modules/human-signals/build/src/core.mjs +274 -0
- package/dist/node_modules/.pnpm/human-signals@5.0.0/node_modules/human-signals/build/src/main.mjs +44 -0
- package/dist/node_modules/.pnpm/human-signals@5.0.0/node_modules/human-signals/build/src/realtime.mjs +15 -0
- package/dist/node_modules/.pnpm/human-signals@5.0.0/node_modules/human-signals/build/src/signals.mjs +23 -0
- package/dist/node_modules/.pnpm/is-docker@3.0.0/node_modules/is-docker/index.mjs +24 -0
- package/dist/node_modules/.pnpm/is-inside-container@1.0.0/node_modules/is-inside-container/index.mjs +18 -0
- package/dist/node_modules/.pnpm/is-stream@3.0.0/node_modules/is-stream/index.mjs +9 -0
- package/dist/node_modules/.pnpm/is-wsl@3.1.1/node_modules/is-wsl/index.mjs +20 -0
- package/dist/node_modules/.pnpm/is64bit@2.0.0/node_modules/is64bit/index.mjs +13 -0
- package/dist/node_modules/.pnpm/isexe@2.0.0/node_modules/isexe/index.mjs +47 -0
- package/dist/node_modules/.pnpm/isexe@2.0.0/node_modules/isexe/mode.mjs +33 -0
- package/dist/node_modules/.pnpm/isexe@2.0.0/node_modules/isexe/windows.mjs +33 -0
- package/dist/node_modules/.pnpm/listhen@1.9.0/node_modules/listhen/dist/chunks/xdg-open.mjs +1070 -0
- package/dist/node_modules/.pnpm/listhen@1.9.0/node_modules/listhen/dist/index.mjs +619 -0
- package/dist/node_modules/.pnpm/listhen@1.9.0/node_modules/listhen/dist/shared/listhen.1c46e31d.d.mts +83 -0
- package/dist/node_modules/.pnpm/merge-stream@2.0.0/node_modules/merge-stream/index.mjs +38 -0
- package/dist/node_modules/.pnpm/mimic-fn@4.0.0/node_modules/mimic-fn/index.mjs +38 -0
- package/dist/node_modules/.pnpm/node-forge@1.4.0/node_modules/node-forge/lib/aes.mjs +597 -0
- package/dist/node_modules/.pnpm/node-forge@1.4.0/node_modules/node-forge/lib/aesCipherSuites.mjs +195 -0
- package/dist/node_modules/.pnpm/node-forge@1.4.0/node_modules/node-forge/lib/asn1-validator.mjs +76 -0
- package/dist/node_modules/.pnpm/node-forge@1.4.0/node_modules/node-forge/lib/asn1.mjs +967 -0
- package/dist/node_modules/.pnpm/node-forge@1.4.0/node_modules/node-forge/lib/baseN.mjs +137 -0
- package/dist/node_modules/.pnpm/node-forge@1.4.0/node_modules/node-forge/lib/cipher.mjs +186 -0
- package/dist/node_modules/.pnpm/node-forge@1.4.0/node_modules/node-forge/lib/cipherModes.mjs +597 -0
- package/dist/node_modules/.pnpm/node-forge@1.4.0/node_modules/node-forge/lib/des.mjs +1187 -0
- package/dist/node_modules/.pnpm/node-forge@1.4.0/node_modules/node-forge/lib/ed25519.mjs +1029 -0
- package/dist/node_modules/.pnpm/node-forge@1.4.0/node_modules/node-forge/lib/forge.mjs +15 -0
- package/dist/node_modules/.pnpm/node-forge@1.4.0/node_modules/node-forge/lib/hmac.mjs +107 -0
- package/dist/node_modules/.pnpm/node-forge@1.4.0/node_modules/node-forge/lib/index.mjs +66 -0
- package/dist/node_modules/.pnpm/node-forge@1.4.0/node_modules/node-forge/lib/jsbn.mjs +1334 -0
- package/dist/node_modules/.pnpm/node-forge@1.4.0/node_modules/node-forge/lib/kem.mjs +146 -0
- package/dist/node_modules/.pnpm/node-forge@1.4.0/node_modules/node-forge/lib/log.mjs +241 -0
- package/dist/node_modules/.pnpm/node-forge@1.4.0/node_modules/node-forge/lib/md.all.mjs +24 -0
- package/dist/node_modules/.pnpm/node-forge@1.4.0/node_modules/node-forge/lib/md.mjs +18 -0
- package/dist/node_modules/.pnpm/node-forge@1.4.0/node_modules/node-forge/lib/md5.mjs +324 -0
- package/dist/node_modules/.pnpm/node-forge@1.4.0/node_modules/node-forge/lib/mgf.mjs +20 -0
- package/dist/node_modules/.pnpm/node-forge@1.4.0/node_modules/node-forge/lib/mgf1.mjs +44 -0
- package/dist/node_modules/.pnpm/node-forge@1.4.0/node_modules/node-forge/lib/oids.mjs +154 -0
- package/dist/node_modules/.pnpm/node-forge@1.4.0/node_modules/node-forge/lib/pbe.mjs +815 -0
- package/dist/node_modules/.pnpm/node-forge@1.4.0/node_modules/node-forge/lib/pbkdf2.mjs +125 -0
- package/dist/node_modules/.pnpm/node-forge@1.4.0/node_modules/node-forge/lib/pem.mjs +175 -0
- package/dist/node_modules/.pnpm/node-forge@1.4.0/node_modules/node-forge/lib/pkcs1.mjs +200 -0
- package/dist/node_modules/.pnpm/node-forge@1.4.0/node_modules/node-forge/lib/pkcs12.mjs +724 -0
- package/dist/node_modules/.pnpm/node-forge@1.4.0/node_modules/node-forge/lib/pkcs7.mjs +642 -0
- package/dist/node_modules/.pnpm/node-forge@1.4.0/node_modules/node-forge/lib/pkcs7asn1.mjs +405 -0
- package/dist/node_modules/.pnpm/node-forge@1.4.0/node_modules/node-forge/lib/pki.mjs +101 -0
- package/dist/node_modules/.pnpm/node-forge@1.4.0/node_modules/node-forge/lib/prime.mjs +193 -0
- package/dist/node_modules/.pnpm/node-forge@1.4.0/node_modules/node-forge/lib/prng.mjs +290 -0
- package/dist/node_modules/.pnpm/node-forge@1.4.0/node_modules/node-forge/lib/pss.mjs +141 -0
- package/dist/node_modules/.pnpm/node-forge@1.4.0/node_modules/node-forge/lib/random.mjs +141 -0
- package/dist/node_modules/.pnpm/node-forge@1.4.0/node_modules/node-forge/lib/rc2.mjs +538 -0
- package/dist/node_modules/.pnpm/node-forge@1.4.0/node_modules/node-forge/lib/rsa.mjs +1309 -0
- package/dist/node_modules/.pnpm/node-forge@1.4.0/node_modules/node-forge/lib/sha1.mjs +230 -0
- package/dist/node_modules/.pnpm/node-forge@1.4.0/node_modules/node-forge/lib/sha256.mjs +267 -0
- package/dist/node_modules/.pnpm/node-forge@1.4.0/node_modules/node-forge/lib/sha512.mjs +413 -0
- package/dist/node_modules/.pnpm/node-forge@1.4.0/node_modules/node-forge/lib/ssh.mjs +194 -0
- package/dist/node_modules/.pnpm/node-forge@1.4.0/node_modules/node-forge/lib/tls.mjs +3655 -0
- package/dist/node_modules/.pnpm/node-forge@1.4.0/node_modules/node-forge/lib/util.mjs +2117 -0
- package/dist/node_modules/.pnpm/node-forge@1.4.0/node_modules/node-forge/lib/x509.mjs +2168 -0
- package/dist/node_modules/.pnpm/npm-run-path@5.3.0/node_modules/npm-run-path/index.mjs +34 -0
- package/dist/node_modules/.pnpm/onetime@6.0.0/node_modules/onetime/index.mjs +26 -0
- package/dist/node_modules/.pnpm/path-key@3.1.1/node_modules/path-key/index.mjs +14 -0
- package/dist/node_modules/.pnpm/path-key@4.0.0/node_modules/path-key/index.mjs +8 -0
- package/dist/node_modules/.pnpm/pathe@1.1.2/node_modules/pathe/dist/shared/pathe.ff20891b.mjs +176 -0
- package/dist/node_modules/.pnpm/shebang-command@2.0.0/node_modules/shebang-command/index.mjs +17 -0
- package/dist/node_modules/.pnpm/shebang-regex@3.0.0/node_modules/shebang-regex/index.mjs +8 -0
- package/dist/node_modules/.pnpm/signal-exit@4.1.0/node_modules/signal-exit/dist/mjs/index.mjs +169 -0
- package/dist/node_modules/.pnpm/signal-exit@4.1.0/node_modules/signal-exit/dist/mjs/signals.mjs +33 -0
- package/dist/node_modules/.pnpm/std-env@3.10.0/node_modules/std-env/dist/index.mjs +171 -0
- package/dist/node_modules/.pnpm/strip-final-newline@3.0.0/node_modules/strip-final-newline/index.mjs +10 -0
- package/dist/node_modules/.pnpm/system-architecture@0.1.0/node_modules/system-architecture/index.mjs +16 -0
- package/dist/node_modules/.pnpm/uncrypto@0.1.3/node_modules/uncrypto/dist/crypto.node.mjs +7 -0
- package/dist/node_modules/.pnpm/untun@0.1.3/node_modules/untun/dist/chunks/index.mjs +154 -0
- package/dist/node_modules/.pnpm/untun@0.1.3/node_modules/untun/dist/index.mjs +34 -0
- package/dist/node_modules/.pnpm/uqr@0.1.2/node_modules/uqr/dist/index.mjs +896 -0
- package/dist/node_modules/.pnpm/which@2.0.2/node_modules/which/which.mjs +76 -0
- package/dist/oauth2/errors.mjs +16 -1
- package/dist/oauth2/index.d.mts +2 -2
- package/dist/oauth2/index.mjs +3 -3
- package/dist/oauth2/link-account.d.mts +27 -1
- package/dist/oauth2/link-account.mjs +30 -5
- package/dist/oauth2/state.mjs +8 -2
- package/dist/{package.mjs → packages/better-auth/package.mjs} +1 -1
- package/dist/plugins/access/access.d.mts +3 -15
- package/dist/plugins/access/access.mjs +11 -6
- package/dist/plugins/access/index.d.mts +2 -2
- package/dist/plugins/access/types.d.mts +11 -4
- package/dist/plugins/admin/access/statement.d.mts +29 -93
- package/dist/plugins/admin/admin.mjs +0 -4
- package/dist/plugins/admin/client.d.mts +1 -1
- package/dist/plugins/admin/routes.mjs +3 -2
- package/dist/plugins/anonymous/client.d.mts +1 -0
- package/dist/plugins/anonymous/error-codes.d.mts +1 -0
- package/dist/plugins/anonymous/error-codes.mjs +1 -0
- package/dist/plugins/anonymous/index.d.mts +1 -0
- package/dist/plugins/anonymous/index.mjs +16 -2
- package/dist/plugins/bearer/index.mjs +4 -9
- package/dist/plugins/captcha/index.mjs +2 -2
- package/dist/plugins/device-authorization/error-codes.mjs +1 -0
- package/dist/plugins/device-authorization/index.d.mts +1 -0
- package/dist/plugins/device-authorization/routes.mjs +34 -3
- package/dist/plugins/email-otp/routes.mjs +1 -1
- package/dist/plugins/generic-oauth/error-codes.mjs +0 -1
- package/dist/plugins/generic-oauth/index.d.mts +2 -4
- package/dist/plugins/generic-oauth/index.mjs +23 -17
- package/dist/plugins/generic-oauth/providers/auth0.mjs +1 -0
- package/dist/plugins/generic-oauth/providers/gumroad.mjs +1 -0
- package/dist/plugins/generic-oauth/providers/hubspot.mjs +1 -0
- package/dist/plugins/generic-oauth/providers/keycloak.mjs +1 -0
- package/dist/plugins/generic-oauth/providers/line.mjs +1 -0
- package/dist/plugins/generic-oauth/providers/microsoft-entra-id.mjs +1 -0
- package/dist/plugins/generic-oauth/providers/okta.mjs +1 -0
- package/dist/plugins/generic-oauth/providers/patreon.mjs +1 -0
- package/dist/plugins/generic-oauth/providers/slack.mjs +1 -0
- package/dist/plugins/generic-oauth/types.d.mts +30 -8
- package/dist/plugins/index.d.mts +2 -2
- package/dist/plugins/jwt/utils.d.mts +1 -1
- package/dist/plugins/last-login-method/client.mjs +2 -2
- package/dist/plugins/magic-link/index.d.mts +8 -1
- package/dist/plugins/magic-link/index.mjs +4 -17
- package/dist/plugins/mcp/authorize.mjs +8 -2
- package/dist/plugins/mcp/index.mjs +75 -35
- package/dist/plugins/multi-session/index.mjs +2 -2
- package/dist/plugins/oauth-proxy/index.mjs +45 -32
- package/dist/plugins/oauth-proxy/utils.mjs +3 -10
- package/dist/plugins/oidc-provider/authorize.mjs +8 -2
- package/dist/plugins/oidc-provider/index.mjs +65 -38
- package/dist/plugins/one-tap/client.mjs +9 -2
- package/dist/plugins/one-tap/index.mjs +17 -35
- package/dist/plugins/open-api/generator.mjs +25 -5
- package/dist/plugins/organization/access/statement.d.mts +68 -201
- package/dist/plugins/organization/adapter.mjs +61 -56
- package/dist/plugins/organization/client.d.mts +3 -1
- package/dist/plugins/organization/error-codes.d.mts +2 -0
- package/dist/plugins/organization/error-codes.mjs +3 -1
- package/dist/plugins/organization/routes/crud-access-control.d.mts +2 -2
- package/dist/plugins/organization/routes/crud-invites.mjs +7 -2
- package/dist/plugins/organization/routes/crud-org.d.mts +4 -4
- package/dist/plugins/organization/routes/crud-org.mjs +2 -2
- package/dist/plugins/organization/types.d.mts +15 -5
- package/dist/plugins/phone-number/routes.mjs +1 -1
- package/dist/plugins/two-factor/backup-codes/index.d.mts +4 -3
- package/dist/plugins/two-factor/client.mjs +2 -1
- package/dist/plugins/two-factor/index.mjs +3 -2
- package/dist/plugins/username/index.d.mts +24 -2
- package/dist/plugins/username/index.mjs +49 -3
- package/dist/state.d.mts +2 -2
- package/dist/state.mjs +18 -4
- package/dist/test-utils/headers.mjs +2 -7
- package/dist/test-utils/http-test-instance.d.mts +397 -0
- package/dist/test-utils/http-test-instance.mjs +54 -0
- package/dist/test-utils/index.d.mts +2 -1
- package/dist/test-utils/index.mjs +2 -1
- package/dist/test-utils/test-instance.d.mts +73 -184
- package/dist/test-utils/test-instance.mjs +11 -2
- package/dist/utils/index.d.mts +1 -1
- package/dist/utils/url.d.mts +2 -1
- package/dist/utils/url.mjs +9 -3
- package/dist/version.mjs +1 -1
- package/package.json +14 -14
- package/dist/oauth2/error-codes.d.mts +0 -20
- package/dist/plugins/generic-oauth/client.d.mts +0 -32
- package/dist/plugins/generic-oauth/client.mjs +0 -19
- package/dist/plugins/generic-oauth/error-codes.d.mts +0 -10
|
@@ -1,8 +1,12 @@
|
|
|
1
|
+
import { createRequire } from "node:module";
|
|
1
2
|
//#region \0rolldown/runtime.js
|
|
3
|
+
var __create = Object.create;
|
|
2
4
|
var __defProp = Object.defineProperty;
|
|
3
5
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
6
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
7
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
5
8
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
9
|
+
var __commonJSMin = (cb, mod) => () => (mod || cb((mod = { exports: {} }).exports, mod), mod.exports);
|
|
6
10
|
var __exportAll = (all, no_symbols) => {
|
|
7
11
|
let target = {};
|
|
8
12
|
for (var name in all) __defProp(target, name, {
|
|
@@ -23,5 +27,10 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
23
27
|
return to;
|
|
24
28
|
};
|
|
25
29
|
var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
|
30
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
31
|
+
value: mod,
|
|
32
|
+
enumerable: true
|
|
33
|
+
}) : target, mod));
|
|
34
|
+
var __require = /* @__PURE__ */ createRequire(import.meta.url);
|
|
26
35
|
//#endregion
|
|
27
|
-
export { __exportAll, __reExport };
|
|
36
|
+
export { __commonJSMin, __exportAll, __reExport, __require, __toESM };
|
package/dist/api/index.d.mts
CHANGED
|
@@ -110,6 +110,7 @@ declare function getEndpoints<Option extends BetterAuthOptions>(ctx: Awaitable<A
|
|
|
110
110
|
scopes: zod.ZodOptional<zod.ZodArray<zod.ZodString>>;
|
|
111
111
|
requestSignUp: zod.ZodOptional<zod.ZodBoolean>;
|
|
112
112
|
loginHint: zod.ZodOptional<zod.ZodString>;
|
|
113
|
+
additionalParams: zod.ZodOptional<zod.ZodRecord<zod.ZodString, zod.ZodString>>;
|
|
113
114
|
additionalData: zod.ZodOptional<zod.ZodRecord<zod.ZodString, zod.ZodAny>>;
|
|
114
115
|
}, zod_v4_core0.$strip>;
|
|
115
116
|
metadata: {
|
|
@@ -137,6 +138,7 @@ declare function getEndpoints<Option extends BetterAuthOptions>(ctx: Awaitable<A
|
|
|
137
138
|
scopes: zod.ZodOptional<zod.ZodArray<zod.ZodString>>;
|
|
138
139
|
requestSignUp: zod.ZodOptional<zod.ZodBoolean>;
|
|
139
140
|
loginHint: zod.ZodOptional<zod.ZodString>;
|
|
141
|
+
additionalParams: zod.ZodOptional<zod.ZodRecord<zod.ZodString, zod.ZodString>>;
|
|
140
142
|
additionalData: zod.ZodOptional<zod.ZodRecord<zod.ZodString, zod.ZodAny>>;
|
|
141
143
|
}, zod_v4_core0.$strip>>;
|
|
142
144
|
returned: {
|
|
@@ -329,6 +331,7 @@ declare function getEndpoints<Option extends BetterAuthOptions>(ctx: Awaitable<A
|
|
|
329
331
|
callbackURL: zod.ZodOptional<zod.ZodString>;
|
|
330
332
|
rememberMe: zod.ZodOptional<zod.ZodBoolean>;
|
|
331
333
|
}, zod_v4_core0.$strip>, zod.ZodRecord<zod.ZodString, zod.ZodAny>>;
|
|
334
|
+
cloneRequest: true;
|
|
332
335
|
metadata: {
|
|
333
336
|
allowedMediaTypes: string[];
|
|
334
337
|
$Infer: {
|
|
@@ -495,6 +498,7 @@ declare function getEndpoints<Option extends BetterAuthOptions>(ctx: Awaitable<A
|
|
|
495
498
|
method: "POST";
|
|
496
499
|
operationId: string;
|
|
497
500
|
use: ((inputContext: better_call0.MiddlewareInputContext<better_call0.MiddlewareOptions>) => Promise<void>)[];
|
|
501
|
+
cloneRequest: true;
|
|
498
502
|
body: zod.ZodObject<{
|
|
499
503
|
email: zod.ZodString;
|
|
500
504
|
password: zod.ZodString;
|
|
@@ -726,6 +730,7 @@ declare function getEndpoints<Option extends BetterAuthOptions>(ctx: Awaitable<A
|
|
|
726
730
|
readonly sendVerificationEmail: better_call0.StrictEndpoint<"/send-verification-email", {
|
|
727
731
|
method: "POST";
|
|
728
732
|
operationId: string;
|
|
733
|
+
cloneRequest: true;
|
|
729
734
|
body: zod.ZodObject<{
|
|
730
735
|
email: zod.ZodEmail;
|
|
731
736
|
callbackURL: zod.ZodOptional<zod.ZodString>;
|
|
@@ -1582,6 +1587,8 @@ declare function getEndpoints<Option extends BetterAuthOptions>(ctx: Awaitable<A
|
|
|
1582
1587
|
scopes: zod.ZodOptional<zod.ZodArray<zod.ZodString>>;
|
|
1583
1588
|
errorCallbackURL: zod.ZodOptional<zod.ZodString>;
|
|
1584
1589
|
disableRedirect: zod.ZodOptional<zod.ZodBoolean>;
|
|
1590
|
+
loginHint: zod.ZodOptional<zod.ZodString>;
|
|
1591
|
+
additionalParams: zod.ZodOptional<zod.ZodRecord<zod.ZodString, zod.ZodString>>;
|
|
1585
1592
|
additionalData: zod.ZodOptional<zod.ZodRecord<zod.ZodString, zod.ZodAny>>;
|
|
1586
1593
|
}, zod_v4_core0.$strip>;
|
|
1587
1594
|
use: ((inputContext: better_call0.MiddlewareInputContext<better_call0.MiddlewareOptions>) => Promise<{
|
|
@@ -1930,29 +1937,6 @@ declare function getEndpoints<Option extends BetterAuthOptions>(ctx: Awaitable<A
|
|
|
1930
1937
|
}>;
|
|
1931
1938
|
readonly accountInfo: better_call0.StrictEndpoint<"/account-info", {
|
|
1932
1939
|
method: "GET";
|
|
1933
|
-
use: ((inputContext: better_call0.MiddlewareInputContext<better_call0.MiddlewareOptions>) => Promise<{
|
|
1934
|
-
session: {
|
|
1935
|
-
session: Record<string, any> & {
|
|
1936
|
-
id: string;
|
|
1937
|
-
createdAt: Date;
|
|
1938
|
-
updatedAt: Date;
|
|
1939
|
-
userId: string;
|
|
1940
|
-
expiresAt: Date;
|
|
1941
|
-
token: string;
|
|
1942
|
-
ipAddress?: string | null | undefined;
|
|
1943
|
-
userAgent?: string | null | undefined;
|
|
1944
|
-
};
|
|
1945
|
-
user: Record<string, any> & {
|
|
1946
|
-
id: string;
|
|
1947
|
-
createdAt: Date;
|
|
1948
|
-
updatedAt: Date;
|
|
1949
|
-
email: string;
|
|
1950
|
-
emailVerified: boolean;
|
|
1951
|
-
name: string;
|
|
1952
|
-
image?: string | null | undefined;
|
|
1953
|
-
};
|
|
1954
|
-
};
|
|
1955
|
-
}>)[];
|
|
1956
1940
|
metadata: {
|
|
1957
1941
|
openapi: {
|
|
1958
1942
|
description: string;
|
|
@@ -2002,6 +1986,8 @@ declare function getEndpoints<Option extends BetterAuthOptions>(ctx: Awaitable<A
|
|
|
2002
1986
|
};
|
|
2003
1987
|
query: zod.ZodOptional<zod.ZodObject<{
|
|
2004
1988
|
accountId: zod.ZodOptional<zod.ZodString>;
|
|
1989
|
+
providerId: zod.ZodOptional<zod.ZodString>;
|
|
1990
|
+
userId: zod.ZodOptional<zod.ZodString>;
|
|
2005
1991
|
}, zod_v4_core0.$strip>>;
|
|
2006
1992
|
}, {
|
|
2007
1993
|
user: _better_auth_core_oauth20.OAuth2UserInfo;
|
|
@@ -2100,6 +2086,7 @@ declare const router: <Option extends BetterAuthOptions>(ctx: AuthContext, optio
|
|
|
2100
2086
|
scopes: zod.ZodOptional<zod.ZodArray<zod.ZodString>>;
|
|
2101
2087
|
requestSignUp: zod.ZodOptional<zod.ZodBoolean>;
|
|
2102
2088
|
loginHint: zod.ZodOptional<zod.ZodString>;
|
|
2089
|
+
additionalParams: zod.ZodOptional<zod.ZodRecord<zod.ZodString, zod.ZodString>>;
|
|
2103
2090
|
additionalData: zod.ZodOptional<zod.ZodRecord<zod.ZodString, zod.ZodAny>>;
|
|
2104
2091
|
}, zod_v4_core0.$strip>;
|
|
2105
2092
|
metadata: {
|
|
@@ -2127,6 +2114,7 @@ declare const router: <Option extends BetterAuthOptions>(ctx: AuthContext, optio
|
|
|
2127
2114
|
scopes: zod.ZodOptional<zod.ZodArray<zod.ZodString>>;
|
|
2128
2115
|
requestSignUp: zod.ZodOptional<zod.ZodBoolean>;
|
|
2129
2116
|
loginHint: zod.ZodOptional<zod.ZodString>;
|
|
2117
|
+
additionalParams: zod.ZodOptional<zod.ZodRecord<zod.ZodString, zod.ZodString>>;
|
|
2130
2118
|
additionalData: zod.ZodOptional<zod.ZodRecord<zod.ZodString, zod.ZodAny>>;
|
|
2131
2119
|
}, zod_v4_core0.$strip>>;
|
|
2132
2120
|
returned: {
|
|
@@ -2319,6 +2307,7 @@ declare const router: <Option extends BetterAuthOptions>(ctx: AuthContext, optio
|
|
|
2319
2307
|
callbackURL: zod.ZodOptional<zod.ZodString>;
|
|
2320
2308
|
rememberMe: zod.ZodOptional<zod.ZodBoolean>;
|
|
2321
2309
|
}, zod_v4_core0.$strip>, zod.ZodRecord<zod.ZodString, zod.ZodAny>>;
|
|
2310
|
+
cloneRequest: true;
|
|
2322
2311
|
metadata: {
|
|
2323
2312
|
allowedMediaTypes: string[];
|
|
2324
2313
|
$Infer: {
|
|
@@ -2485,6 +2474,7 @@ declare const router: <Option extends BetterAuthOptions>(ctx: AuthContext, optio
|
|
|
2485
2474
|
method: "POST";
|
|
2486
2475
|
operationId: string;
|
|
2487
2476
|
use: ((inputContext: better_call0.MiddlewareInputContext<better_call0.MiddlewareOptions>) => Promise<void>)[];
|
|
2477
|
+
cloneRequest: true;
|
|
2488
2478
|
body: zod.ZodObject<{
|
|
2489
2479
|
email: zod.ZodString;
|
|
2490
2480
|
password: zod.ZodString;
|
|
@@ -2716,6 +2706,7 @@ declare const router: <Option extends BetterAuthOptions>(ctx: AuthContext, optio
|
|
|
2716
2706
|
readonly sendVerificationEmail: better_call0.StrictEndpoint<"/send-verification-email", {
|
|
2717
2707
|
method: "POST";
|
|
2718
2708
|
operationId: string;
|
|
2709
|
+
cloneRequest: true;
|
|
2719
2710
|
body: zod.ZodObject<{
|
|
2720
2711
|
email: zod.ZodEmail;
|
|
2721
2712
|
callbackURL: zod.ZodOptional<zod.ZodString>;
|
|
@@ -3572,6 +3563,8 @@ declare const router: <Option extends BetterAuthOptions>(ctx: AuthContext, optio
|
|
|
3572
3563
|
scopes: zod.ZodOptional<zod.ZodArray<zod.ZodString>>;
|
|
3573
3564
|
errorCallbackURL: zod.ZodOptional<zod.ZodString>;
|
|
3574
3565
|
disableRedirect: zod.ZodOptional<zod.ZodBoolean>;
|
|
3566
|
+
loginHint: zod.ZodOptional<zod.ZodString>;
|
|
3567
|
+
additionalParams: zod.ZodOptional<zod.ZodRecord<zod.ZodString, zod.ZodString>>;
|
|
3575
3568
|
additionalData: zod.ZodOptional<zod.ZodRecord<zod.ZodString, zod.ZodAny>>;
|
|
3576
3569
|
}, zod_v4_core0.$strip>;
|
|
3577
3570
|
use: ((inputContext: better_call0.MiddlewareInputContext<better_call0.MiddlewareOptions>) => Promise<{
|
|
@@ -3920,29 +3913,6 @@ declare const router: <Option extends BetterAuthOptions>(ctx: AuthContext, optio
|
|
|
3920
3913
|
}>;
|
|
3921
3914
|
readonly accountInfo: better_call0.StrictEndpoint<"/account-info", {
|
|
3922
3915
|
method: "GET";
|
|
3923
|
-
use: ((inputContext: better_call0.MiddlewareInputContext<better_call0.MiddlewareOptions>) => Promise<{
|
|
3924
|
-
session: {
|
|
3925
|
-
session: Record<string, any> & {
|
|
3926
|
-
id: string;
|
|
3927
|
-
createdAt: Date;
|
|
3928
|
-
updatedAt: Date;
|
|
3929
|
-
userId: string;
|
|
3930
|
-
expiresAt: Date;
|
|
3931
|
-
token: string;
|
|
3932
|
-
ipAddress?: string | null | undefined;
|
|
3933
|
-
userAgent?: string | null | undefined;
|
|
3934
|
-
};
|
|
3935
|
-
user: Record<string, any> & {
|
|
3936
|
-
id: string;
|
|
3937
|
-
createdAt: Date;
|
|
3938
|
-
updatedAt: Date;
|
|
3939
|
-
email: string;
|
|
3940
|
-
emailVerified: boolean;
|
|
3941
|
-
name: string;
|
|
3942
|
-
image?: string | null | undefined;
|
|
3943
|
-
};
|
|
3944
|
-
};
|
|
3945
|
-
}>)[];
|
|
3946
3916
|
metadata: {
|
|
3947
3917
|
openapi: {
|
|
3948
3918
|
description: string;
|
|
@@ -3992,6 +3962,8 @@ declare const router: <Option extends BetterAuthOptions>(ctx: AuthContext, optio
|
|
|
3992
3962
|
};
|
|
3993
3963
|
query: zod.ZodOptional<zod.ZodObject<{
|
|
3994
3964
|
accountId: zod.ZodOptional<zod.ZodString>;
|
|
3965
|
+
providerId: zod.ZodOptional<zod.ZodString>;
|
|
3966
|
+
userId: zod.ZodOptional<zod.ZodString>;
|
|
3995
3967
|
}, zod_v4_core0.$strip>>;
|
|
3996
3968
|
}, {
|
|
3997
3969
|
user: _better_auth_core_oauth20.OAuth2UserInfo;
|
|
@@ -104,6 +104,8 @@ declare const linkSocialAccount: better_call0.StrictEndpoint<"/link-social", {
|
|
|
104
104
|
scopes: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
105
105
|
errorCallbackURL: z.ZodOptional<z.ZodString>;
|
|
106
106
|
disableRedirect: z.ZodOptional<z.ZodBoolean>;
|
|
107
|
+
loginHint: z.ZodOptional<z.ZodString>;
|
|
108
|
+
additionalParams: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
|
|
107
109
|
additionalData: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodAny>>;
|
|
108
110
|
}, z.core.$strip>;
|
|
109
111
|
use: ((inputContext: better_call0.MiddlewareInputContext<better_call0.MiddlewareOptions>) => Promise<{
|
|
@@ -328,29 +330,6 @@ declare const refreshToken: better_call0.StrictEndpoint<"/refresh-token", {
|
|
|
328
330
|
}>;
|
|
329
331
|
declare const accountInfo: better_call0.StrictEndpoint<"/account-info", {
|
|
330
332
|
method: "GET";
|
|
331
|
-
use: ((inputContext: better_call0.MiddlewareInputContext<better_call0.MiddlewareOptions>) => Promise<{
|
|
332
|
-
session: {
|
|
333
|
-
session: Record<string, any> & {
|
|
334
|
-
id: string;
|
|
335
|
-
createdAt: Date;
|
|
336
|
-
updatedAt: Date;
|
|
337
|
-
userId: string;
|
|
338
|
-
expiresAt: Date;
|
|
339
|
-
token: string;
|
|
340
|
-
ipAddress?: string | null | undefined;
|
|
341
|
-
userAgent?: string | null | undefined;
|
|
342
|
-
};
|
|
343
|
-
user: Record<string, any> & {
|
|
344
|
-
id: string;
|
|
345
|
-
createdAt: Date;
|
|
346
|
-
updatedAt: Date;
|
|
347
|
-
email: string;
|
|
348
|
-
emailVerified: boolean;
|
|
349
|
-
name: string;
|
|
350
|
-
image?: string | null | undefined;
|
|
351
|
-
};
|
|
352
|
-
};
|
|
353
|
-
}>)[];
|
|
354
333
|
metadata: {
|
|
355
334
|
openapi: {
|
|
356
335
|
description: string;
|
|
@@ -400,6 +379,8 @@ declare const accountInfo: better_call0.StrictEndpoint<"/account-info", {
|
|
|
400
379
|
};
|
|
401
380
|
query: z.ZodOptional<z.ZodObject<{
|
|
402
381
|
accountId: z.ZodOptional<z.ZodString>;
|
|
382
|
+
providerId: z.ZodOptional<z.ZodString>;
|
|
383
|
+
userId: z.ZodOptional<z.ZodString>;
|
|
403
384
|
}, z.core.$strip>>;
|
|
404
385
|
}, {
|
|
405
386
|
user: _better_auth_core_oauth20.OAuth2UserInfo;
|
|
@@ -2,10 +2,12 @@ import { parseAccountOutput } from "../../db/schema.mjs";
|
|
|
2
2
|
import { getAccountCookie, setAccountCookie } from "../../cookies/session-store.mjs";
|
|
3
3
|
import { getAwaitableValue } from "../../context/helpers.mjs";
|
|
4
4
|
import { missingEmailLogMessage } from "../../oauth2/errors.mjs";
|
|
5
|
-
import { generateState } from "../../oauth2/state.mjs";
|
|
6
5
|
import { decryptOAuthToken, setTokenUtil } from "../../oauth2/utils.mjs";
|
|
6
|
+
import { applyUpdateUserInfoOnLink } from "../../oauth2/link-account.mjs";
|
|
7
|
+
import { generateState } from "../../oauth2/state.mjs";
|
|
7
8
|
import { freshSessionMiddleware, getSessionFromCtx, sessionMiddleware } from "./session.mjs";
|
|
8
9
|
import { APIError, BASE_ERROR_CODES } from "@better-auth/core/error";
|
|
10
|
+
import { additionalAuthorizationParamsSchema } from "@better-auth/core/oauth2";
|
|
9
11
|
import { SocialProviderListEnum } from "@better-auth/core/social-providers";
|
|
10
12
|
import { createAuthEndpoint } from "@better-auth/core/api";
|
|
11
13
|
import * as z from "zod";
|
|
@@ -81,6 +83,8 @@ const linkSocialAccount = createAuthEndpoint("/link-social", {
|
|
|
81
83
|
scopes: z.array(z.string()).meta({ description: "Additional scopes to request from the provider" }).optional(),
|
|
82
84
|
errorCallbackURL: z.string().meta({ description: "The URL to redirect to if there is an error during the link process" }).optional(),
|
|
83
85
|
disableRedirect: z.boolean().meta({ description: "Disable automatic redirection to the provider. Useful for handling the redirection yourself" }).optional(),
|
|
86
|
+
loginHint: z.string().meta({ description: "The login hint to use for the authorization code request" }).optional(),
|
|
87
|
+
additionalParams: additionalAuthorizationParamsSchema,
|
|
84
88
|
additionalData: z.record(z.string(), z.any()).optional()
|
|
85
89
|
}),
|
|
86
90
|
use: [sessionMiddleware],
|
|
@@ -166,14 +170,7 @@ const linkSocialAccount = createAuthEndpoint("/link-social", {
|
|
|
166
170
|
code: "LINKING_FAILED"
|
|
167
171
|
});
|
|
168
172
|
}
|
|
169
|
-
|
|
170
|
-
await c.context.internalAdapter.updateUser(session.user.id, {
|
|
171
|
-
name: linkingUserInfo.user?.name,
|
|
172
|
-
image: linkingUserInfo.user?.image
|
|
173
|
-
});
|
|
174
|
-
} catch (e) {
|
|
175
|
-
console.warn("Could not update user - " + e.toString());
|
|
176
|
-
}
|
|
173
|
+
await applyUpdateUserInfoOnLink(c, session.user.id, linkingUserInfo.user);
|
|
177
174
|
return c.json({
|
|
178
175
|
url: "",
|
|
179
176
|
status: true,
|
|
@@ -188,7 +185,9 @@ const linkSocialAccount = createAuthEndpoint("/link-social", {
|
|
|
188
185
|
state: state.state,
|
|
189
186
|
codeVerifier: state.codeVerifier,
|
|
190
187
|
redirectURI: `${c.context.baseURL}/callback/${provider.id}`,
|
|
191
|
-
scopes: c.body.scopes
|
|
188
|
+
scopes: c.body.scopes,
|
|
189
|
+
loginHint: c.body.loginHint,
|
|
190
|
+
additionalParams: c.body.additionalParams
|
|
192
191
|
});
|
|
193
192
|
if (!c.body.disableRedirect) c.setHeader("Location", url.toString());
|
|
194
193
|
return c.json({
|
|
@@ -222,50 +221,44 @@ const unlinkAccount = createAuthEndpoint("/unlink-account", {
|
|
|
222
221
|
await ctx.context.internalAdapter.deleteAccount(accountExist.id);
|
|
223
222
|
return ctx.json({ status: true });
|
|
224
223
|
});
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
description: "A Valid access token",
|
|
237
|
-
content: { "application/json": { schema: {
|
|
238
|
-
type: "object",
|
|
239
|
-
properties: {
|
|
240
|
-
tokenType: { type: "string" },
|
|
241
|
-
idToken: { type: "string" },
|
|
242
|
-
accessToken: { type: "string" },
|
|
243
|
-
accessTokenExpiresAt: {
|
|
244
|
-
type: "string",
|
|
245
|
-
format: "date-time"
|
|
246
|
-
}
|
|
247
|
-
}
|
|
248
|
-
} } }
|
|
249
|
-
},
|
|
250
|
-
400: { description: "Invalid refresh token or provider configuration" }
|
|
251
|
-
}
|
|
252
|
-
} }
|
|
253
|
-
}, async (ctx) => {
|
|
254
|
-
const { providerId, accountId, userId } = ctx.body || {};
|
|
255
|
-
const req = ctx.request;
|
|
224
|
+
/**
|
|
225
|
+
* Resolves the user id an account-token operation should act on.
|
|
226
|
+
*
|
|
227
|
+
* A caller reaching the server over HTTP (a request or session headers are
|
|
228
|
+
* present) must have a valid session, and that session's user always wins.
|
|
229
|
+
* A trusted server-side `auth.api` caller with no session may instead name a
|
|
230
|
+
* `userId` directly. Throws `UNAUTHORIZED` when an HTTP caller is
|
|
231
|
+
* unauthenticated, and `USER_ID_OR_SESSION_REQUIRED` when neither a session
|
|
232
|
+
* nor a `userId` is available.
|
|
233
|
+
*/
|
|
234
|
+
async function resolveUserId(ctx, userId) {
|
|
256
235
|
const session = await getSessionFromCtx(ctx);
|
|
257
|
-
if (
|
|
236
|
+
if (!session && (ctx.request || ctx.headers)) throw ctx.error("UNAUTHORIZED");
|
|
258
237
|
const resolvedUserId = session?.user?.id || userId;
|
|
259
|
-
if (!resolvedUserId) throw
|
|
238
|
+
if (!resolvedUserId) throw APIError.from("BAD_REQUEST", {
|
|
239
|
+
message: "Either userId or session is required",
|
|
240
|
+
code: "USER_ID_OR_SESSION_REQUIRED"
|
|
241
|
+
});
|
|
242
|
+
return resolvedUserId;
|
|
243
|
+
}
|
|
244
|
+
/**
|
|
245
|
+
* Fetches a currently-valid access token for a user's provider account,
|
|
246
|
+
* refreshing and persisting it when it is within five seconds of expiry.
|
|
247
|
+
* Shared by the `/get-access-token` endpoint and `/account-info` so both
|
|
248
|
+
* resolve and refresh tokens through one path.
|
|
249
|
+
*/
|
|
250
|
+
async function getValidAccessToken(ctx, { resolvedUserId, providerId, accountId, account: resolvedAccount }) {
|
|
260
251
|
const provider = await getAwaitableValue(ctx.context.socialProviders, { value: providerId });
|
|
261
252
|
if (!provider) throw APIError.from("BAD_REQUEST", {
|
|
262
253
|
message: `Provider ${providerId} is not supported.`,
|
|
263
254
|
code: "PROVIDER_NOT_SUPPORTED"
|
|
264
255
|
});
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
256
|
+
let account = resolvedAccount;
|
|
257
|
+
if (!account) {
|
|
258
|
+
const accountData = await getAccountCookie(ctx);
|
|
259
|
+
if (accountData && accountData.userId === resolvedUserId && providerId === accountData.providerId && (!accountId || accountData.accountId === accountId)) account = accountData;
|
|
260
|
+
else account = (await ctx.context.internalAdapter.findAccounts(resolvedUserId)).find((acc) => accountId ? acc.accountId === accountId && acc.providerId === providerId : acc.providerId === providerId);
|
|
261
|
+
}
|
|
269
262
|
if (!account) throw APIError.from("BAD_REQUEST", BASE_ERROR_CODES.ACCOUNT_NOT_FOUND);
|
|
270
263
|
try {
|
|
271
264
|
let newTokens = null;
|
|
@@ -297,19 +290,55 @@ const getAccessToken = createAuthEndpoint("/get-access-token", {
|
|
|
297
290
|
return account.accessTokenExpiresAt;
|
|
298
291
|
}
|
|
299
292
|
})();
|
|
300
|
-
|
|
293
|
+
return {
|
|
301
294
|
accessToken: newTokens?.accessToken ?? await decryptOAuthToken(account.accessToken ?? "", ctx.context),
|
|
302
295
|
accessTokenExpiresAt,
|
|
303
296
|
scopes: account.scope?.split(",") ?? [],
|
|
304
297
|
idToken: newTokens?.idToken ?? account.idToken ?? void 0
|
|
305
298
|
};
|
|
306
|
-
return ctx.json(tokens);
|
|
307
299
|
} catch (_error) {
|
|
308
300
|
throw APIError.from("BAD_REQUEST", {
|
|
309
301
|
message: "Failed to get a valid access token",
|
|
310
302
|
code: "FAILED_TO_GET_ACCESS_TOKEN"
|
|
311
303
|
});
|
|
312
304
|
}
|
|
305
|
+
}
|
|
306
|
+
const getAccessToken = createAuthEndpoint("/get-access-token", {
|
|
307
|
+
method: "POST",
|
|
308
|
+
body: z.object({
|
|
309
|
+
providerId: z.string().meta({ description: "The provider ID for the OAuth provider" }),
|
|
310
|
+
accountId: z.string().meta({ description: "The account ID associated with the refresh token" }).optional(),
|
|
311
|
+
userId: z.string().meta({ description: "The user ID associated with the account" }).optional()
|
|
312
|
+
}),
|
|
313
|
+
metadata: { openapi: {
|
|
314
|
+
description: "Get a valid access token, doing a refresh if needed",
|
|
315
|
+
responses: {
|
|
316
|
+
200: {
|
|
317
|
+
description: "A Valid access token",
|
|
318
|
+
content: { "application/json": { schema: {
|
|
319
|
+
type: "object",
|
|
320
|
+
properties: {
|
|
321
|
+
tokenType: { type: "string" },
|
|
322
|
+
idToken: { type: "string" },
|
|
323
|
+
accessToken: { type: "string" },
|
|
324
|
+
accessTokenExpiresAt: {
|
|
325
|
+
type: "string",
|
|
326
|
+
format: "date-time"
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
} } }
|
|
330
|
+
},
|
|
331
|
+
400: { description: "Invalid refresh token or provider configuration" }
|
|
332
|
+
}
|
|
333
|
+
} }
|
|
334
|
+
}, async (ctx) => {
|
|
335
|
+
const { providerId, accountId, userId } = ctx.body || {};
|
|
336
|
+
const tokens = await getValidAccessToken(ctx, {
|
|
337
|
+
resolvedUserId: await resolveUserId(ctx, userId),
|
|
338
|
+
providerId,
|
|
339
|
+
accountId
|
|
340
|
+
});
|
|
341
|
+
return ctx.json(tokens);
|
|
313
342
|
});
|
|
314
343
|
const refreshToken = createAuthEndpoint("/refresh-token", {
|
|
315
344
|
method: "POST",
|
|
@@ -346,14 +375,7 @@ const refreshToken = createAuthEndpoint("/refresh-token", {
|
|
|
346
375
|
} }
|
|
347
376
|
}, async (ctx) => {
|
|
348
377
|
const { providerId, accountId, userId } = ctx.body;
|
|
349
|
-
const
|
|
350
|
-
const session = await getSessionFromCtx(ctx);
|
|
351
|
-
if (req && !session) throw ctx.error("UNAUTHORIZED");
|
|
352
|
-
const resolvedUserId = session?.user?.id || userId;
|
|
353
|
-
if (!resolvedUserId) throw APIError.from("BAD_REQUEST", {
|
|
354
|
-
message: `Either userId or session is required`,
|
|
355
|
-
code: "USER_ID_OR_SESSION_REQUIRED"
|
|
356
|
-
});
|
|
378
|
+
const resolvedUserId = await resolveUserId(ctx, userId);
|
|
357
379
|
const provider = await getAwaitableValue(ctx.context.socialProviders, { value: providerId });
|
|
358
380
|
if (!provider) throw APIError.from("BAD_REQUEST", {
|
|
359
381
|
message: `Provider ${providerId} is not supported.`,
|
|
@@ -418,10 +440,13 @@ const refreshToken = createAuthEndpoint("/refresh-token", {
|
|
|
418
440
|
});
|
|
419
441
|
}
|
|
420
442
|
});
|
|
421
|
-
const accountInfoQuerySchema = z.optional(z.object({
|
|
443
|
+
const accountInfoQuerySchema = z.optional(z.object({
|
|
444
|
+
accountId: z.string().meta({ description: "The provider given account id for which to get the account info" }).optional(),
|
|
445
|
+
providerId: z.string().meta({ description: "The provider ID to disambiguate provider-issued account IDs" }).optional(),
|
|
446
|
+
userId: z.string().meta({ description: "The user ID associated with the account" }).optional()
|
|
447
|
+
}));
|
|
422
448
|
const accountInfo = createAuthEndpoint("/account-info", {
|
|
423
449
|
method: "GET",
|
|
424
|
-
use: [sessionMiddleware],
|
|
425
450
|
metadata: { openapi: {
|
|
426
451
|
description: "Get the account info provided by the provider",
|
|
427
452
|
responses: { "200": {
|
|
@@ -453,7 +478,8 @@ const accountInfo = createAuthEndpoint("/account-info", {
|
|
|
453
478
|
} },
|
|
454
479
|
query: accountInfoQuerySchema
|
|
455
480
|
}, async (ctx) => {
|
|
456
|
-
const providedAccountId = ctx.query
|
|
481
|
+
const { accountId: providedAccountId, providerId: providedProviderId, userId } = ctx.query || {};
|
|
482
|
+
const resolvedUserId = await resolveUserId(ctx, userId);
|
|
457
483
|
let account = void 0;
|
|
458
484
|
if (!providedAccountId) {
|
|
459
485
|
if (ctx.context.options.account?.storeAccountCookie) {
|
|
@@ -461,24 +487,24 @@ const accountInfo = createAuthEndpoint("/account-info", {
|
|
|
461
487
|
if (accountData) account = accountData;
|
|
462
488
|
}
|
|
463
489
|
} else {
|
|
464
|
-
const
|
|
465
|
-
if (
|
|
490
|
+
const matchingAccounts = (await ctx.context.internalAdapter.findAccounts(resolvedUserId)).filter((acc) => acc.accountId === providedAccountId && (!providedProviderId || acc.providerId === providedProviderId));
|
|
491
|
+
if (matchingAccounts.length > 1) throw APIError.from("BAD_REQUEST", {
|
|
492
|
+
message: "Multiple accounts share this account ID. Pass a providerId to disambiguate.",
|
|
493
|
+
code: "AMBIGUOUS_ACCOUNT"
|
|
494
|
+
});
|
|
495
|
+
account = matchingAccounts[0];
|
|
466
496
|
}
|
|
467
|
-
if (!account || account.userId !==
|
|
497
|
+
if (!account || account.userId !== resolvedUserId) throw APIError.from("BAD_REQUEST", BASE_ERROR_CODES.ACCOUNT_NOT_FOUND);
|
|
468
498
|
const provider = await getAwaitableValue(ctx.context.socialProviders, { value: account.providerId });
|
|
469
|
-
if (!provider) throw APIError.from("
|
|
470
|
-
message:
|
|
499
|
+
if (!provider) throw APIError.from("BAD_REQUEST", {
|
|
500
|
+
message: "Account is not associated with a configured social provider.",
|
|
471
501
|
code: "PROVIDER_NOT_CONFIGURED"
|
|
472
502
|
});
|
|
473
|
-
const tokens = await
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
providerId: account.providerId
|
|
479
|
-
},
|
|
480
|
-
returnHeaders: false,
|
|
481
|
-
returnStatus: false
|
|
503
|
+
const tokens = await getValidAccessToken(ctx, {
|
|
504
|
+
resolvedUserId,
|
|
505
|
+
providerId: account.providerId,
|
|
506
|
+
accountId: account.accountId,
|
|
507
|
+
account
|
|
482
508
|
});
|
|
483
509
|
if (!tokens.accessToken) throw APIError.from("BAD_REQUEST", {
|
|
484
510
|
message: "Access token not found",
|
|
@@ -1,10 +1,11 @@
|
|
|
1
|
+
import { isAPIError } from "../../utils/is-api-error.mjs";
|
|
1
2
|
import { setSessionCookie } from "../../cookies/index.mjs";
|
|
2
3
|
import { getAwaitableValue } from "../../context/helpers.mjs";
|
|
3
4
|
import { missingEmailLogMessage } from "../../oauth2/errors.mjs";
|
|
4
|
-
import { parseState } from "../../oauth2/state.mjs";
|
|
5
5
|
import { setTokenUtil } from "../../oauth2/utils.mjs";
|
|
6
|
+
import { applyUpdateUserInfoOnLink, handleOAuthUserInfo } from "../../oauth2/link-account.mjs";
|
|
7
|
+
import { generateState, parseState } from "../../oauth2/state.mjs";
|
|
6
8
|
import { OAUTH_CALLBACK_ERROR_CODES } from "../../oauth2/error-codes.mjs";
|
|
7
|
-
import { handleOAuthUserInfo } from "../../oauth2/link-account.mjs";
|
|
8
9
|
import { HIDE_METADATA } from "../../utils/hide-metadata.mjs";
|
|
9
10
|
import { safeJSONParse } from "@better-auth/core/utils/json";
|
|
10
11
|
import { createAuthEndpoint } from "@better-auth/core/api";
|
|
@@ -52,9 +53,21 @@ const callbackOAuth = createAuthEndpoint("/callback/:id", {
|
|
|
52
53
|
throw c.redirect(`${defaultErrorURL}?error=invalid_callback_request`);
|
|
53
54
|
}
|
|
54
55
|
const { code, error, state, error_description, device_id, user: userData, iss } = queryOrBody;
|
|
56
|
+
if (state === void 0 && code) {
|
|
57
|
+
const provider = await getAwaitableValue(c.context.socialProviders, { value: c.params.id });
|
|
58
|
+
if (provider?.allowIdpInitiated) {
|
|
59
|
+
const { state: freshState, codeVerifier } = await generateState(c, void 0, void 0);
|
|
60
|
+
const authUrl = await provider.createAuthorizationURL({
|
|
61
|
+
state: freshState,
|
|
62
|
+
codeVerifier,
|
|
63
|
+
redirectURI: `${c.context.baseURL}/callback/${provider.id}`
|
|
64
|
+
});
|
|
65
|
+
throw c.redirect(authUrl.toString());
|
|
66
|
+
}
|
|
67
|
+
}
|
|
55
68
|
if (!state) {
|
|
56
69
|
c.context.logger.error("State not found", error);
|
|
57
|
-
const url = `${defaultErrorURL}${defaultErrorURL.includes("?") ? "&" : "?"}
|
|
70
|
+
const url = `${defaultErrorURL}${defaultErrorURL.includes("?") ? "&" : "?"}error=state_not_found`;
|
|
58
71
|
throw c.redirect(url);
|
|
59
72
|
}
|
|
60
73
|
const { codeVerifier, callbackURL, link, errorURL, newUserURL, requestSignUp } = await parseState(c);
|
|
@@ -136,6 +149,7 @@ const callbackOAuth = createAuthEndpoint("/callback/:id", {
|
|
|
136
149
|
refreshToken: await setTokenUtil(tokens.refreshToken, c.context),
|
|
137
150
|
scope: tokens.scopes?.join(",")
|
|
138
151
|
})) return redirectOnError(OAUTH_CALLBACK_ERROR_CODES.UNABLE_TO_LINK_ACCOUNT);
|
|
152
|
+
await applyUpdateUserInfoOnLink(c, link.userId, userInfo);
|
|
139
153
|
let toRedirectTo;
|
|
140
154
|
try {
|
|
141
155
|
toRedirectTo = callbackURL.toString();
|
|
@@ -154,18 +168,24 @@ const callbackOAuth = createAuthEndpoint("/callback/:id", {
|
|
|
154
168
|
...tokens,
|
|
155
169
|
scope: tokens.scopes?.join(",")
|
|
156
170
|
};
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
171
|
+
let result;
|
|
172
|
+
try {
|
|
173
|
+
result = await handleOAuthUserInfo(c, {
|
|
174
|
+
userInfo: {
|
|
175
|
+
...userInfo,
|
|
176
|
+
id: providerAccountId,
|
|
177
|
+
email: userInfo.email,
|
|
178
|
+
name: userInfo.name || ""
|
|
179
|
+
},
|
|
180
|
+
account: accountData,
|
|
181
|
+
callbackURL,
|
|
182
|
+
disableSignUp: provider.disableImplicitSignUp && !requestSignUp || provider.options?.disableSignUp,
|
|
183
|
+
overrideUserInfo: provider.options?.overrideUserInfoOnSignIn
|
|
184
|
+
});
|
|
185
|
+
} catch (e) {
|
|
186
|
+
if (isAPIError(e) && e.body?.code) redirectOnError(e.body.code, e.body.message);
|
|
187
|
+
throw e;
|
|
188
|
+
}
|
|
169
189
|
if (result.error) {
|
|
170
190
|
c.context.logger.error(result.error.split(" ").join("_"));
|
|
171
191
|
return redirectOnError(result.error.split(" ").join("_"));
|
|
@@ -27,6 +27,7 @@ declare function sendVerificationEmailFn(ctx: GenericEndpointContext, user: User
|
|
|
27
27
|
declare const sendVerificationEmail: better_call0.StrictEndpoint<"/send-verification-email", {
|
|
28
28
|
method: "POST";
|
|
29
29
|
operationId: string;
|
|
30
|
+
cloneRequest: true;
|
|
30
31
|
body: z.ZodObject<{
|
|
31
32
|
email: z.ZodEmail;
|
|
32
33
|
callbackURL: z.ZodOptional<z.ZodString>;
|
|
@@ -31,11 +31,12 @@ async function sendVerificationEmailFn(ctx, user) {
|
|
|
31
31
|
user,
|
|
32
32
|
url,
|
|
33
33
|
token
|
|
34
|
-
}, ctx.request));
|
|
34
|
+
}, ctx.request?.clone()));
|
|
35
35
|
}
|
|
36
36
|
const sendVerificationEmail = createAuthEndpoint("/send-verification-email", {
|
|
37
37
|
method: "POST",
|
|
38
38
|
operationId: "sendVerificationEmail",
|
|
39
|
+
cloneRequest: true,
|
|
39
40
|
body: z.object({
|
|
40
41
|
email: z.email().meta({ description: "The email to send the verification email to" }),
|
|
41
42
|
callbackURL: z.string().meta({ description: "The URL to use for email verification callback" }).optional()
|
|
@@ -185,7 +186,7 @@ const verifyEmail = createAuthEndpoint("/verify-email", {
|
|
|
185
186
|
},
|
|
186
187
|
url,
|
|
187
188
|
token: newToken
|
|
188
|
-
}, ctx.request));
|
|
189
|
+
}, ctx.request?.clone()));
|
|
189
190
|
if (ctx.query.callbackURL) throw ctx.redirect(ctx.query.callbackURL);
|
|
190
191
|
return ctx.json({ status: true });
|
|
191
192
|
}
|
|
@@ -238,7 +239,7 @@ const verifyEmail = createAuthEndpoint("/verify-email", {
|
|
|
238
239
|
user: updatedUser,
|
|
239
240
|
url: `${ctx.context.baseURL}/verify-email?token=${newToken}&callbackURL=${updateCallbackURL}`,
|
|
240
241
|
token: newToken
|
|
241
|
-
}, ctx.request));
|
|
242
|
+
}, ctx.request?.clone()));
|
|
242
243
|
await setSessionCookie(ctx, {
|
|
243
244
|
session: activeSession.session,
|
|
244
245
|
user: {
|
|
@@ -161,7 +161,7 @@ const resetPassword = createAuthEndpoint("/reset-password", {
|
|
|
161
161
|
const user = await ctx.context.internalAdapter.findUserById(userId);
|
|
162
162
|
if (user) await ctx.context.options.emailAndPassword.onPasswordReset({ user }, ctx.request);
|
|
163
163
|
}
|
|
164
|
-
if (ctx.context.options.emailAndPassword?.revokeSessionsOnPasswordReset) await ctx.context.internalAdapter.
|
|
164
|
+
if (ctx.context.options.emailAndPassword?.revokeSessionsOnPasswordReset) await ctx.context.internalAdapter.deleteUserSessions(userId);
|
|
165
165
|
return ctx.json({ status: true });
|
|
166
166
|
});
|
|
167
167
|
const verifyPassword = createAuthEndpoint("/verify-password", {
|