better-auth 1.7.11 → 1.7.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/adapters/index.d.mts +5 -10
- package/dist/api/dispatch.d.mts +3 -5
- package/dist/api/dispatch.mjs +6 -4
- package/dist/api/index.d.mts +506 -508
- package/dist/api/index.mjs +35 -34
- package/dist/api/middlewares/authorization.d.mts +15 -12
- package/dist/api/middlewares/authorization.mjs +2 -1
- package/dist/api/middlewares/index.d.mts +2 -1
- package/dist/api/middlewares/origin-check.d.mts +4 -7
- package/dist/api/routes/account.d.mts +11 -15
- package/dist/api/routes/account.mjs +7 -4
- package/dist/api/routes/callback.d.mts +2 -5
- package/dist/api/routes/callback.mjs +14 -53
- package/dist/api/routes/email-verification.d.mts +7 -12
- package/dist/api/routes/error.d.mts +2 -5
- package/dist/api/routes/index.d.mts +2 -1
- package/dist/api/routes/ok.d.mts +2 -5
- package/dist/api/routes/password.d.mts +8 -11
- package/dist/api/routes/password.mjs +3 -2
- package/dist/api/routes/session.d.mts +26 -29
- package/dist/api/routes/session.mjs +1 -1
- package/dist/api/routes/sign-in.d.mts +4 -6
- package/dist/api/routes/sign-out.d.mts +2 -5
- package/dist/api/routes/sign-up.d.mts +4 -6
- package/dist/api/routes/update-session.d.mts +4 -6
- package/dist/api/routes/update-user.d.mts +14 -16
- package/dist/api/routes/update-user.mjs +1 -1
- package/dist/api/state/oauth.d.mts +0 -3
- package/dist/api/state/oauth.mjs +2 -1
- package/dist/auth/full.d.mts +3 -4
- package/dist/auth/minimal.d.mts +3 -3
- package/dist/client/broadcast-channel.d.mts +6 -7
- package/dist/client/config.d.mts +15 -19
- package/dist/client/config.mjs +2 -2
- package/dist/client/equality.d.mts +3 -5
- package/dist/client/focus-manager.d.mts +4 -5
- package/dist/client/index.d.mts +8 -7
- package/dist/client/lynx/index.d.mts +6 -7
- package/dist/client/lynx/index.mjs +3 -2
- package/dist/client/lynx/lynx-store.d.mts +3 -4
- package/dist/client/online-manager.d.mts +4 -5
- package/dist/client/parser.d.mts +9 -5
- package/dist/client/path-to-object.d.mts +13 -14
- package/dist/client/plugins/index.d.mts +1 -1
- package/dist/client/plugins/infer-plugin.d.mts +2 -4
- package/dist/client/query.d.mts +4 -6
- package/dist/client/react/index.d.mts +6 -7
- package/dist/client/react/index.mjs +3 -2
- package/dist/client/react/react-store.d.mts +3 -4
- package/dist/client/session-atom.d.mts +4 -4
- package/dist/client/session-refresh.d.mts +3 -5
- package/dist/client/solid/index.d.mts +6 -7
- package/dist/client/solid/index.mjs +3 -2
- package/dist/client/svelte/index.d.mts +6 -7
- package/dist/client/svelte/index.mjs +3 -2
- package/dist/client/types.d.mts +11 -11
- package/dist/client/vanilla.d.mts +4 -5
- package/dist/client/vanilla.mjs +3 -2
- package/dist/client/vue/index.d.mts +6 -7
- package/dist/client/vue/index.mjs +3 -2
- package/dist/context/create-context.mjs +7 -7
- package/dist/context/helpers.mjs +9 -7
- package/dist/cookies/cookie-utils.d.mts +13 -13
- package/dist/cookies/cookie-utils.mjs +1 -3
- package/dist/cookies/index.d.mts +17 -18
- package/dist/cookies/index.mjs +11 -7
- package/dist/cookies/jwt.mjs +2 -1
- package/dist/cookies/session-store.d.mts +6 -5
- package/dist/cookies/session-store.mjs +3 -2
- package/dist/crypto/buffer.d.mts +2 -3
- package/dist/crypto/index.d.mts +9 -16
- package/dist/crypto/index.mjs +2 -1
- package/dist/crypto/jwt.d.mts +5 -7
- package/dist/crypto/jwt.mjs +2 -1
- package/dist/crypto/password.d.mts +1 -5
- package/dist/crypto/random.d.mts +2 -3
- package/dist/db/adapter-base.d.mts +2 -4
- package/dist/db/adapter-kysely.d.mts +2 -4
- package/dist/db/field-converter.d.mts +3 -5
- package/dist/db/field.d.mts +11 -12
- package/dist/db/get-migration.d.mts +4 -8
- package/dist/db/get-migration.mjs +22 -22
- package/dist/db/get-schema.d.mts +2 -4
- package/dist/db/internal-adapter.d.mts +2 -4
- package/dist/db/internal-adapter.mjs +6 -4
- package/dist/db/revoke-unproven-account-access.d.mts +3 -4
- package/dist/db/schema.d.mts +15 -16
- package/dist/db/schema.mjs +6 -3
- package/dist/db/to-zod.d.mts +5 -9
- package/dist/db/with-hooks.d.mts +3 -5
- package/dist/index.d.mts +4 -3
- package/dist/integrations/next-js.d.mts +7 -11
- package/dist/integrations/node.d.mts +5 -7
- package/dist/integrations/node.mjs +4 -2
- package/dist/integrations/solid-start.d.mts +2 -3
- package/dist/integrations/svelte-kit.d.mts +6 -14
- package/dist/integrations/tanstack-start-solid.d.mts +4 -8
- package/dist/integrations/tanstack-start.d.mts +4 -8
- package/dist/oauth2/callback.mjs +68 -0
- package/dist/oauth2/link-account.d.mts +5 -11
- package/dist/oauth2/link-account.mjs +12 -6
- package/dist/oauth2/state.d.mts +5 -7
- package/dist/oauth2/state.mjs +1 -1
- package/dist/oauth2/utils.d.mts +4 -6
- package/dist/package.mjs +1 -1
- package/dist/plugins/access/access.d.mts +4 -6
- package/dist/plugins/access/index.mjs +1 -2
- package/dist/plugins/access/types.d.mts +12 -14
- package/dist/plugins/additional-fields/client.d.mts +2 -4
- package/dist/plugins/admin/access/index.mjs +1 -2
- package/dist/plugins/admin/access/statement.d.mts +7 -7
- package/dist/plugins/admin/admin.d.mts +122 -128
- package/dist/plugins/admin/client.d.mts +32 -32
- package/dist/plugins/admin/client.mjs +1 -1
- package/dist/plugins/admin/error-codes.d.mts +25 -28
- package/dist/plugins/admin/index.d.mts +1 -1
- package/dist/plugins/admin/index.mjs +1 -2
- package/dist/plugins/admin/schema.d.mts +3 -4
- package/dist/plugins/admin/types.d.mts +8 -8
- package/dist/plugins/anonymous/client.d.mts +10 -12
- package/dist/plugins/anonymous/client.mjs +1 -1
- package/dist/plugins/anonymous/error-codes.d.mts +10 -13
- package/dist/plugins/anonymous/index.d.mts +17 -21
- package/dist/plugins/anonymous/schema.d.mts +2 -3
- package/dist/plugins/anonymous/types.d.mts +5 -6
- package/dist/plugins/bearer/index.d.mts +7 -11
- package/dist/plugins/captcha/constants.d.mts +2 -3
- package/dist/plugins/captcha/index.d.mts +6 -9
- package/dist/plugins/captcha/types.d.mts +11 -13
- package/dist/plugins/custom-session/client.d.mts +2 -4
- package/dist/plugins/custom-session/index.d.mts +10 -16
- package/dist/plugins/device-authorization/client.d.mts +2 -4
- package/dist/plugins/device-authorization/index.d.mts +39 -44
- package/dist/plugins/device-authorization/index.mjs +10 -9
- package/dist/plugins/device-authorization/routes.d.mts +7 -5
- package/dist/plugins/device-authorization/routes.mjs +6 -5
- package/dist/plugins/device-authorization/schema.d.mts +2 -3
- package/dist/plugins/email-otp/client.d.mts +5 -7
- package/dist/plugins/email-otp/client.mjs +1 -1
- package/dist/plugins/email-otp/error-codes.d.mts +5 -8
- package/dist/plugins/email-otp/index.d.mts +69 -76
- package/dist/plugins/email-otp/otp-token.mjs +19 -7
- package/dist/plugins/email-otp/types.d.mts +2 -4
- package/dist/plugins/generic-oauth/index.d.mts +9 -13
- package/dist/plugins/generic-oauth/index.mjs +6 -4
- package/dist/plugins/generic-oauth/providers/auth0.d.mts +3 -5
- package/dist/plugins/generic-oauth/providers/gumroad.d.mts +3 -5
- package/dist/plugins/generic-oauth/providers/hubspot.d.mts +3 -5
- package/dist/plugins/generic-oauth/providers/hubspot.mjs +2 -1
- package/dist/plugins/generic-oauth/providers/index.d.mts +2 -1
- package/dist/plugins/generic-oauth/providers/keycloak.d.mts +3 -5
- package/dist/plugins/generic-oauth/providers/line.d.mts +3 -5
- package/dist/plugins/generic-oauth/providers/microsoft-entra-id.d.mts +3 -5
- package/dist/plugins/generic-oauth/providers/okta.d.mts +3 -5
- package/dist/plugins/generic-oauth/providers/patreon.d.mts +3 -5
- package/dist/plugins/generic-oauth/providers/slack.d.mts +3 -5
- package/dist/plugins/generic-oauth/providers/yandex.d.mts +3 -5
- package/dist/plugins/generic-oauth/types.d.mts +6 -7
- package/dist/plugins/haveibeenpwned/index.d.mts +7 -11
- package/dist/plugins/index.d.mts +4 -1
- package/dist/plugins/jwt/adapter.mjs +14 -3
- package/dist/plugins/jwt/client.d.mts +2 -3
- package/dist/plugins/jwt/cookie-cache.mjs +3 -8
- package/dist/plugins/jwt/index.d.mts +11 -14
- package/dist/plugins/jwt/index.mjs +3 -3
- package/dist/plugins/jwt/schema.d.mts +2 -3
- package/dist/plugins/jwt/sign.d.mts +9 -8
- package/dist/plugins/jwt/sign.mjs +6 -5
- package/dist/plugins/jwt/types.d.mts +7 -8
- package/dist/plugins/jwt/utils.d.mts +6 -9
- package/dist/plugins/jwt/verify.d.mts +2 -4
- package/dist/plugins/jwt/verify.mjs +10 -4
- package/dist/plugins/last-login-method/client.d.mts +3 -4
- package/dist/plugins/last-login-method/index.d.mts +5 -9
- package/dist/plugins/last-login-method/index.mjs +1 -1
- package/dist/plugins/magic-link/client.d.mts +2 -4
- package/dist/plugins/magic-link/index.d.mts +7 -10
- package/dist/plugins/magic-link/index.mjs +20 -17
- package/dist/plugins/multi-session/client.d.mts +3 -5
- package/dist/plugins/multi-session/client.mjs +1 -1
- package/dist/plugins/multi-session/error-codes.d.mts +3 -6
- package/dist/plugins/multi-session/index.d.mts +10 -14
- package/dist/plugins/oauth-popup/client.d.mts +11 -17
- package/dist/plugins/oauth-popup/client.mjs +6 -4
- package/dist/plugins/oauth-popup/constants.d.mts +5 -6
- package/dist/plugins/oauth-popup/error-codes.d.mts +6 -9
- package/dist/plugins/oauth-popup/index.d.mts +11 -15
- package/dist/plugins/oauth-popup/index.mjs +8 -7
- package/dist/plugins/oauth-popup/types.d.mts +4 -6
- package/dist/plugins/oauth-proxy/index.d.mts +11 -15
- package/dist/plugins/oauth-proxy/index.mjs +24 -48
- package/dist/plugins/one-tap/client.d.mts +6 -9
- package/dist/plugins/one-tap/index.d.mts +4 -7
- package/dist/plugins/one-time-token/client.d.mts +2 -3
- package/dist/plugins/one-time-token/index.d.mts +8 -10
- package/dist/plugins/open-api/generator.d.mts +8 -8
- package/dist/plugins/open-api/generator.mjs +5 -5
- package/dist/plugins/open-api/index.d.mts +5 -7
- package/dist/plugins/organization/access/index.mjs +1 -2
- package/dist/plugins/organization/access/statement.d.mts +8 -8
- package/dist/plugins/organization/adapter.d.mts +60 -87
- package/dist/plugins/organization/adapter.mjs +14 -10
- package/dist/plugins/organization/client.d.mts +108 -107
- package/dist/plugins/organization/client.mjs +9 -5
- package/dist/plugins/organization/error-codes.d.mts +61 -64
- package/dist/plugins/organization/has-permission.d.mts +2 -4
- package/dist/plugins/organization/has-permission.mjs +1 -1
- package/dist/plugins/organization/index.d.mts +1 -1
- package/dist/plugins/organization/organization.d.mts +20 -20
- package/dist/plugins/organization/organization.mjs +13 -8
- package/dist/plugins/organization/permission.d.mts +4 -5
- package/dist/plugins/organization/routes/crud-access-control.d.mts +28 -28
- package/dist/plugins/organization/routes/crud-invites.d.mts +64 -65
- package/dist/plugins/organization/routes/crud-invites.mjs +21 -18
- package/dist/plugins/organization/routes/crud-members.d.mts +53 -56
- package/dist/plugins/organization/routes/crud-members.mjs +23 -21
- package/dist/plugins/organization/routes/crud-org.d.mts +63 -65
- package/dist/plugins/organization/routes/crud-org.mjs +4 -2
- package/dist/plugins/organization/routes/crud-team.d.mts +65 -66
- package/dist/plugins/organization/routes/crud-team.mjs +4 -2
- package/dist/plugins/organization/schema.d.mts +33 -33
- package/dist/plugins/organization/schema.mjs +1 -1
- package/dist/plugins/organization/types.d.mts +16 -17
- package/dist/plugins/phone-number/client.d.mts +14 -16
- package/dist/plugins/phone-number/client.mjs +1 -1
- package/dist/plugins/phone-number/error-codes.d.mts +14 -17
- package/dist/plugins/phone-number/index.d.mts +48 -54
- package/dist/plugins/phone-number/schema.d.mts +2 -3
- package/dist/plugins/phone-number/types.d.mts +4 -5
- package/dist/plugins/siwe/client.d.mts +2 -4
- package/dist/plugins/siwe/index.d.mts +7 -9
- package/dist/plugins/siwe/index.mjs +1 -1
- package/dist/plugins/siwe/parse-message.mjs +1 -3
- package/dist/plugins/siwe/schema.d.mts +3 -4
- package/dist/plugins/siwe/types.d.mts +4 -4
- package/dist/plugins/test-utils/auth-helpers.mjs +4 -2
- package/dist/plugins/test-utils/index.d.mts +3 -5
- package/dist/plugins/test-utils/types.d.mts +7 -7
- package/dist/plugins/two-factor/backup-codes/index.d.mts +11 -14
- package/dist/plugins/two-factor/backup-codes/index.mjs +12 -6
- package/dist/plugins/two-factor/client.d.mts +16 -19
- package/dist/plugins/two-factor/client.mjs +1 -1
- package/dist/plugins/two-factor/constant.mjs +1 -1
- package/dist/plugins/two-factor/error-code.d.mts +15 -18
- package/dist/plugins/two-factor/index.d.mts +31 -35
- package/dist/plugins/two-factor/index.mjs +6 -3
- package/dist/plugins/two-factor/otp/index.d.mts +5 -8
- package/dist/plugins/two-factor/otp/index.mjs +159 -154
- package/dist/plugins/two-factor/schema.d.mts +2 -3
- package/dist/plugins/two-factor/totp/index.d.mts +7 -10
- package/dist/plugins/two-factor/totp/index.mjs +153 -148
- package/dist/plugins/two-factor/types.d.mts +6 -7
- package/dist/plugins/username/client.d.mts +12 -14
- package/dist/plugins/username/client.mjs +1 -1
- package/dist/plugins/username/error-codes.d.mts +11 -14
- package/dist/plugins/username/index.d.mts +26 -31
- package/dist/plugins/username/schema.d.mts +7 -10
- package/dist/state.d.mts +4 -5
- package/dist/test-utils/headers.d.mts +2 -3
- package/dist/test-utils/http-test-instance.d.mts +26 -29
- package/dist/test-utils/test-instance.d.mts +7 -6
- package/dist/test-utils/test-instance.mjs +4 -2
- package/dist/types/adapter.d.mts +1 -1
- package/dist/types/api.d.mts +4 -6
- package/dist/types/auth.d.mts +2 -4
- package/dist/types/helper.d.mts +11 -12
- package/dist/types/index.d.mts +2 -2
- package/dist/types/models.d.mts +4 -5
- package/dist/types/plugins.d.mts +7 -8
- package/dist/utils/hide-metadata.d.mts +2 -3
- package/dist/utils/index.d.mts +2 -1
- package/dist/utils/is-api-error.mjs +1 -2
- package/dist/utils/time.d.mts +4 -4
- package/dist/utils/url.d.mts +13 -15
- package/dist/utils/wildcard.mjs +5 -3
- package/package.json +13 -13
|
@@ -1,6 +1,3 @@
|
|
|
1
|
-
import * as _$_better_auth_core0 from "@better-auth/core";
|
|
2
|
-
import * as _$better_call0 from "better-call";
|
|
3
|
-
|
|
4
1
|
//#region src/integrations/tanstack-start.d.ts
|
|
5
2
|
/**
|
|
6
3
|
* TanStack Start cookie plugin for React.
|
|
@@ -19,15 +16,14 @@ import * as _$better_call0 from "better-call";
|
|
|
19
16
|
* });
|
|
20
17
|
* ```
|
|
21
18
|
*/
|
|
22
|
-
declare const tanstackStartCookies: () => {
|
|
19
|
+
export declare const tanstackStartCookies: () => {
|
|
23
20
|
id: "tanstack-start-cookies";
|
|
24
21
|
version: string;
|
|
25
22
|
hooks: {
|
|
26
23
|
after: {
|
|
27
|
-
matcher(ctx:
|
|
28
|
-
handler:
|
|
24
|
+
matcher(ctx: import("@better-auth/core").HookEndpointContext): true;
|
|
25
|
+
handler: import("better-call").Middleware<import("better-call").MiddlewareOptions, (inputContext: import("better-call").MiddlewareInputContext<import("better-call").MiddlewareOptions>) => Promise<void>>;
|
|
29
26
|
}[];
|
|
30
27
|
};
|
|
31
28
|
};
|
|
32
|
-
//#endregion
|
|
33
|
-
export { tanstackStartCookies };
|
|
29
|
+
//#endregion
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { resolveOAuthAccountKey, toOAuthProfileRecord } from "./account-key.mjs";
|
|
2
|
+
import { OAUTH_CALLBACK_ERROR_CODES } from "./errors.mjs";
|
|
3
|
+
import { getOAuthCallbackPath } from "./utils.mjs";
|
|
4
|
+
import { safeJSONParse } from "@better-auth/core/utils/json";
|
|
5
|
+
//#region src/oauth2/callback.ts
|
|
6
|
+
/**
|
|
7
|
+
* Turns a provider callback into a verified identity. It checks that the
|
|
8
|
+
* callback answers this authorization request, exchanges the code, and
|
|
9
|
+
* resolves the user and account key.
|
|
10
|
+
*
|
|
11
|
+
* Every route that completes a provider callback goes through here, so the
|
|
12
|
+
* routes run the same checks.
|
|
13
|
+
*/
|
|
14
|
+
async function exchangeOAuthCallback(ctx, provider, callback) {
|
|
15
|
+
if (callback.iss && provider.issuer && callback.iss !== provider.issuer) {
|
|
16
|
+
ctx.context.logger.error("OAuth issuer mismatch", {
|
|
17
|
+
expected: provider.issuer,
|
|
18
|
+
received: callback.iss
|
|
19
|
+
});
|
|
20
|
+
return { error: OAUTH_CALLBACK_ERROR_CODES.ISSUER_MISMATCH };
|
|
21
|
+
}
|
|
22
|
+
if (provider.requiresIdTokenNonce && !callback.idTokenNonce) {
|
|
23
|
+
ctx.context.logger.error("OAuth id_token nonce binding required but no expected nonce was found in state", { providerId: provider.id });
|
|
24
|
+
return { error: OAUTH_CALLBACK_ERROR_CODES.NONCE_BINDING_MISSING };
|
|
25
|
+
}
|
|
26
|
+
let tokens;
|
|
27
|
+
try {
|
|
28
|
+
tokens = await provider.validateAuthorizationCode({
|
|
29
|
+
code: callback.code,
|
|
30
|
+
codeVerifier: callback.codeVerifier,
|
|
31
|
+
deviceId: callback.deviceId,
|
|
32
|
+
redirectURI: `${ctx.context.baseURL}${getOAuthCallbackPath(provider)}`
|
|
33
|
+
});
|
|
34
|
+
} catch (error) {
|
|
35
|
+
ctx.context.logger.error("Failed to validate authorization code", error);
|
|
36
|
+
return { error: OAUTH_CALLBACK_ERROR_CODES.INVALID_CODE };
|
|
37
|
+
}
|
|
38
|
+
if (!tokens) return { error: OAUTH_CALLBACK_ERROR_CODES.INVALID_CODE };
|
|
39
|
+
const result = await provider.getUserInfo({
|
|
40
|
+
...tokens,
|
|
41
|
+
expectedIdTokenNonce: callback.idTokenNonce,
|
|
42
|
+
/**
|
|
43
|
+
* The user object from the provider
|
|
44
|
+
* This is only available for some providers like Apple
|
|
45
|
+
*/
|
|
46
|
+
user: safeJSONParse(callback.user) ?? void 0
|
|
47
|
+
});
|
|
48
|
+
if (!result?.user) {
|
|
49
|
+
ctx.context.logger.error("Unable to get user info");
|
|
50
|
+
return { error: OAUTH_CALLBACK_ERROR_CODES.UNABLE_TO_GET_USER_INFO };
|
|
51
|
+
}
|
|
52
|
+
const accountKey = await resolveOAuthAccountKey(provider, tokens, result.data).catch((error) => {
|
|
53
|
+
ctx.context.logger.error("Unable to derive provider account identity", {
|
|
54
|
+
providerId: provider.id,
|
|
55
|
+
error
|
|
56
|
+
});
|
|
57
|
+
return null;
|
|
58
|
+
});
|
|
59
|
+
if (!accountKey) return { error: OAUTH_CALLBACK_ERROR_CODES.UNABLE_TO_GET_USER_INFO };
|
|
60
|
+
return {
|
|
61
|
+
tokens,
|
|
62
|
+
userInfo: result.user,
|
|
63
|
+
providerProfile: toOAuthProfileRecord(result.data),
|
|
64
|
+
accountKey
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
//#endregion
|
|
68
|
+
export { exchangeOAuthCallback };
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Account, User } from "../types/models.mjs";
|
|
2
|
+
import "../types/index.mjs";
|
|
2
3
|
import { GenericEndpointContext, UserProvisioningSource } from "@better-auth/core";
|
|
3
|
-
|
|
4
4
|
//#region src/oauth2/link-account.d.ts
|
|
5
5
|
type OAuthAccountData = Omit<Account, "id" | "userId" | "createdAt" | "updatedAt">;
|
|
6
6
|
/**
|
|
@@ -35,14 +35,8 @@ interface LinkOAuthAccountFailure {
|
|
|
35
35
|
type LinkOAuthAccountResult = {
|
|
36
36
|
linked: true;
|
|
37
37
|
} | LinkOAuthAccountFailure;
|
|
38
|
-
declare function linkOAuthAccount(c: GenericEndpointContext, {
|
|
39
|
-
|
|
40
|
-
userInfo,
|
|
41
|
-
account,
|
|
42
|
-
profile,
|
|
43
|
-
scopes
|
|
44
|
-
}: LinkOAuthAccountOptions): Promise<LinkOAuthAccountResult>;
|
|
45
|
-
declare function handleOAuthUserInfo(c: GenericEndpointContext, opts: {
|
|
38
|
+
export declare function linkOAuthAccount(c: GenericEndpointContext, { link, userInfo, account, profile, scopes }: LinkOAuthAccountOptions): Promise<LinkOAuthAccountResult>;
|
|
39
|
+
export declare function handleOAuthUserInfo(c: GenericEndpointContext, opts: {
|
|
46
40
|
userInfo: Omit<User, "createdAt" | "updatedAt">;
|
|
47
41
|
account: OAuthAccountData;
|
|
48
42
|
callbackURL?: string | undefined;
|
|
@@ -119,6 +113,6 @@ declare function handleOAuthUserInfo(c: GenericEndpointContext, opts: {
|
|
|
119
113
|
* cookie cache with the fresh row. Returns `undefined` when the policy is
|
|
120
114
|
* disabled or the update fails: a failed profile sync must not abort the link.
|
|
121
115
|
*/
|
|
122
|
-
declare function applyUpdateUserInfoOnLink(c: GenericEndpointContext, userId: string, userInfo: LinkedProviderProfile): Promise<User | undefined>;
|
|
116
|
+
export declare function applyUpdateUserInfoOnLink(c: GenericEndpointContext, userId: string, userInfo: LinkedProviderProfile): Promise<User | undefined>;
|
|
123
117
|
//#endregion
|
|
124
|
-
export {
|
|
118
|
+
export {};
|
|
@@ -82,7 +82,8 @@ async function handleOAuthUserInfo(c, opts) {
|
|
|
82
82
|
accountId: account.accountId
|
|
83
83
|
}).catch((e) => {
|
|
84
84
|
c.context.logger.error("Better auth was unable to query your database.\nError: ", e);
|
|
85
|
-
|
|
85
|
+
const errorURL = c.context.options.onAPIError?.errorURL || `${c.context.baseURL}/error`;
|
|
86
|
+
redirectOnError(c, errorURL, "internal_server_error");
|
|
86
87
|
});
|
|
87
88
|
if (accountOwner?.kind === "orphaned") {
|
|
88
89
|
c.context.logger.error("OAuth account references a missing user. Repair the account before retrying authentication.");
|
|
@@ -126,7 +127,8 @@ async function handleOAuthUserInfo(c, opts) {
|
|
|
126
127
|
})().catch((e) => {
|
|
127
128
|
if (isAPIError(e)) throw e;
|
|
128
129
|
c.context.logger.error("Better auth was unable to query your database.\nError: ", e);
|
|
129
|
-
|
|
130
|
+
const errorURL = c.context.options.onAPIError?.errorURL || `${c.context.baseURL}/error`;
|
|
131
|
+
redirectOnError(c, errorURL, "internal_server_error");
|
|
130
132
|
});
|
|
131
133
|
let user = dbUser?.user;
|
|
132
134
|
const isRegister = !user;
|
|
@@ -175,8 +177,10 @@ async function handleOAuthUserInfo(c, opts) {
|
|
|
175
177
|
code: "account_hook_binding_conflict",
|
|
176
178
|
message: "Account hook changed the selected authentication binding"
|
|
177
179
|
});
|
|
178
|
-
if (c.context.options.account?.storeAccountCookie)
|
|
179
|
-
|
|
180
|
+
if (c.context.options.account?.storeAccountCookie) {
|
|
181
|
+
if (opts.deferNonDatabaseWrites) pendingAccountCookie = createdAccount;
|
|
182
|
+
else await setAccountCookie(c, createdAccount);
|
|
183
|
+
}
|
|
180
184
|
} catch (e) {
|
|
181
185
|
if (isAPIError(e)) throw e;
|
|
182
186
|
c.context.logger.error("Unable to link account", e);
|
|
@@ -292,8 +296,10 @@ async function handleOAuthUserInfo(c, opts) {
|
|
|
292
296
|
message: "Account hook changed the selected authentication binding"
|
|
293
297
|
});
|
|
294
298
|
user = createdUser;
|
|
295
|
-
if (c.context.options.account?.storeAccountCookie)
|
|
296
|
-
|
|
299
|
+
if (c.context.options.account?.storeAccountCookie) {
|
|
300
|
+
if (opts.deferNonDatabaseWrites) pendingAccountCookie = createdAccount;
|
|
301
|
+
else await setAccountCookie(c, createdAccount);
|
|
302
|
+
}
|
|
297
303
|
} catch (e) {
|
|
298
304
|
if (isAPIError(e)) throw e;
|
|
299
305
|
c.context.logger.error("Unable to create OAuth user", e);
|
package/dist/oauth2/state.d.mts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { GenericEndpointContext } from "@better-auth/core";
|
|
2
|
-
|
|
3
2
|
//#region src/oauth2/state.d.ts
|
|
4
3
|
/**
|
|
5
4
|
* Mint the OIDC `nonce` for the redirect flow, or `undefined` when the provider
|
|
@@ -8,14 +7,14 @@ import { GenericEndpointContext } from "@better-auth/core";
|
|
|
8
7
|
* through this helper, so the value sent on the authorization URL and the value
|
|
9
8
|
* persisted in state are produced one way and cannot drift apart.
|
|
10
9
|
*/
|
|
11
|
-
declare function generateIdTokenNonce(provider: {
|
|
10
|
+
export declare function generateIdTokenNonce(provider: {
|
|
12
11
|
requiresIdTokenNonce?: boolean | undefined;
|
|
13
12
|
}): string | undefined;
|
|
14
13
|
/**
|
|
15
14
|
* Inputs for {@link generateState}. Grouped into one object so call sites read
|
|
16
15
|
* by name instead of by position.
|
|
17
16
|
*/
|
|
18
|
-
interface GenerateStateOptions {
|
|
17
|
+
export interface GenerateStateOptions {
|
|
19
18
|
/** Link target when this flow links a provider identity to an existing user. */
|
|
20
19
|
link?: {
|
|
21
20
|
email: string;
|
|
@@ -30,11 +29,11 @@ interface GenerateStateOptions {
|
|
|
30
29
|
/** The OIDC nonce already sent as the authorization URL `nonce` parameter. */
|
|
31
30
|
idTokenNonce?: string | undefined;
|
|
32
31
|
}
|
|
33
|
-
declare function generateState(c: GenericEndpointContext, options?: GenerateStateOptions): Promise<{
|
|
32
|
+
export declare function generateState(c: GenericEndpointContext, options?: GenerateStateOptions): Promise<{
|
|
34
33
|
state: string;
|
|
35
34
|
codeVerifier: string;
|
|
36
35
|
}>;
|
|
37
|
-
declare function parseState(c: GenericEndpointContext): Promise<{
|
|
36
|
+
export declare function parseState(c: GenericEndpointContext): Promise<{
|
|
38
37
|
[x: string]: unknown;
|
|
39
38
|
callbackURL: string;
|
|
40
39
|
codeVerifier: string;
|
|
@@ -50,5 +49,4 @@ declare function parseState(c: GenericEndpointContext): Promise<{
|
|
|
50
49
|
idTokenNonce?: string | undefined;
|
|
51
50
|
serverContext?: Record<string, unknown> | undefined;
|
|
52
51
|
}>;
|
|
53
|
-
//#endregion
|
|
54
|
-
export { GenerateStateOptions, generateIdTokenNonce, generateState, parseState };
|
|
52
|
+
//#endregion
|
package/dist/oauth2/state.mjs
CHANGED
|
@@ -28,7 +28,7 @@ async function generateState(c, options) {
|
|
|
28
28
|
newUserURL: c.body?.newUserCallbackURL,
|
|
29
29
|
link: options?.link,
|
|
30
30
|
serverContext,
|
|
31
|
-
expiresAt: Date.now() +
|
|
31
|
+
expiresAt: Date.now() + 6e5,
|
|
32
32
|
requestSignUp: c.body?.requestSignUp,
|
|
33
33
|
idTokenNonce: options?.idTokenNonce
|
|
34
34
|
};
|
package/dist/oauth2/utils.d.mts
CHANGED
|
@@ -1,11 +1,9 @@
|
|
|
1
1
|
import { AuthContext, LiteralString } from "@better-auth/core";
|
|
2
|
-
|
|
3
2
|
//#region src/oauth2/utils.d.ts
|
|
4
|
-
declare function decryptOAuthToken(token: string, ctx: AuthContext): string | Promise<string>;
|
|
5
|
-
declare function setTokenUtil(token: string | null | undefined, ctx: AuthContext): string | Promise<string> | null | undefined;
|
|
6
|
-
declare function getOAuthCallbackPath(provider: {
|
|
3
|
+
export declare function decryptOAuthToken(token: string, ctx: AuthContext): string | Promise<string>;
|
|
4
|
+
export declare function setTokenUtil(token: string | null | undefined, ctx: AuthContext): string | Promise<string> | null | undefined;
|
|
5
|
+
export declare function getOAuthCallbackPath(provider: {
|
|
7
6
|
id: LiteralString;
|
|
8
7
|
callbackPath?: string | undefined;
|
|
9
8
|
}): string;
|
|
10
|
-
//#endregion
|
|
11
|
-
export { decryptOAuthToken, getOAuthCallbackPath, setTokenUtil };
|
|
9
|
+
//#endregion
|
package/dist/package.mjs
CHANGED
|
@@ -1,17 +1,15 @@
|
|
|
1
1
|
import { ExactRoleStatements, Role, RoleInput, Statements } from "./types.mjs";
|
|
2
|
-
|
|
3
2
|
//#region src/plugins/access/access.d.ts
|
|
4
|
-
type AuthorizeResponse = {
|
|
3
|
+
export type AuthorizeResponse = {
|
|
5
4
|
success: false;
|
|
6
5
|
error: string;
|
|
7
6
|
} | {
|
|
8
7
|
success: true;
|
|
9
8
|
error?: never | undefined;
|
|
10
9
|
};
|
|
11
|
-
declare function role<const TRoleStatements extends Statements, TAuthorizeStatements extends Statements = TRoleStatements>(statements: TRoleStatements): Role<ExactRoleStatements<TRoleStatements>, TAuthorizeStatements>;
|
|
12
|
-
declare function createAccessControl<const TStatements extends Statements>(s: TStatements): {
|
|
10
|
+
export declare function role<const TRoleStatements extends Statements, TAuthorizeStatements extends Statements = TRoleStatements>(statements: TRoleStatements): Role<ExactRoleStatements<TRoleStatements>, TAuthorizeStatements>;
|
|
11
|
+
export declare function createAccessControl<const TStatements extends Statements>(s: TStatements): {
|
|
13
12
|
newRole<const TRoleStatements extends Statements>(statements: RoleInput<TStatements, TRoleStatements>): Role<ExactRoleStatements<TRoleStatements>, TStatements>;
|
|
14
13
|
statements: TStatements;
|
|
15
14
|
};
|
|
16
|
-
//#endregion
|
|
17
|
-
export { AuthorizeResponse, createAccessControl, role };
|
|
15
|
+
//#endregion
|
|
@@ -1,2 +1 @@
|
|
|
1
|
-
|
|
2
|
-
export { createAccessControl, role };
|
|
1
|
+
export { createAccessControl, role } from "./access.mjs";
|
|
@@ -1,24 +1,22 @@
|
|
|
1
1
|
import { AuthorizeResponse, createAccessControl } from "./access.mjs";
|
|
2
2
|
import { LiteralString } from "@better-auth/core";
|
|
3
|
-
|
|
4
3
|
//#region src/plugins/access/types.d.ts
|
|
5
|
-
type ArrayElement<T> = T extends readonly (infer E)[] ? E : never;
|
|
6
|
-
type SubArray<T extends unknown[] | readonly unknown[] | any[]> = T[number][] | ReadonlyArray<T[number]>;
|
|
7
|
-
type Subset<K extends keyof R, R extends Record<string | LiteralString, readonly string[] | readonly LiteralString[]>> = { [P in K]: SubArray<R[P]
|
|
8
|
-
type Statements = {
|
|
4
|
+
export type ArrayElement<T> = T extends readonly (infer E)[] ? E : never;
|
|
5
|
+
export type SubArray<T extends unknown[] | readonly unknown[] | any[]> = T[number][] | ReadonlyArray<T[number]>;
|
|
6
|
+
export type Subset<K extends keyof R, R extends Record<string | LiteralString, readonly string[] | readonly LiteralString[]>> = { [P in K]: SubArray<R[P]>; };
|
|
7
|
+
export type Statements = {
|
|
9
8
|
readonly [resource: string]: readonly LiteralString[];
|
|
10
9
|
};
|
|
11
|
-
type RoleStatements<TStatements extends Statements> = { readonly [P in keyof TStatements]?: SubArray<TStatements[P]
|
|
12
|
-
type RoleInput<TStatements extends Statements, TRoleStatements extends Statements> = TRoleStatements & (string extends keyof TRoleStatements ? {} : RoleStatements<TStatements> & Record<Exclude<keyof TRoleStatements, keyof TStatements>, never>);
|
|
13
|
-
type ExactRoleStatements<TStatements extends Statements> = { readonly [P in keyof TStatements]: readonly [...TStatements[P]] };
|
|
14
|
-
type AccessControl<TStatements extends Statements = Statements> = ReturnType<typeof createAccessControl<TStatements>>;
|
|
15
|
-
type RoleAuthorizeRequest<TStatements extends Statements> = { [P in keyof TStatements]?: SubArray<TStatements[P]> | {
|
|
10
|
+
export type RoleStatements<TStatements extends Statements> = { readonly [P in keyof TStatements]?: SubArray<TStatements[P]>; };
|
|
11
|
+
export type RoleInput<TStatements extends Statements, TRoleStatements extends Statements> = TRoleStatements & (string extends keyof TRoleStatements ? {} : RoleStatements<TStatements> & Record<Exclude<keyof TRoleStatements, keyof TStatements>, never>);
|
|
12
|
+
export type ExactRoleStatements<TStatements extends Statements> = { readonly [P in keyof TStatements]: readonly [...TStatements[P]]; };
|
|
13
|
+
export type AccessControl<TStatements extends Statements = Statements> = ReturnType<typeof createAccessControl<TStatements>>;
|
|
14
|
+
export type RoleAuthorizeRequest<TStatements extends Statements> = { [P in keyof TStatements]?: SubArray<TStatements[P]> | {
|
|
16
15
|
actions: SubArray<TStatements[P]>;
|
|
17
16
|
connector: "OR" | "AND";
|
|
18
|
-
} };
|
|
19
|
-
type Role<TRoleStatements extends Statements = Record<string, any>, TAuthorizeStatements extends Statements = TRoleStatements> = {
|
|
17
|
+
}; };
|
|
18
|
+
export type Role<TRoleStatements extends Statements = Record<string, any>, TAuthorizeStatements extends Statements = TRoleStatements> = {
|
|
20
19
|
authorize: (request: RoleAuthorizeRequest<TAuthorizeStatements>, connector?: ("OR" | "AND") | undefined) => AuthorizeResponse;
|
|
21
20
|
statements: TRoleStatements;
|
|
22
21
|
};
|
|
23
|
-
//#endregion
|
|
24
|
-
export { AccessControl, ArrayElement, ExactRoleStatements, Role, RoleAuthorizeRequest, RoleInput, RoleStatements, Statements, SubArray, Subset };
|
|
22
|
+
//#endregion
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import { BetterAuthOptions, BetterAuthPlugin } from "@better-auth/core";
|
|
2
2
|
import { DBFieldAttribute } from "@better-auth/core/db";
|
|
3
|
-
|
|
4
3
|
//#region src/plugins/additional-fields/client.d.ts
|
|
5
|
-
declare const inferAdditionalFields: <T, S extends {
|
|
4
|
+
export declare const inferAdditionalFields: <T, S extends {
|
|
6
5
|
user?: {
|
|
7
6
|
[key: string]: DBFieldAttribute;
|
|
8
7
|
} | undefined;
|
|
@@ -96,5 +95,4 @@ declare const inferAdditionalFields: <T, S extends {
|
|
|
96
95
|
};
|
|
97
96
|
} : never : undefined;
|
|
98
97
|
};
|
|
99
|
-
//#endregion
|
|
100
|
-
export { inferAdditionalFields };
|
|
98
|
+
//#endregion
|
|
@@ -1,2 +1 @@
|
|
|
1
|
-
|
|
2
|
-
export { adminAc, defaultAc, defaultRoles, defaultStatements, userAc };
|
|
1
|
+
export { adminAc, defaultAc, defaultRoles, defaultStatements, userAc } from "./statement.mjs";
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import { ExactRoleStatements, Role, RoleInput, Statements } from "../../access/types.mjs";
|
|
2
|
+
import "../../index.mjs";
|
|
2
3
|
//#region src/plugins/admin/access/statement.d.ts
|
|
3
|
-
declare const defaultStatements: {
|
|
4
|
+
export declare const defaultStatements: {
|
|
4
5
|
readonly user: readonly ["create", "list", "set-role", "ban", "impersonate", "impersonate-admins", "delete", "set-password", "set-email", "get", "update"];
|
|
5
6
|
readonly session: readonly ["list", "revoke", "delete"];
|
|
6
7
|
};
|
|
7
|
-
declare const defaultAc: {
|
|
8
|
+
export declare const defaultAc: {
|
|
8
9
|
newRole<const TRoleStatements extends Statements>(statements: RoleInput<{
|
|
9
10
|
readonly user: readonly ["create", "list", "set-role", "ban", "impersonate", "impersonate-admins", "delete", "set-password", "set-email", "get", "update"];
|
|
10
11
|
readonly session: readonly ["list", "revoke", "delete"];
|
|
@@ -17,21 +18,21 @@ declare const defaultAc: {
|
|
|
17
18
|
readonly session: readonly ["list", "revoke", "delete"];
|
|
18
19
|
};
|
|
19
20
|
};
|
|
20
|
-
declare const adminAc: Role<ExactRoleStatements<{
|
|
21
|
+
export declare const adminAc: Role<ExactRoleStatements<{
|
|
21
22
|
readonly user: ["create", "list", "set-role", "ban", "impersonate", "delete", "set-password", "set-email", "get", "update"];
|
|
22
23
|
readonly session: ["list", "revoke", "delete"];
|
|
23
24
|
}>, {
|
|
24
25
|
readonly user: readonly ["create", "list", "set-role", "ban", "impersonate", "impersonate-admins", "delete", "set-password", "set-email", "get", "update"];
|
|
25
26
|
readonly session: readonly ["list", "revoke", "delete"];
|
|
26
27
|
}>;
|
|
27
|
-
declare const userAc: Role<ExactRoleStatements<{
|
|
28
|
+
export declare const userAc: Role<ExactRoleStatements<{
|
|
28
29
|
readonly user: [];
|
|
29
30
|
readonly session: [];
|
|
30
31
|
}>, {
|
|
31
32
|
readonly user: readonly ["create", "list", "set-role", "ban", "impersonate", "impersonate-admins", "delete", "set-password", "set-email", "get", "update"];
|
|
32
33
|
readonly session: readonly ["list", "revoke", "delete"];
|
|
33
34
|
}>;
|
|
34
|
-
declare const defaultRoles: {
|
|
35
|
+
export declare const defaultRoles: {
|
|
35
36
|
admin: Role<ExactRoleStatements<{
|
|
36
37
|
readonly user: ["create", "list", "set-role", "ban", "impersonate", "delete", "set-password", "set-email", "get", "update"];
|
|
37
38
|
readonly session: ["list", "revoke", "delete"];
|
|
@@ -47,5 +48,4 @@ declare const defaultRoles: {
|
|
|
47
48
|
readonly session: readonly ["list", "revoke", "delete"];
|
|
48
49
|
}>;
|
|
49
50
|
};
|
|
50
|
-
//#endregion
|
|
51
|
-
export { adminAc, defaultAc, defaultRoles, defaultStatements, userAc };
|
|
51
|
+
//#endregion
|