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
|
@@ -129,12 +129,8 @@ const getSession = () => createAuthEndpoint("/get-session", {
|
|
|
129
129
|
const updateAge = cookieRefreshCache.updateAge * 1e3;
|
|
130
130
|
const shouldSkipSessionRefresh = await getShouldSkipSessionRefresh();
|
|
131
131
|
if (timeUntilExpiry < updateAge && !shouldSkipSessionRefresh) {
|
|
132
|
-
const newExpiresAt = getDate(ctx.context.options.session?.cookieCache?.maxAge || 300, "sec");
|
|
133
132
|
const refreshedSession = {
|
|
134
|
-
session: {
|
|
135
|
-
...session.session,
|
|
136
|
-
expiresAt: newExpiresAt
|
|
137
|
-
},
|
|
133
|
+
session: { ...session.session },
|
|
138
134
|
user: session.user,
|
|
139
135
|
updatedAt: Date.now()
|
|
140
136
|
};
|
|
@@ -276,17 +272,26 @@ const getSessionFromCtx = async (ctx, config) => {
|
|
|
276
272
|
method: "GET",
|
|
277
273
|
asResponse: false,
|
|
278
274
|
headers: ctx.headers,
|
|
279
|
-
returnHeaders:
|
|
275
|
+
returnHeaders: true,
|
|
280
276
|
returnStatus: false,
|
|
281
277
|
query: {
|
|
282
278
|
...config,
|
|
283
279
|
...ctx.query
|
|
284
280
|
}
|
|
285
|
-
}).catch((
|
|
281
|
+
}).catch(() => {
|
|
286
282
|
return null;
|
|
287
283
|
});
|
|
288
|
-
|
|
289
|
-
|
|
284
|
+
if (!session) {
|
|
285
|
+
ctx.context.session = null;
|
|
286
|
+
return null;
|
|
287
|
+
}
|
|
288
|
+
if (session.headers) session.headers.forEach((value, key) => {
|
|
289
|
+
if (!ctx.context.responseHeaders) ctx.context.responseHeaders = new Headers({ [key]: value });
|
|
290
|
+
else if (key.toLowerCase() === "set-cookie") ctx.context.responseHeaders.append(key, value);
|
|
291
|
+
else ctx.context.responseHeaders.set(key, value);
|
|
292
|
+
});
|
|
293
|
+
ctx.context.session = session.response;
|
|
294
|
+
return session.response;
|
|
290
295
|
};
|
|
291
296
|
/**
|
|
292
297
|
* The middleware forces the endpoint to require a valid session.
|
|
@@ -440,7 +445,7 @@ const revokeSessions = createAuthEndpoint("/revoke-sessions", {
|
|
|
440
445
|
} }
|
|
441
446
|
}, async (ctx) => {
|
|
442
447
|
try {
|
|
443
|
-
await ctx.context.internalAdapter.
|
|
448
|
+
await ctx.context.internalAdapter.deleteUserSessions(ctx.context.session.user.id);
|
|
444
449
|
} catch (error) {
|
|
445
450
|
ctx.context.logger.error(error && typeof error === "object" && "name" in error ? error.name : "", error);
|
|
446
451
|
throw APIError.from("INTERNAL_SERVER_ERROR", {
|
|
@@ -27,6 +27,7 @@ declare const socialSignInBodySchema: z.ZodObject<{
|
|
|
27
27
|
scopes: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
28
28
|
requestSignUp: z.ZodOptional<z.ZodBoolean>;
|
|
29
29
|
loginHint: z.ZodOptional<z.ZodString>;
|
|
30
|
+
additionalParams: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
|
|
30
31
|
additionalData: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodAny>>;
|
|
31
32
|
}, z.core.$strip>;
|
|
32
33
|
declare const signInSocial: <O extends BetterAuthOptions>() => better_call0.StrictEndpoint<"/sign-in/social", {
|
|
@@ -55,6 +56,7 @@ declare const signInSocial: <O extends BetterAuthOptions>() => better_call0.Stri
|
|
|
55
56
|
scopes: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
56
57
|
requestSignUp: z.ZodOptional<z.ZodBoolean>;
|
|
57
58
|
loginHint: z.ZodOptional<z.ZodString>;
|
|
59
|
+
additionalParams: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
|
|
58
60
|
additionalData: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodAny>>;
|
|
59
61
|
}, z.core.$strip>;
|
|
60
62
|
metadata: {
|
|
@@ -114,6 +116,7 @@ declare const signInEmail: <O extends BetterAuthOptions>() => better_call0.Stric
|
|
|
114
116
|
method: "POST";
|
|
115
117
|
operationId: string;
|
|
116
118
|
use: ((inputContext: better_call0.MiddlewareInputContext<better_call0.MiddlewareOptions>) => Promise<void>)[];
|
|
119
|
+
cloneRequest: true;
|
|
117
120
|
body: z.ZodObject<{
|
|
118
121
|
email: z.ZodString;
|
|
119
122
|
password: z.ZodString;
|
|
@@ -3,10 +3,11 @@ import { parseUserOutput } from "../../db/schema.mjs";
|
|
|
3
3
|
import { setSessionCookie } from "../../cookies/index.mjs";
|
|
4
4
|
import { getAwaitableValue } from "../../context/helpers.mjs";
|
|
5
5
|
import { missingEmailLogMessage } from "../../oauth2/errors.mjs";
|
|
6
|
-
import { generateState } from "../../oauth2/state.mjs";
|
|
7
6
|
import { handleOAuthUserInfo } from "../../oauth2/link-account.mjs";
|
|
7
|
+
import { generateState } from "../../oauth2/state.mjs";
|
|
8
8
|
import { createEmailVerificationToken } from "./email-verification.mjs";
|
|
9
9
|
import { APIError, BASE_ERROR_CODES } from "@better-auth/core/error";
|
|
10
|
+
import { additionalAuthorizationParamsSchema } from "@better-auth/core/oauth2";
|
|
10
11
|
import { SocialProviderListEnum } from "@better-auth/core/social-providers";
|
|
11
12
|
import { createAuthEndpoint } from "@better-auth/core/api";
|
|
12
13
|
import * as z from "zod";
|
|
@@ -34,6 +35,7 @@ const socialSignInBodySchema = z.object({
|
|
|
34
35
|
scopes: z.array(z.string()).meta({ description: "Array of scopes to request from the provider. This will override the default scopes passed." }).optional(),
|
|
35
36
|
requestSignUp: z.boolean().meta({ description: "Explicitly request sign-up. Useful when disableImplicitSignUp is true for this provider" }).optional(),
|
|
36
37
|
loginHint: z.string().meta({ description: "The login hint to use for the authorization code request" }).optional(),
|
|
38
|
+
additionalParams: additionalAuthorizationParamsSchema,
|
|
37
39
|
additionalData: z.record(z.string(), z.any()).optional().meta({ description: "Additional data to be passed through the OAuth flow" })
|
|
38
40
|
});
|
|
39
41
|
const signInSocial = () => createAuthEndpoint("/sign-in/social", {
|
|
@@ -132,7 +134,8 @@ const signInSocial = () => createAuthEndpoint("/sign-in/social", {
|
|
|
132
134
|
codeVerifier,
|
|
133
135
|
redirectURI: `${c.context.baseURL}/callback/${provider.id}`,
|
|
134
136
|
scopes: c.body.scopes,
|
|
135
|
-
loginHint: c.body.loginHint
|
|
137
|
+
loginHint: c.body.loginHint,
|
|
138
|
+
additionalParams: c.body.additionalParams
|
|
136
139
|
});
|
|
137
140
|
if (!c.body.disableRedirect) c.setHeader("Location", url.toString());
|
|
138
141
|
return c.json({
|
|
@@ -144,6 +147,7 @@ const signInEmail = () => createAuthEndpoint("/sign-in/email", {
|
|
|
144
147
|
method: "POST",
|
|
145
148
|
operationId: "signInEmail",
|
|
146
149
|
use: [formCsrfMiddleware],
|
|
150
|
+
cloneRequest: true,
|
|
147
151
|
body: z.object({
|
|
148
152
|
email: z.string().meta({ description: "Email of the user" }),
|
|
149
153
|
password: z.string().meta({ description: "Password of the user" }),
|
|
@@ -236,7 +240,7 @@ const signInEmail = () => createAuthEndpoint("/sign-in/email", {
|
|
|
236
240
|
user: user.user,
|
|
237
241
|
url,
|
|
238
242
|
token
|
|
239
|
-
}, ctx.request));
|
|
243
|
+
}, ctx.request?.clone()));
|
|
240
244
|
}
|
|
241
245
|
throw APIError.from("FORBIDDEN", BASE_ERROR_CODES.EMAIL_NOT_VERIFIED);
|
|
242
246
|
}
|
|
@@ -16,6 +16,7 @@ declare const signUpEmail: <O extends BetterAuthOptions>() => better_call0.Stric
|
|
|
16
16
|
callbackURL: z.ZodOptional<z.ZodString>;
|
|
17
17
|
rememberMe: z.ZodOptional<z.ZodBoolean>;
|
|
18
18
|
}, z.core.$strip>, z.ZodRecord<z.ZodString, z.ZodAny>>;
|
|
19
|
+
cloneRequest: true;
|
|
19
20
|
metadata: {
|
|
20
21
|
allowedMediaTypes: string[];
|
|
21
22
|
$Infer: {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { isAPIError } from "../../utils/is-api-error.mjs";
|
|
2
2
|
import { formCsrfMiddleware } from "../middlewares/origin-check.mjs";
|
|
3
|
-
import { parseUserInput, parseUserOutput } from "../../db/schema.mjs";
|
|
3
|
+
import { buildSyntheticUserOutput, parseUserInput, parseUserOutput } from "../../db/schema.mjs";
|
|
4
4
|
import { setSessionCookie } from "../../cookies/index.mjs";
|
|
5
5
|
import { createEmailVerificationToken } from "./email-verification.mjs";
|
|
6
6
|
import { runWithTransaction } from "@better-auth/core/context";
|
|
@@ -23,6 +23,7 @@ const signUpEmail = () => createAuthEndpoint("/sign-up/email", {
|
|
|
23
23
|
operationId: "signUpWithEmailAndPassword",
|
|
24
24
|
use: [formCsrfMiddleware],
|
|
25
25
|
body: signUpEmailBodySchema,
|
|
26
|
+
cloneRequest: true,
|
|
26
27
|
metadata: {
|
|
27
28
|
allowedMediaTypes: ["application/x-www-form-urlencoded", "application/json"],
|
|
28
29
|
$Infer: {
|
|
@@ -170,14 +171,14 @@ const signUpEmail = () => createAuthEndpoint("/sign-up/email", {
|
|
|
170
171
|
* between existing and non-existing emails.
|
|
171
172
|
*/
|
|
172
173
|
await ctx.context.password.hash(password);
|
|
173
|
-
if (ctx.context.options.emailAndPassword?.onExistingUserSignUp) await ctx.context.runInBackgroundOrAwait(ctx.context.options.emailAndPassword.onExistingUserSignUp({ user: dbUser.user }, ctx.request));
|
|
174
|
+
if (ctx.context.options.emailAndPassword?.onExistingUserSignUp) await ctx.context.runInBackgroundOrAwait(ctx.context.options.emailAndPassword.onExistingUserSignUp({ user: dbUser.user }, ctx.request?.clone()));
|
|
174
175
|
const now = /* @__PURE__ */ new Date();
|
|
175
176
|
const generatedId = ctx.context.generateId({ model: "user" }) || generateId();
|
|
176
177
|
const coreFields = {
|
|
177
178
|
name,
|
|
178
179
|
email: normalizedEmail,
|
|
179
180
|
emailVerified: false,
|
|
180
|
-
image: image
|
|
181
|
+
image: image ?? null,
|
|
181
182
|
createdAt: now,
|
|
182
183
|
updatedAt: now
|
|
183
184
|
};
|
|
@@ -187,16 +188,17 @@ const signUpEmail = () => createAuthEndpoint("/sign-up/email", {
|
|
|
187
188
|
const additionalFieldKeys = Object.keys(ctx.context.options.user?.additionalFields ?? {});
|
|
188
189
|
const additionalFields = {};
|
|
189
190
|
for (const key of additionalFieldKeys) if (key in additionalUserFields) additionalFields[key] = additionalUserFields[key];
|
|
190
|
-
|
|
191
|
+
const customResult = customSyntheticUser({
|
|
191
192
|
coreFields,
|
|
192
193
|
additionalFields,
|
|
193
194
|
id: generatedId
|
|
194
195
|
});
|
|
195
|
-
|
|
196
|
+
syntheticUser = buildSyntheticUserOutput(ctx.context.options, customResult);
|
|
197
|
+
} else syntheticUser = buildSyntheticUserOutput(ctx.context.options, {
|
|
196
198
|
...coreFields,
|
|
197
199
|
...additionalUserFields,
|
|
198
200
|
id: generatedId
|
|
199
|
-
};
|
|
201
|
+
});
|
|
200
202
|
return ctx.json({
|
|
201
203
|
token: null,
|
|
202
204
|
user: parseUserOutput(ctx.context.options, syntheticUser)
|
|
@@ -244,7 +246,7 @@ const signUpEmail = () => createAuthEndpoint("/sign-up/email", {
|
|
|
244
246
|
user: createdUser,
|
|
245
247
|
url,
|
|
246
248
|
token
|
|
247
|
-
}, ctx.request));
|
|
249
|
+
}, ctx.request?.clone()));
|
|
248
250
|
}
|
|
249
251
|
if (shouldSkipAutoSignIn) return ctx.json({
|
|
250
252
|
token: null,
|
|
@@ -168,7 +168,7 @@ const changePassword = createAuthEndpoint("/change-password", {
|
|
|
168
168
|
await ctx.context.internalAdapter.updateAccount(account.id, { password: passwordHash });
|
|
169
169
|
let token = null;
|
|
170
170
|
if (revokeOtherSessions) {
|
|
171
|
-
await ctx.context.internalAdapter.
|
|
171
|
+
await ctx.context.internalAdapter.deleteUserSessions(session.user.id);
|
|
172
172
|
const newSession = await ctx.context.internalAdapter.createSession(session.user.id);
|
|
173
173
|
if (!newSession) throw APIError.from("INTERNAL_SERVER_ERROR", BASE_ERROR_CODES.FAILED_TO_GET_SESSION);
|
|
174
174
|
await setSessionCookie(ctx, {
|
|
@@ -309,7 +309,7 @@ const deleteUser = createAuthEndpoint("/delete-user", {
|
|
|
309
309
|
const beforeDelete = ctx.context.options.user.deleteUser?.beforeDelete;
|
|
310
310
|
if (beforeDelete) await beforeDelete(session.user, ctx.request);
|
|
311
311
|
await ctx.context.internalAdapter.deleteUser(session.user.id);
|
|
312
|
-
await ctx.context.internalAdapter.
|
|
312
|
+
await ctx.context.internalAdapter.deleteUserSessions(session.user.id);
|
|
313
313
|
deleteSessionCookie(ctx);
|
|
314
314
|
const afterDelete = ctx.context.options.user.deleteUser?.afterDelete;
|
|
315
315
|
if (afterDelete) await afterDelete(session.user, ctx.request);
|
|
@@ -362,7 +362,7 @@ const deleteUserCallback = createAuthEndpoint("/delete-user/callback", {
|
|
|
362
362
|
const beforeDelete = ctx.context.options.user.deleteUser?.beforeDelete;
|
|
363
363
|
if (beforeDelete) await beforeDelete(session.user, ctx.request);
|
|
364
364
|
await ctx.context.internalAdapter.deleteUser(session.user.id);
|
|
365
|
-
await ctx.context.internalAdapter.
|
|
365
|
+
await ctx.context.internalAdapter.deleteUserSessions(session.user.id);
|
|
366
366
|
await ctx.context.internalAdapter.deleteAccounts(session.user.id);
|
|
367
367
|
await ctx.context.internalAdapter.deleteVerificationByIdentifier(`delete-account-${ctx.query.token}`);
|
|
368
368
|
deleteSessionCookie(ctx);
|
|
@@ -410,7 +410,7 @@ const changeEmail = createAuthEndpoint("/change-email", {
|
|
|
410
410
|
}, async (ctx) => {
|
|
411
411
|
if (!ctx.context.options.user?.changeEmail?.enabled) {
|
|
412
412
|
ctx.context.logger.error("Change email is disabled.");
|
|
413
|
-
throw APIError.
|
|
413
|
+
throw APIError.from("BAD_REQUEST", BASE_ERROR_CODES.CHANGE_EMAIL_DISABLED);
|
|
414
414
|
}
|
|
415
415
|
const newEmail = ctx.body.newEmail.toLowerCase();
|
|
416
416
|
if (newEmail === ctx.context.session.user.email) {
|
|
@@ -424,8 +424,8 @@ const changeEmail = createAuthEndpoint("/change-email", {
|
|
|
424
424
|
* email would later throw 400, leaking email existence.
|
|
425
425
|
*/
|
|
426
426
|
const canUpdateWithoutVerification = ctx.context.session.user.emailVerified !== true && ctx.context.options.user.changeEmail.updateEmailWithoutVerification;
|
|
427
|
-
const canSendConfirmation = ctx.context.session.user.emailVerified && ctx.context.options.user.changeEmail.sendChangeEmailConfirmation;
|
|
428
427
|
const canSendVerification = ctx.context.options.emailVerification?.sendVerificationEmail;
|
|
428
|
+
const canSendConfirmation = canSendVerification && ctx.context.session.user.emailVerified && ctx.context.options.user.changeEmail.sendChangeEmailConfirmation;
|
|
429
429
|
if (!canUpdateWithoutVerification && !canSendConfirmation && !canSendVerification) {
|
|
430
430
|
ctx.context.logger.error("Verification email isn't enabled.");
|
|
431
431
|
throw APIError.fromStatus("BAD_REQUEST", { message: "Verification email isn't enabled" });
|
|
@@ -449,7 +449,7 @@ const changeEmail = createAuthEndpoint("/change-email", {
|
|
|
449
449
|
});
|
|
450
450
|
if (canSendVerification) {
|
|
451
451
|
const token = await createEmailVerificationToken(ctx.context.secret, newEmail, void 0, ctx.context.options.emailVerification?.expiresIn);
|
|
452
|
-
const url = `${ctx.context.baseURL}/verify-email?token=${token}&callbackURL=${ctx.body.callbackURL || "/"}`;
|
|
452
|
+
const url = `${ctx.context.baseURL}/verify-email?token=${token}&callbackURL=${encodeURIComponent(ctx.body.callbackURL || "/")}`;
|
|
453
453
|
await ctx.context.runInBackgroundOrAwait(canSendVerification({
|
|
454
454
|
user: {
|
|
455
455
|
...ctx.context.session.user,
|
|
@@ -466,7 +466,7 @@ const changeEmail = createAuthEndpoint("/change-email", {
|
|
|
466
466
|
*/
|
|
467
467
|
if (canSendConfirmation) {
|
|
468
468
|
const token = await createEmailVerificationToken(ctx.context.secret, ctx.context.session.user.email, newEmail, ctx.context.options.emailVerification?.expiresIn, { requestType: "change-email-confirmation" });
|
|
469
|
-
const url = `${ctx.context.baseURL}/verify-email?token=${token}&callbackURL=${ctx.body.callbackURL || "/"}`;
|
|
469
|
+
const url = `${ctx.context.baseURL}/verify-email?token=${token}&callbackURL=${encodeURIComponent(ctx.body.callbackURL || "/")}`;
|
|
470
470
|
await ctx.context.runInBackgroundOrAwait(canSendConfirmation({
|
|
471
471
|
user: ctx.context.session.user,
|
|
472
472
|
newEmail,
|
|
@@ -480,7 +480,7 @@ const changeEmail = createAuthEndpoint("/change-email", {
|
|
|
480
480
|
throw APIError.fromStatus("BAD_REQUEST", { message: "Verification email isn't enabled" });
|
|
481
481
|
}
|
|
482
482
|
const token = await createEmailVerificationToken(ctx.context.secret, ctx.context.session.user.email, newEmail, ctx.context.options.emailVerification?.expiresIn, { requestType: "change-email-verification" });
|
|
483
|
-
const url = `${ctx.context.baseURL}/verify-email?token=${token}&callbackURL=${ctx.body.callbackURL || "/"}`;
|
|
483
|
+
const url = `${ctx.context.baseURL}/verify-email?token=${token}&callbackURL=${encodeURIComponent(ctx.body.callbackURL || "/")}`;
|
|
484
484
|
await ctx.context.runInBackgroundOrAwait(canSendVerification({
|
|
485
485
|
user: {
|
|
486
486
|
...ctx.context.session.user,
|
|
@@ -1,9 +1,10 @@
|
|
|
1
|
+
import { isSafeUrlScheme } from "@better-auth/core/utils/url";
|
|
1
2
|
//#region src/client/fetch-plugins.ts
|
|
2
3
|
const redirectPlugin = {
|
|
3
4
|
id: "redirect",
|
|
4
5
|
name: "Redirect",
|
|
5
6
|
hooks: { onSuccess(context) {
|
|
6
|
-
if (context.data?.url && context.data?.redirect) {
|
|
7
|
+
if (context.data?.url && context.data?.redirect && isSafeUrlScheme(context.data.url)) {
|
|
7
8
|
if (typeof window !== "undefined" && window.location) {
|
|
8
9
|
if (window.location) try {
|
|
9
10
|
window.location.href = context.data.url;
|
package/dist/client/index.d.mts
CHANGED
|
@@ -8,7 +8,7 @@ import { parseJSON } from "./parser.mjs";
|
|
|
8
8
|
import { AuthQueryAtom, useAuthQuery } from "./query.mjs";
|
|
9
9
|
import { SessionRefreshOptions, SessionResponse, createSessionRefreshManager } from "./session-refresh.mjs";
|
|
10
10
|
import { AuthClient, createAuthClient } from "./vanilla.mjs";
|
|
11
|
-
import { AccessControl, ArrayElement, Role, Statements, SubArray, Subset } from "../plugins/access/types.mjs";
|
|
11
|
+
import { AccessControl, ArrayElement, ExactRoleStatements, Role, RoleAuthorizeRequest, RoleInput, RoleStatements, Statements, SubArray, Subset } from "../plugins/access/types.mjs";
|
|
12
12
|
import { AuthorizeResponse, createAccessControl, role } from "../plugins/access/access.mjs";
|
|
13
13
|
import { OrganizationOptions } from "../plugins/organization/types.mjs";
|
|
14
14
|
import { InferInvitation, InferMember, InferOrganization, InferOrganizationRolesFromOption, InferOrganizationZodRolesFromOption, InferTeam, Invitation, InvitationInput, InvitationStatus, Member, MemberInput, Organization, OrganizationInput, OrganizationRole, OrganizationSchema, Team, TeamInput, TeamMember, TeamMemberInput, defaultRolesSchema, invitationSchema, invitationStatus, memberSchema, organizationRoleSchema, organizationSchema, roleSchema, teamMemberSchema, teamSchema } from "../plugins/organization/schema.mjs";
|
|
@@ -31,4 +31,4 @@ declare function InferAuth<O extends {
|
|
|
31
31
|
options: BetterAuthOptions;
|
|
32
32
|
}>(): O["options"];
|
|
33
33
|
//#endregion
|
|
34
|
-
export { AccessControl, ArrayElement, AuthClient, AuthQueryAtom, AuthorizeResponse, BetterAuthClientOptions, BetterAuthClientPlugin, BroadcastChannel, BroadcastListener, BroadcastMessage, CamelCase, ClientAtomListener, ClientStore, type DBPrimitive, DefaultOrganizationPlugin, DynamicAccessControlEndpoints, ExtractPluginField, type FocusListener, type FocusManager, HasRequiredKeys, InferActions, InferAdditionalFromClient, InferAuth, InferClientAPI, InferCtx, InferErrorCodes, InferInvitation, InferMember, InferOrganization, InferOrganizationRolesFromOption, InferOrganizationZodRolesFromOption, InferPlugin, InferPluginFieldFromTuple, InferRoute, InferRoutes, InferSessionFromClient, InferSignUpEmailCtx, InferTeam, InferUserFromClient, InferUserUpdateCtx, Invitation, InvitationInput, InvitationStatus, IsAny, IsSignal, Member, MemberInput, MergeRoutes, type OnlineListener, type OnlineManager, Organization, OrganizationCreator, OrganizationEndpoints, OrganizationInput, OrganizationOptions, OrganizationPlugin, OrganizationRole, OrganizationSchema, OverrideMerge, PathToObject, Prettify, PrettifyDeep, ProxyRequest, RequiredKeysOf, Role, SessionQueryParams, SessionRefreshOptions, SessionResponse, Statements, StripEmptyObjects, SubArray, Subset, Team, TeamEndpoints, TeamInput, TeamMember, TeamMemberInput, type UnionToIntersection, createAccessControl, createAuthClient, createSessionRefreshManager, defaultRolesSchema, getGlobalBroadcastChannel, getOrgAdapter, hasPermission, invitationSchema, invitationStatus, kBroadcastChannel, kFocusManager, kOnlineManager, memberSchema, organization, organizationRoleSchema, organizationSchema, parseJSON, parseRoles, role, roleSchema, teamMemberSchema, teamSchema, useAuthQuery };
|
|
34
|
+
export { AccessControl, ArrayElement, AuthClient, AuthQueryAtom, AuthorizeResponse, BetterAuthClientOptions, BetterAuthClientPlugin, BroadcastChannel, BroadcastListener, BroadcastMessage, CamelCase, ClientAtomListener, ClientStore, type DBPrimitive, DefaultOrganizationPlugin, DynamicAccessControlEndpoints, ExactRoleStatements, ExtractPluginField, type FocusListener, type FocusManager, HasRequiredKeys, InferActions, InferAdditionalFromClient, InferAuth, InferClientAPI, InferCtx, InferErrorCodes, InferInvitation, InferMember, InferOrganization, InferOrganizationRolesFromOption, InferOrganizationZodRolesFromOption, InferPlugin, InferPluginFieldFromTuple, InferRoute, InferRoutes, InferSessionFromClient, InferSignUpEmailCtx, InferTeam, InferUserFromClient, InferUserUpdateCtx, Invitation, InvitationInput, InvitationStatus, IsAny, IsSignal, Member, MemberInput, MergeRoutes, type OnlineListener, type OnlineManager, Organization, OrganizationCreator, OrganizationEndpoints, OrganizationInput, OrganizationOptions, OrganizationPlugin, OrganizationRole, OrganizationSchema, OverrideMerge, PathToObject, Prettify, PrettifyDeep, ProxyRequest, RequiredKeysOf, Role, RoleAuthorizeRequest, RoleInput, RoleStatements, SessionQueryParams, SessionRefreshOptions, SessionResponse, Statements, StripEmptyObjects, SubArray, Subset, Team, TeamEndpoints, TeamInput, TeamMember, TeamMemberInput, type UnionToIntersection, createAccessControl, createAuthClient, createSessionRefreshManager, defaultRolesSchema, getGlobalBroadcastChannel, getOrgAdapter, hasPermission, invitationSchema, invitationStatus, kBroadcastChannel, kFocusManager, kOnlineManager, memberSchema, organization, organizationRoleSchema, organizationSchema, parseJSON, parseRoles, role, roleSchema, teamMemberSchema, teamSchema, useAuthQuery };
|
package/dist/client/parser.mjs
CHANGED
|
@@ -34,7 +34,6 @@ function betterJSONParse(value, options = {}) {
|
|
|
34
34
|
const { strict = false, warnings = false, reviver, parseDates = true } = options;
|
|
35
35
|
if (typeof value !== "string") return value;
|
|
36
36
|
const trimmed = value.trim();
|
|
37
|
-
if (trimmed.length > 0 && trimmed[0] === "\"" && trimmed.endsWith("\"") && !trimmed.slice(1, -1).includes("\"")) return trimmed.slice(1, -1);
|
|
38
37
|
const lowerValue = trimmed.toLowerCase();
|
|
39
38
|
if (lowerValue.length <= 9 && lowerValue in SPECIAL_VALUES) return SPECIAL_VALUES[lowerValue];
|
|
40
39
|
if (!JSON_SIGNATURE.test(trimmed)) {
|
|
@@ -4,17 +4,6 @@ import { InferInvitation, InferMember, InferOrganization, InferOrganizationRoles
|
|
|
4
4
|
import { AdminOptions, InferAdminRolesFromOption, SessionWithImpersonatedBy, UserWithRole } from "../../plugins/admin/types.mjs";
|
|
5
5
|
import { schema } from "../../plugins/anonymous/schema.mjs";
|
|
6
6
|
import { AnonymousOptions, AnonymousSession, UserWithAnonymous } from "../../plugins/anonymous/types.mjs";
|
|
7
|
-
import { GenericOAuthConfig, GenericOAuthOptions } from "../../plugins/generic-oauth/types.mjs";
|
|
8
|
-
import { Auth0Options, auth0 } from "../../plugins/generic-oauth/providers/auth0.mjs";
|
|
9
|
-
import { GumroadOptions, gumroad } from "../../plugins/generic-oauth/providers/gumroad.mjs";
|
|
10
|
-
import { HubSpotOptions, hubspot } from "../../plugins/generic-oauth/providers/hubspot.mjs";
|
|
11
|
-
import { KeycloakOptions, keycloak } from "../../plugins/generic-oauth/providers/keycloak.mjs";
|
|
12
|
-
import { LineOptions, line } from "../../plugins/generic-oauth/providers/line.mjs";
|
|
13
|
-
import { MicrosoftEntraIdOptions, microsoftEntraId } from "../../plugins/generic-oauth/providers/microsoft-entra-id.mjs";
|
|
14
|
-
import { OktaOptions, okta } from "../../plugins/generic-oauth/providers/okta.mjs";
|
|
15
|
-
import { PatreonOptions, patreon } from "../../plugins/generic-oauth/providers/patreon.mjs";
|
|
16
|
-
import { SlackOptions, slack } from "../../plugins/generic-oauth/providers/slack.mjs";
|
|
17
|
-
import { BaseOAuthProviderOptions } from "../../plugins/generic-oauth/index.mjs";
|
|
18
7
|
import { JWKOptions, JWSAlgorithms, Jwk, JwtOptions, ResolvedSigningKey } from "../../plugins/jwt/types.mjs";
|
|
19
8
|
import { AuthorizationQuery, Client, CodeVerificationValue, OAuthAccessToken, OIDCMetadata, OIDCOptions, TokenBody } from "../../plugins/oidc-provider/types.mjs";
|
|
20
9
|
import { MULTI_SESSION_ERROR_CODES } from "../../plugins/multi-session/error-codes.mjs";
|
|
@@ -31,16 +20,13 @@ import { USERNAME_ERROR_CODES } from "../../plugins/username/error-codes.mjs";
|
|
|
31
20
|
import { ORGANIZATION_ERROR_CODES } from "../../plugins/organization/error-codes.mjs";
|
|
32
21
|
import { inferAdditionalFields } from "../../plugins/additional-fields/client.mjs";
|
|
33
22
|
import { ADMIN_ERROR_CODES } from "../../plugins/admin/error-codes.mjs";
|
|
34
|
-
import { adminClient } from "../../plugins/admin/client.mjs";
|
|
23
|
+
import { AdminClientOptions, adminClient } from "../../plugins/admin/client.mjs";
|
|
35
24
|
import { ANONYMOUS_ERROR_CODES } from "../../plugins/anonymous/error-codes.mjs";
|
|
36
25
|
import { anonymousClient } from "../../plugins/anonymous/client.mjs";
|
|
37
26
|
import { customSessionClient } from "../../plugins/custom-session/client.mjs";
|
|
38
27
|
import { deviceAuthorizationClient } from "../../plugins/device-authorization/client.mjs";
|
|
39
28
|
import { EMAIL_OTP_ERROR_CODES } from "../../plugins/email-otp/error-codes.mjs";
|
|
40
29
|
import { emailOTPClient } from "../../plugins/email-otp/client.mjs";
|
|
41
|
-
import { OAUTH_CALLBACK_ERROR_CODES } from "../../oauth2/error-codes.mjs";
|
|
42
|
-
import { GENERIC_OAUTH_ERROR_CODES } from "../../plugins/generic-oauth/error-codes.mjs";
|
|
43
|
-
import { genericOAuthClient } from "../../plugins/generic-oauth/client.mjs";
|
|
44
30
|
import { jwtClient } from "../../plugins/jwt/client.mjs";
|
|
45
31
|
import { LastLoginMethodClientConfig, lastLoginMethodClient } from "../../plugins/last-login-method/client.mjs";
|
|
46
32
|
import { magicLinkClient } from "../../plugins/magic-link/client.mjs";
|
|
@@ -48,10 +34,10 @@ import { multiSessionClient } from "../../plugins/multi-session/client.mjs";
|
|
|
48
34
|
import { OidcClientPlugin, oidcClient } from "../../plugins/oidc-provider/client.mjs";
|
|
49
35
|
import { GoogleOneTapActionOptions, GoogleOneTapOptions, GsiButtonConfiguration, oneTapClient } from "../../plugins/one-tap/client.mjs";
|
|
50
36
|
import { oneTimeTokenClient } from "../../plugins/one-time-token/client.mjs";
|
|
51
|
-
import { clientSideHasPermission, inferOrgAdditionalFields, organizationClient } from "../../plugins/organization/client.mjs";
|
|
37
|
+
import { OrganizationClientOptions, clientSideHasPermission, inferOrgAdditionalFields, organizationClient } from "../../plugins/organization/client.mjs";
|
|
52
38
|
import { PHONE_NUMBER_ERROR_CODES } from "../../plugins/phone-number/error-codes.mjs";
|
|
53
39
|
import { phoneNumberClient } from "../../plugins/phone-number/client.mjs";
|
|
54
40
|
import { siweClient } from "../../plugins/siwe/client.mjs";
|
|
55
41
|
import { usernameClient } from "../../plugins/username/client.mjs";
|
|
56
42
|
import { InferServerPlugin } from "./infer-plugin.mjs";
|
|
57
|
-
export { ADMIN_ERROR_CODES, ANONYMOUS_ERROR_CODES, AdminOptions, AnonymousOptions, AnonymousSession,
|
|
43
|
+
export { ADMIN_ERROR_CODES, ANONYMOUS_ERROR_CODES, AdminClientOptions, AdminOptions, AnonymousOptions, AnonymousSession, AuthorizationQuery, BackupCodeOptions, Client, CodeVerificationValue, EMAIL_OTP_ERROR_CODES, ExtractPluginField, type FieldAttributeToObject, GoogleOneTapActionOptions, GoogleOneTapOptions, GsiButtonConfiguration, HasRequiredKeys, InferAdminRolesFromOption, InferInvitation, InferMember, InferOrganization, InferOrganizationRolesFromOption, InferOrganizationZodRolesFromOption, InferPluginFieldFromTuple, InferServerPlugin, InferTeam, Invitation, InvitationInput, InvitationStatus, IsAny, JWKOptions, JWSAlgorithms, Jwk, JwtOptions, LastLoginMethodClientConfig, MULTI_SESSION_ERROR_CODES, Member, MemberInput, MultiSessionConfig, OAuthAccessToken, OIDCMetadata, OIDCOptions, ORGANIZATION_ERROR_CODES, OTPOptions, OidcClientPlugin, OneTimeTokenOptions, Organization, OrganizationClientOptions, OrganizationInput, OrganizationRole, OrganizationSchema, OverrideMerge, PHONE_NUMBER_ERROR_CODES, PhoneNumberOptions, Prettify, PrettifyDeep, type RemoveFieldsWithReturnedFalse, RequiredKeysOf, ResolvedSigningKey, SessionWithImpersonatedBy, StripEmptyObjects, TOTPOptions, TWO_FACTOR_ERROR_CODES, Team, TeamInput, TeamMember, TeamMemberInput, TokenBody, TwoFactorOptions, TwoFactorProvider, TwoFactorTable, USERNAME_ERROR_CODES, UnionToIntersection, UserWithAnonymous, UserWithPhoneNumber, UserWithRole, UserWithTwoFactor, adminClient, anonymousClient, backupCode2fa, clientSideHasPermission, customSessionClient, defaultRolesSchema, deviceAuthorizationClient, emailOTPClient, encodeBackupCodes, generateBackupCodes, getBackupCodes, inferAdditionalFields, inferOrgAdditionalFields, invitationSchema, invitationStatus, jwtClient, lastLoginMethodClient, magicLinkClient, memberSchema, multiSessionClient, oidcClient, oneTapClient, oneTimeTokenClient, organizationClient, organizationRoleSchema, organizationSchema, otp2fa, phoneNumberClient, roleSchema, schema, siweClient, teamMemberSchema, teamSchema, totp2fa, twoFactorClient, usernameClient, verifyBackupCode };
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { OAUTH_CALLBACK_ERROR_CODES } from "../../oauth2/error-codes.mjs";
|
|
2
1
|
import { inferAdditionalFields } from "../../plugins/additional-fields/client.mjs";
|
|
3
2
|
import { ADMIN_ERROR_CODES } from "../../plugins/admin/error-codes.mjs";
|
|
4
3
|
import { adminClient } from "../../plugins/admin/client.mjs";
|
|
@@ -8,8 +7,6 @@ import { customSessionClient } from "../../plugins/custom-session/client.mjs";
|
|
|
8
7
|
import { deviceAuthorizationClient } from "../../plugins/device-authorization/client.mjs";
|
|
9
8
|
import { EMAIL_OTP_ERROR_CODES } from "../../plugins/email-otp/error-codes.mjs";
|
|
10
9
|
import { emailOTPClient } from "../../plugins/email-otp/client.mjs";
|
|
11
|
-
import { GENERIC_OAUTH_ERROR_CODES } from "../../plugins/generic-oauth/error-codes.mjs";
|
|
12
|
-
import { genericOAuthClient } from "../../plugins/generic-oauth/client.mjs";
|
|
13
10
|
import { jwtClient } from "../../plugins/jwt/client.mjs";
|
|
14
11
|
import { lastLoginMethodClient } from "../../plugins/last-login-method/client.mjs";
|
|
15
12
|
import { magicLinkClient } from "../../plugins/magic-link/client.mjs";
|
|
@@ -28,4 +25,4 @@ import { twoFactorClient } from "../../plugins/two-factor/client.mjs";
|
|
|
28
25
|
import { USERNAME_ERROR_CODES } from "../../plugins/username/error-codes.mjs";
|
|
29
26
|
import { usernameClient } from "../../plugins/username/client.mjs";
|
|
30
27
|
import { InferServerPlugin } from "./infer-plugin.mjs";
|
|
31
|
-
export { ADMIN_ERROR_CODES, ANONYMOUS_ERROR_CODES, EMAIL_OTP_ERROR_CODES,
|
|
28
|
+
export { ADMIN_ERROR_CODES, ANONYMOUS_ERROR_CODES, EMAIL_OTP_ERROR_CODES, InferServerPlugin, MULTI_SESSION_ERROR_CODES, ORGANIZATION_ERROR_CODES, PHONE_NUMBER_ERROR_CODES, TWO_FACTOR_ERROR_CODES, USERNAME_ERROR_CODES, adminClient, anonymousClient, clientSideHasPermission, customSessionClient, deviceAuthorizationClient, emailOTPClient, inferAdditionalFields, inferOrgAdditionalFields, jwtClient, lastLoginMethodClient, magicLinkClient, multiSessionClient, oidcClient, oneTapClient, oneTimeTokenClient, organizationClient, phoneNumberClient, siweClient, twoFactorClient, usernameClient };
|
package/dist/client/proxy.mjs
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { isAtom } from "../utils/is-atom.mjs";
|
|
2
|
+
import { toKebabCase } from "@better-auth/core/utils/string";
|
|
2
3
|
//#region src/client/proxy.ts
|
|
3
4
|
function getMethod(path, knownPathMethods, args) {
|
|
4
5
|
const method = knownPathMethods[path];
|
|
@@ -26,7 +27,7 @@ function createDynamicPathProxy(routes, client, knownPathMethods, atoms, atomLis
|
|
|
26
27
|
return createProxy(fullPath);
|
|
27
28
|
},
|
|
28
29
|
apply: async (_, __, args) => {
|
|
29
|
-
const routePath = "/" + path.map(
|
|
30
|
+
const routePath = "/" + path.map(toKebabCase).join("/");
|
|
30
31
|
const arg = args[0] || {};
|
|
31
32
|
const fetchOptions = args[1] || {};
|
|
32
33
|
const { query, fetchOptions: argFetchOptions, ...body } = arg;
|
|
@@ -42,18 +42,14 @@ function validateSecret(secret, logger) {
|
|
|
42
42
|
if (estimateEntropy(secret) < 120) logger.warn("[better-auth] Warning: your BETTER_AUTH_SECRET appears low-entropy. Use a randomly generated secret for production.");
|
|
43
43
|
}
|
|
44
44
|
async function createAuthContext(adapter, options, getDatabaseType) {
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
storeStateStrategy: "cookie",
|
|
54
|
-
storeAccountCookie: true
|
|
55
|
-
}
|
|
56
|
-
});
|
|
45
|
+
const isStateful = !!options.database || !!options.secondaryStorage;
|
|
46
|
+
if (!isStateful) options = defu$1(options, { session: { cookieCache: {
|
|
47
|
+
enabled: true,
|
|
48
|
+
strategy: "jwe",
|
|
49
|
+
refreshCache: true,
|
|
50
|
+
maxAge: options.session?.expiresIn || 3600 * 24 * 7
|
|
51
|
+
} } });
|
|
52
|
+
if (!options.database) options = defu$1(options, { account: { storeAccountCookie: true } });
|
|
57
53
|
const plugins = options.plugins || [];
|
|
58
54
|
const internalPlugins = getInternalPlugins(options);
|
|
59
55
|
const logger = createLogger(options.logger);
|
|
@@ -130,7 +126,7 @@ Most of the features of Better Auth will not work correctly.`);
|
|
|
130
126
|
socialProviders: providers,
|
|
131
127
|
options,
|
|
132
128
|
oauthConfig: {
|
|
133
|
-
storeStateStrategy: options.account?.storeStateStrategy || (
|
|
129
|
+
storeStateStrategy: options.account?.storeStateStrategy || (isStateful ? "database" : "cookie"),
|
|
134
130
|
skipStateCookieCheck: !!options.account?.skipStateCookieCheck
|
|
135
131
|
},
|
|
136
132
|
tables,
|
|
@@ -146,7 +142,7 @@ Most of the features of Better Auth will not work correctly.`);
|
|
|
146
142
|
cookieRefreshCache: (() => {
|
|
147
143
|
const refreshCache = options.session?.cookieCache?.refreshCache;
|
|
148
144
|
const maxAge = options.session?.cookieCache?.maxAge || 300;
|
|
149
|
-
if (
|
|
145
|
+
if (isStateful && refreshCache) {
|
|
150
146
|
logger.warn("[better-auth] `session.cookieCache.refreshCache` is enabled while `database` or `secondaryStorage` is configured. `refreshCache` is meant for stateless (DB-less) setups. Disabling `refreshCache` — remove it from your config to silence this warning.");
|
|
151
147
|
return false;
|
|
152
148
|
}
|
package/dist/context/helpers.mjs
CHANGED
|
@@ -61,9 +61,10 @@ async function getTrustedOrigins(options, request) {
|
|
|
61
61
|
const trustedOrigins = [];
|
|
62
62
|
if (isDynamicBaseURLConfig(options.baseURL)) {
|
|
63
63
|
const allowedHosts = options.baseURL.allowedHosts;
|
|
64
|
+
const proto = options.baseURL.protocol;
|
|
64
65
|
for (const host of allowedHosts) if (!host.includes("://")) {
|
|
65
|
-
trustedOrigins.push(`https://${host}`);
|
|
66
|
-
if (isLoopbackHost(host)) trustedOrigins.push(`http://${host}`);
|
|
66
|
+
if (!proto || proto === "https" || proto === "auto") trustedOrigins.push(`https://${host}`);
|
|
67
|
+
if (proto === "http" || proto === "auto" || isLoopbackHost(host)) trustedOrigins.push(`http://${host}`);
|
|
67
68
|
} else trustedOrigins.push(host);
|
|
68
69
|
if (options.baseURL.fallback) try {
|
|
69
70
|
trustedOrigins.push(new URL(options.baseURL.fallback).origin);
|
|
@@ -33,6 +33,20 @@ declare function stripSecureCookiePrefix(cookieName: string): string;
|
|
|
33
33
|
declare function splitSetCookieHeader(setCookie: string): string[];
|
|
34
34
|
declare function parseSetCookieHeader(setCookie: string): Map<string, CookieAttributes>;
|
|
35
35
|
declare function toCookieOptions(attributes: CookieAttributes): ParsedCookieOptions;
|
|
36
|
+
/**
|
|
37
|
+
* Cookie-name token char set per RFC 7230 §3.2.6.
|
|
38
|
+
*
|
|
39
|
+
* @see https://datatracker.ietf.org/doc/html/rfc7230#section-3.2.6
|
|
40
|
+
*/
|
|
41
|
+
declare const cookieNameRegex: RegExp;
|
|
42
|
+
/**
|
|
43
|
+
* Tolerates `;` separators without the SP that RFC 6265 §4.2.1 mandates,
|
|
44
|
+
* since proxies and runtimes commonly strip it. Silently drops entries
|
|
45
|
+
* whose name violates RFC 7230 token or whose value violates RFC 6265
|
|
46
|
+
* cookie-octet (plus space and comma). Strips optional surrounding
|
|
47
|
+
* double-quotes per RFC 6265 §4.1.1.
|
|
48
|
+
*/
|
|
49
|
+
declare function parseCookies(cookie: string): Map<string, string>;
|
|
36
50
|
/**
|
|
37
51
|
* Add or replace a cookie in the request `Cookie` header.
|
|
38
52
|
*
|
|
@@ -42,8 +56,17 @@ declare function toCookieOptions(attributes: CookieAttributes): ParsedCookieOpti
|
|
|
42
56
|
* parse-mutate-serialize.
|
|
43
57
|
*/
|
|
44
58
|
declare function setRequestCookie(headers: Headers, name: string, value: string): void;
|
|
59
|
+
/**
|
|
60
|
+
* Merge `Set-Cookie` header values into the target's `Cookie` header.
|
|
61
|
+
* Mutates `target`.
|
|
62
|
+
*
|
|
63
|
+
* Name/value-level merge only. RFC 6265 §5 user-agent semantics
|
|
64
|
+
* (expiration, domain/path scoping, ordering) are out of scope. Suitable
|
|
65
|
+
* for single-request proxy, middleware, and test contexts.
|
|
66
|
+
*/
|
|
67
|
+
declare function applySetCookies(target: Headers, setCookieValues: Iterable<string>): void;
|
|
45
68
|
declare function setCookieToHeader(headers: Headers): (context: {
|
|
46
69
|
response: Response;
|
|
47
70
|
}) => void;
|
|
48
71
|
//#endregion
|
|
49
|
-
export { CookieAttributes, HOST_COOKIE_PREFIX, SECURE_COOKIE_PREFIX, parseSetCookieHeader, setCookieToHeader, setRequestCookie, splitSetCookieHeader, stripSecureCookiePrefix, toCookieOptions };
|
|
72
|
+
export { CookieAttributes, HOST_COOKIE_PREFIX, SECURE_COOKIE_PREFIX, applySetCookies, cookieNameRegex, parseCookies, parseSetCookieHeader, setCookieToHeader, setRequestCookie, splitSetCookieHeader, stripSecureCookiePrefix, toCookieOptions };
|