better-auth 1.6.22 → 1.6.24
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 +1 -6
- package/dist/api/dispatch.d.mts +0 -1
- package/dist/api/index.d.mts +476 -478
- package/dist/api/middlewares/authorization.d.mts +12 -8
- 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 +3 -5
- package/dist/api/routes/account.d.mts +10 -13
- package/dist/api/routes/account.mjs +35 -7
- package/dist/api/routes/callback.d.mts +1 -3
- package/dist/api/routes/callback.mjs +4 -0
- package/dist/api/routes/email-verification.d.mts +4 -8
- package/dist/api/routes/email-verification.mjs +15 -2
- package/dist/api/routes/error.d.mts +1 -3
- package/dist/api/routes/index.d.mts +2 -1
- package/dist/api/routes/ok.d.mts +1 -3
- package/dist/api/routes/password.d.mts +7 -9
- package/dist/api/routes/password.mjs +14 -1
- package/dist/api/routes/session.d.mts +22 -24
- package/dist/api/routes/session.mjs +5 -1
- package/dist/api/routes/sign-in.d.mts +3 -5
- package/dist/api/routes/sign-in.mjs +84 -2
- package/dist/api/routes/sign-out.d.mts +1 -3
- package/dist/api/routes/sign-up.d.mts +3 -4
- package/dist/api/routes/sign-up.mjs +3 -2
- package/dist/api/routes/update-session.d.mts +3 -4
- package/dist/api/routes/update-user.d.mts +13 -14
- package/dist/api/routes/update-user.mjs +26 -1
- package/dist/auth/full.d.mts +1 -1
- package/dist/auth/minimal.d.mts +1 -1
- package/dist/client/config.d.mts +12 -14
- package/dist/client/config.mjs +2 -2
- package/dist/client/equality.d.mts +0 -1
- package/dist/client/index.d.mts +6 -5
- package/dist/client/lynx/index.d.mts +4 -5
- package/dist/client/lynx/lynx-store.d.mts +1 -2
- package/dist/client/parser.d.mts +7 -3
- package/dist/client/path-to-object.d.mts +3 -4
- package/dist/client/plugins/index.d.mts +2 -1
- package/dist/client/plugins/infer-plugin.d.mts +0 -1
- package/dist/client/query.d.mts +0 -1
- package/dist/client/query.mjs +38 -20
- package/dist/client/react/index.d.mts +4 -5
- package/dist/client/react/react-store.d.mts +1 -2
- package/dist/client/session-refresh.d.mts +0 -1
- package/dist/client/solid/index.d.mts +5 -6
- package/dist/client/svelte/index.d.mts +5 -6
- package/dist/client/types.d.mts +2 -2
- package/dist/client/vanilla.d.mts +2 -3
- package/dist/client/vue/index.d.mts +5 -6
- package/dist/context/create-context.mjs +3 -3
- package/dist/context/helpers.mjs +2 -2
- package/dist/cookies/cookie-utils.d.mts +1 -1
- package/dist/cookies/index.d.mts +6 -7
- package/dist/cookies/index.mjs +4 -0
- package/dist/cookies/session-store.d.mts +1 -0
- package/dist/cookies/session-store.mjs +6 -1
- package/dist/crypto/index.d.mts +2 -9
- package/dist/crypto/jwt.d.mts +0 -1
- package/dist/crypto/password.d.mts +1 -5
- package/dist/db/adapter-base.d.mts +0 -1
- package/dist/db/adapter-kysely.d.mts +0 -1
- package/dist/db/field-converter.d.mts +0 -1
- package/dist/db/field.d.mts +9 -10
- package/dist/db/get-migration.d.mts +0 -1
- package/dist/db/get-migration.mjs +8 -4
- package/dist/db/get-schema.d.mts +0 -1
- package/dist/db/internal-adapter.d.mts +0 -1
- package/dist/db/internal-adapter.mjs +61 -1
- package/dist/db/revoke-unproven-account-access.d.mts +0 -1
- package/dist/db/schema.d.mts +2 -2
- package/dist/db/to-zod.d.mts +3 -7
- package/dist/db/with-hooks.d.mts +0 -1
- package/dist/index.d.mts +4 -3
- package/dist/integrations/next-js.d.mts +4 -7
- package/dist/integrations/node.d.mts +2 -3
- package/dist/integrations/svelte-kit.d.mts +2 -9
- package/dist/integrations/tanstack-start-solid.d.mts +2 -5
- package/dist/integrations/tanstack-start.d.mts +2 -5
- package/dist/oauth2/link-account.d.mts +1 -1
- package/dist/oauth2/state.d.mts +0 -1
- package/dist/oauth2/utils.d.mts +0 -1
- package/dist/package.mjs +1 -1
- package/dist/plugins/access/access.d.mts +0 -1
- package/dist/plugins/access/types.d.mts +4 -5
- package/dist/plugins/additional-fields/client.d.mts +0 -1
- package/dist/plugins/admin/access/statement.d.mts +1 -0
- package/dist/plugins/admin/admin.d.mts +120 -125
- package/dist/plugins/admin/client.d.mts +30 -30
- package/dist/plugins/admin/client.mjs +1 -1
- package/dist/plugins/admin/error-codes.d.mts +23 -25
- package/dist/plugins/admin/index.d.mts +1 -1
- package/dist/plugins/admin/routes.mjs +9 -0
- package/dist/plugins/admin/schema.d.mts +1 -1
- package/dist/plugins/admin/types.d.mts +3 -2
- package/dist/plugins/anonymous/client.d.mts +9 -11
- package/dist/plugins/anonymous/client.mjs +1 -1
- package/dist/plugins/anonymous/error-codes.d.mts +8 -10
- package/dist/plugins/anonymous/index.d.mts +14 -18
- package/dist/plugins/anonymous/types.d.mts +1 -1
- package/dist/plugins/bearer/index.d.mts +4 -7
- package/dist/plugins/captcha/index.d.mts +5 -8
- package/dist/plugins/captcha/types.d.mts +0 -1
- package/dist/plugins/custom-session/client.d.mts +0 -1
- package/dist/plugins/custom-session/index.d.mts +7 -12
- package/dist/plugins/device-authorization/client.d.mts +0 -1
- package/dist/plugins/device-authorization/index.d.mts +19 -22
- package/dist/plugins/email-otp/client.d.mts +4 -6
- package/dist/plugins/email-otp/client.mjs +1 -1
- package/dist/plugins/email-otp/error-codes.d.mts +3 -5
- package/dist/plugins/email-otp/index.d.mts +67 -73
- package/dist/plugins/email-otp/routes.mjs +2 -0
- package/dist/plugins/email-otp/types.d.mts +0 -1
- package/dist/plugins/generic-oauth/client.d.mts +11 -11
- package/dist/plugins/generic-oauth/client.mjs +1 -1
- package/dist/plugins/generic-oauth/error-codes.d.mts +8 -10
- package/dist/plugins/generic-oauth/index.d.mts +41 -44
- package/dist/plugins/generic-oauth/index.mjs +2 -1
- package/dist/plugins/generic-oauth/providers/auth0.d.mts +0 -1
- package/dist/plugins/generic-oauth/providers/gumroad.d.mts +0 -1
- package/dist/plugins/generic-oauth/providers/hubspot.d.mts +0 -1
- package/dist/plugins/generic-oauth/providers/index.d.mts +3 -1
- package/dist/plugins/generic-oauth/providers/keycloak.d.mts +0 -1
- package/dist/plugins/generic-oauth/providers/line.d.mts +0 -1
- package/dist/plugins/generic-oauth/providers/microsoft-entra-id.d.mts +0 -1
- package/dist/plugins/generic-oauth/providers/okta.d.mts +0 -1
- package/dist/plugins/generic-oauth/providers/patreon.d.mts +0 -1
- package/dist/plugins/generic-oauth/providers/slack.d.mts +0 -1
- package/dist/plugins/generic-oauth/providers/yandex.d.mts +28 -0
- package/dist/plugins/generic-oauth/providers/yandex.mjs +60 -0
- package/dist/plugins/generic-oauth/routes.mjs +14 -0
- package/dist/plugins/generic-oauth/types.d.mts +1 -2
- package/dist/plugins/haveibeenpwned/index.d.mts +3 -6
- package/dist/plugins/index.d.mts +5 -1
- package/dist/plugins/index.mjs +2 -1
- package/dist/plugins/jwt/client.d.mts +2 -4
- package/dist/plugins/jwt/index.d.mts +8 -11
- package/dist/plugins/jwt/sign.d.mts +2 -2
- package/dist/plugins/jwt/types.d.mts +1 -1
- package/dist/plugins/jwt/utils.d.mts +2 -4
- package/dist/plugins/jwt/verify.d.mts +0 -1
- package/dist/plugins/last-login-method/client.mjs +13 -0
- package/dist/plugins/last-login-method/index.d.mts +11 -5
- package/dist/plugins/last-login-method/index.mjs +8 -0
- package/dist/plugins/magic-link/client.d.mts +0 -1
- package/dist/plugins/magic-link/index.d.mts +4 -5
- package/dist/plugins/magic-link/index.mjs +32 -1
- package/dist/plugins/mcp/authorize.mjs +12 -0
- package/dist/plugins/mcp/client/adapters.d.mts +0 -1
- package/dist/plugins/mcp/client/index.d.mts +2 -0
- package/dist/plugins/mcp/client/index.mjs +36 -11
- package/dist/plugins/mcp/index.d.mts +10 -11
- package/dist/plugins/multi-session/client.d.mts +2 -4
- package/dist/plugins/multi-session/client.mjs +1 -1
- package/dist/plugins/multi-session/error-codes.d.mts +1 -3
- package/dist/plugins/multi-session/index.d.mts +7 -11
- package/dist/plugins/multi-session/index.mjs +45 -0
- package/dist/plugins/oauth-popup/client.d.mts +6 -12
- package/dist/plugins/oauth-popup/client.mjs +5 -3
- package/dist/plugins/oauth-popup/error-codes.d.mts +4 -6
- package/dist/plugins/oauth-popup/index.d.mts +8 -12
- package/dist/plugins/oauth-popup/index.mjs +1 -1
- package/dist/plugins/oauth-popup/types.d.mts +1 -2
- package/dist/plugins/oauth-proxy/index.d.mts +6 -9
- package/dist/plugins/oauth-proxy/index.mjs +2 -2
- package/dist/plugins/oidc-provider/authorize.mjs +9 -0
- package/dist/plugins/oidc-provider/client.d.mts +1 -2
- package/dist/plugins/oidc-provider/index.d.mts +15 -17
- package/dist/plugins/oidc-provider/index.mjs +26 -2
- package/dist/plugins/oidc-provider/schema.d.mts +0 -1
- package/dist/plugins/oidc-provider/schema.mjs +37 -0
- package/dist/plugins/oidc-provider/types.d.mts +1 -1
- package/dist/plugins/one-tap/client.d.mts +3 -6
- package/dist/plugins/one-tap/client.mjs +3 -0
- package/dist/plugins/one-tap/index.d.mts +1 -3
- package/dist/plugins/one-tap/index.mjs +5 -0
- package/dist/plugins/one-time-token/client.d.mts +1 -2
- package/dist/plugins/one-time-token/index.d.mts +5 -6
- package/dist/plugins/one-time-token/index.mjs +30 -0
- package/dist/plugins/open-api/generator.d.mts +0 -1
- package/dist/plugins/open-api/generator.mjs +81 -5
- package/dist/plugins/open-api/index.d.mts +3 -5
- package/dist/plugins/organization/access/statement.d.mts +1 -0
- package/dist/plugins/organization/adapter.d.mts +56 -82
- package/dist/plugins/organization/adapter.mjs +17 -3
- package/dist/plugins/organization/client.d.mts +106 -105
- package/dist/plugins/organization/client.mjs +7 -4
- package/dist/plugins/organization/error-codes.d.mts +59 -61
- package/dist/plugins/organization/has-permission.d.mts +0 -1
- 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 +7 -7
- package/dist/plugins/organization/organization.mjs +434 -1
- package/dist/plugins/organization/permission.d.mts +2 -2
- package/dist/plugins/organization/routes/crud-access-control.d.mts +17 -17
- package/dist/plugins/organization/routes/crud-invites.d.mts +53 -54
- package/dist/plugins/organization/routes/crud-invites.mjs +1 -1
- package/dist/plugins/organization/routes/crud-members.d.mts +44 -46
- package/dist/plugins/organization/routes/crud-members.mjs +4 -1
- package/dist/plugins/organization/routes/crud-org.d.mts +47 -48
- package/dist/plugins/organization/routes/crud-org.mjs +2 -2
- package/dist/plugins/organization/routes/crud-team.d.mts +50 -51
- package/dist/plugins/organization/schema.d.mts +4 -4
- package/dist/plugins/organization/schema.mjs +1 -1
- package/dist/plugins/organization/types.d.mts +16 -16
- package/dist/plugins/phone-number/client.d.mts +13 -15
- package/dist/plugins/phone-number/client.mjs +1 -1
- package/dist/plugins/phone-number/error-codes.d.mts +12 -14
- package/dist/plugins/phone-number/index.d.mts +41 -47
- package/dist/plugins/phone-number/routes.mjs +15 -0
- package/dist/plugins/phone-number/types.d.mts +1 -1
- package/dist/plugins/siwe/client.d.mts +0 -1
- package/dist/plugins/siwe/index.d.mts +4 -5
- package/dist/plugins/test-utils/index.d.mts +2 -4
- package/dist/plugins/test-utils/types.d.mts +1 -0
- package/dist/plugins/two-factor/backup-codes/index.d.mts +4 -6
- package/dist/plugins/two-factor/backup-codes/index.mjs +52 -1
- package/dist/plugins/two-factor/client.d.mts +12 -15
- package/dist/plugins/two-factor/client.mjs +1 -1
- package/dist/plugins/two-factor/error-code.d.mts +10 -12
- package/dist/plugins/two-factor/index.d.mts +27 -31
- package/dist/plugins/two-factor/index.mjs +30 -0
- package/dist/plugins/two-factor/otp/index.d.mts +2 -4
- package/dist/plugins/two-factor/otp/index.mjs +42 -1
- package/dist/plugins/two-factor/totp/index.d.mts +4 -6
- package/dist/plugins/two-factor/totp/index.mjs +47 -0
- package/dist/plugins/two-factor/types.d.mts +1 -1
- package/dist/plugins/username/client.d.mts +9 -11
- package/dist/plugins/username/client.mjs +1 -1
- package/dist/plugins/username/error-codes.d.mts +8 -10
- package/dist/plugins/username/index.d.mts +17 -22
- package/dist/plugins/username/schema.d.mts +3 -5
- package/dist/state.d.mts +0 -1
- package/dist/state.mjs +4 -0
- package/dist/test-utils/test-instance.d.mts +5 -3
- package/dist/test-utils/test-instance.mjs +4 -1
- package/dist/types/adapter.d.mts +1 -1
- package/dist/types/api.d.mts +1 -2
- package/dist/types/auth.d.mts +0 -1
- package/dist/types/helper.d.mts +5 -5
- package/dist/types/index.d.mts +2 -2
- package/dist/types/models.d.mts +0 -1
- package/dist/types/plugins.d.mts +2 -3
- package/dist/utils/index.d.mts +2 -1
- package/dist/utils/request.mjs +23 -0
- package/dist/utils/url.d.mts +0 -1
- package/package.json +10 -10
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { betterFetch } from "@better-fetch/fetch";
|
|
2
|
+
//#region src/plugins/generic-oauth/providers/yandex.ts
|
|
3
|
+
/**
|
|
4
|
+
* Yandex OAuth provider helper
|
|
5
|
+
*
|
|
6
|
+
* @example
|
|
7
|
+
* ```ts
|
|
8
|
+
* import { genericOAuth, yandex } from "better-auth/plugins/generic-oauth";
|
|
9
|
+
*
|
|
10
|
+
* export const auth = betterAuth({
|
|
11
|
+
* plugins: [
|
|
12
|
+
* genericOAuth({
|
|
13
|
+
* config: [
|
|
14
|
+
* yandex({
|
|
15
|
+
* clientId: process.env.YANDEX_CLIENT_ID,
|
|
16
|
+
* clientSecret: process.env.YANDEX_CLIENT_SECRET,
|
|
17
|
+
* }),
|
|
18
|
+
* ],
|
|
19
|
+
* }),
|
|
20
|
+
* ],
|
|
21
|
+
* });
|
|
22
|
+
* ```
|
|
23
|
+
*/
|
|
24
|
+
function yandex(options) {
|
|
25
|
+
const defaultScopes = [
|
|
26
|
+
"login:info",
|
|
27
|
+
"login:email",
|
|
28
|
+
"login:avatar"
|
|
29
|
+
];
|
|
30
|
+
const getUserInfo = async (tokens) => {
|
|
31
|
+
const { data: profile, error } = await betterFetch("https://login.yandex.ru/info?format=json", {
|
|
32
|
+
method: "GET",
|
|
33
|
+
headers: { Authorization: `OAuth ${tokens.accessToken}` }
|
|
34
|
+
});
|
|
35
|
+
if (error || !profile) return null;
|
|
36
|
+
return {
|
|
37
|
+
id: profile.id,
|
|
38
|
+
name: profile.display_name ?? profile.real_name ?? profile.first_name ?? profile.login,
|
|
39
|
+
email: profile.default_email ?? profile.emails?.[0],
|
|
40
|
+
emailVerified: false,
|
|
41
|
+
image: !profile.is_avatar_empty && profile.default_avatar_id ? `https://avatars.yandex.net/get-yapic/${profile.default_avatar_id}/islands-200` : void 0
|
|
42
|
+
};
|
|
43
|
+
};
|
|
44
|
+
return {
|
|
45
|
+
providerId: "yandex",
|
|
46
|
+
authorizationUrl: "https://oauth.yandex.com/authorize",
|
|
47
|
+
tokenUrl: "https://oauth.yandex.com/token",
|
|
48
|
+
clientId: options.clientId,
|
|
49
|
+
clientSecret: options.clientSecret,
|
|
50
|
+
scopes: options.scopes ?? defaultScopes,
|
|
51
|
+
redirectURI: options.redirectURI,
|
|
52
|
+
pkce: options.pkce,
|
|
53
|
+
disableImplicitSignUp: options.disableImplicitSignUp,
|
|
54
|
+
disableSignUp: options.disableSignUp,
|
|
55
|
+
overrideUserInfo: options.overrideUserInfo,
|
|
56
|
+
getUserInfo
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
//#endregion
|
|
60
|
+
export { yandex };
|
|
@@ -26,6 +26,9 @@ const signInWithOAuth2BodySchema = z.object({
|
|
|
26
26
|
disableRedirect: z.boolean().meta({ description: "Disable redirect" }).optional(),
|
|
27
27
|
scopes: z.array(z.string()).meta({ description: "Scopes to be passed to the provider authorization request." }).optional(),
|
|
28
28
|
requestSignUp: z.boolean().meta({ description: "Explicitly request sign-up. Useful when disableImplicitSignUp is true for this provider. Eg: false" }).optional(),
|
|
29
|
+
/**
|
|
30
|
+
* Any additional data to pass through the oauth flow.
|
|
31
|
+
*/
|
|
29
32
|
additionalData: z.record(z.string(), z.any()).optional()
|
|
30
33
|
});
|
|
31
34
|
/**
|
|
@@ -299,8 +302,19 @@ const oAuth2Callback = (options) => createAuthEndpoint("/oauth2/callback/:provid
|
|
|
299
302
|
});
|
|
300
303
|
const OAuth2LinkAccountBodySchema = z.object({
|
|
301
304
|
providerId: z.string(),
|
|
305
|
+
/**
|
|
306
|
+
* Callback URL to redirect to after the user has signed in.
|
|
307
|
+
*/
|
|
302
308
|
callbackURL: z.string(),
|
|
309
|
+
/**
|
|
310
|
+
* Additional scopes to request when linking the account.
|
|
311
|
+
* This is useful for requesting additional permissions when
|
|
312
|
+
* linking a social account compared to the initial authentication.
|
|
313
|
+
*/
|
|
303
314
|
scopes: z.array(z.string()).meta({ description: "Additional scopes to request when linking the account" }).optional(),
|
|
315
|
+
/**
|
|
316
|
+
* The URL to redirect to if there is an error during the link process.
|
|
317
|
+
*/
|
|
304
318
|
errorCallbackURL: z.string().meta({ description: "The URL to redirect to if there is an error during the link process" }).optional()
|
|
305
319
|
});
|
|
306
320
|
/**
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { GenericEndpointContext } from "@better-auth/core";
|
|
2
2
|
import { User } from "@better-auth/core/db";
|
|
3
3
|
import { OAuth2Tokens, OAuth2UserInfo } from "@better-auth/core/oauth2";
|
|
4
|
-
|
|
5
4
|
//#region src/plugins/generic-oauth/types.d.ts
|
|
6
5
|
interface GenericOAuthOptions {
|
|
7
6
|
/**
|
|
@@ -70,7 +69,7 @@ interface GenericOAuthConfig {
|
|
|
70
69
|
responseType?: string | undefined;
|
|
71
70
|
/**
|
|
72
71
|
* The response mode to use for the authorization code request.
|
|
73
|
-
|
|
72
|
+
*/
|
|
74
73
|
responseMode?: ("query" | "form_post") | undefined;
|
|
75
74
|
/**
|
|
76
75
|
* Prompt parameter for the authorization request.
|
|
@@ -1,6 +1,3 @@
|
|
|
1
|
-
import * as _better_auth_core0 from "@better-auth/core";
|
|
2
|
-
import * as _better_auth_core_utils_error_codes0 from "@better-auth/core/utils/error-codes";
|
|
3
|
-
|
|
4
1
|
//#region src/plugins/haveibeenpwned/index.d.ts
|
|
5
2
|
declare module "@better-auth/core" {
|
|
6
3
|
interface BetterAuthPluginRegistry<AuthOptions, Options> {
|
|
@@ -30,7 +27,7 @@ interface HaveIBeenPwnedOptions {
|
|
|
30
27
|
declare const haveIBeenPwned: (options?: HaveIBeenPwnedOptions | undefined) => {
|
|
31
28
|
id: "have-i-been-pwned";
|
|
32
29
|
version: string;
|
|
33
|
-
init(ctx:
|
|
30
|
+
init(ctx: import("@better-auth/core").AuthContext): {
|
|
34
31
|
context: {
|
|
35
32
|
password: {
|
|
36
33
|
hash(password: string): Promise<string>;
|
|
@@ -42,13 +39,13 @@ declare const haveIBeenPwned: (options?: HaveIBeenPwnedOptions | undefined) => {
|
|
|
42
39
|
minPasswordLength: number;
|
|
43
40
|
maxPasswordLength: number;
|
|
44
41
|
};
|
|
45
|
-
checkPassword: (userId: string, ctx:
|
|
42
|
+
checkPassword: (userId: string, ctx: import("@better-auth/core").GenericEndpointContext<import("@better-auth/core").BetterAuthOptions>) => Promise<boolean>;
|
|
46
43
|
};
|
|
47
44
|
};
|
|
48
45
|
};
|
|
49
46
|
options: HaveIBeenPwnedOptions | undefined;
|
|
50
47
|
$ERROR_CODES: {
|
|
51
|
-
PASSWORD_COMPROMISED:
|
|
48
|
+
PASSWORD_COMPROMISED: import("@better-auth/core/utils/error-codes").RawError<"PASSWORD_COMPROMISED">;
|
|
52
49
|
};
|
|
53
50
|
};
|
|
54
51
|
//#endregion
|
package/dist/plugins/index.d.mts
CHANGED
|
@@ -2,11 +2,13 @@ import { InferOptionSchema, InferPluginContext, InferPluginErrorCodes, InferPlug
|
|
|
2
2
|
import { HIDE_METADATA } from "../utils/hide-metadata.mjs";
|
|
3
3
|
import { AccessControl, ArrayElement, ExactRoleStatements, Role, RoleAuthorizeRequest, RoleInput, RoleStatements, Statements, SubArray, Subset } from "./access/types.mjs";
|
|
4
4
|
import { AuthorizeResponse, createAccessControl, role } from "./access/access.mjs";
|
|
5
|
+
import "./access/index.mjs";
|
|
5
6
|
import { OrganizationOptions } from "./organization/types.mjs";
|
|
6
7
|
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 "./organization/schema.mjs";
|
|
7
8
|
import { getOrgAdapter } from "./organization/adapter.mjs";
|
|
8
9
|
import { AdminOptions, InferAdminRolesFromOption, SessionWithImpersonatedBy, UserWithRole } from "./admin/types.mjs";
|
|
9
10
|
import { admin } from "./admin/admin.mjs";
|
|
11
|
+
import "./admin/index.mjs";
|
|
10
12
|
import { AnonymousOptions, AnonymousSession, UserWithAnonymous } from "./anonymous/types.mjs";
|
|
11
13
|
import { anonymous } from "./anonymous/index.mjs";
|
|
12
14
|
import { BearerOptions, bearer } from "./bearer/index.mjs";
|
|
@@ -27,6 +29,7 @@ import { MicrosoftEntraIdOptions, microsoftEntraId } from "./generic-oauth/provi
|
|
|
27
29
|
import { OktaOptions, okta } from "./generic-oauth/providers/okta.mjs";
|
|
28
30
|
import { PatreonOptions, patreon } from "./generic-oauth/providers/patreon.mjs";
|
|
29
31
|
import { SlackOptions, slack } from "./generic-oauth/providers/slack.mjs";
|
|
32
|
+
import { YandexOptions, yandex } from "./generic-oauth/providers/yandex.mjs";
|
|
30
33
|
import { BaseOAuthProviderOptions, genericOAuth } from "./generic-oauth/index.mjs";
|
|
31
34
|
import { HaveIBeenPwnedOptions, haveIBeenPwned } from "./haveibeenpwned/index.mjs";
|
|
32
35
|
import { JWKOptions, JWSAlgorithms, Jwk, JwtOptions } from "./jwt/types.mjs";
|
|
@@ -66,4 +69,5 @@ import { USERNAME_ERROR_CODES } from "./username/error-codes.mjs";
|
|
|
66
69
|
import { UsernameOptions, username } from "./username/index.mjs";
|
|
67
70
|
import { hasPermission } from "./organization/has-permission.mjs";
|
|
68
71
|
import { DefaultOrganizationPlugin, DynamicAccessControlEndpoints, OrganizationCreator, OrganizationEndpoints, OrganizationPlugin, TeamEndpoints, organization, parseRoles } from "./organization/organization.mjs";
|
|
69
|
-
|
|
72
|
+
import "./organization/index.mjs";
|
|
73
|
+
export { AccessControl, type AdminOptions, type AnonymousOptions, type AnonymousSession, ArrayElement, type Auth0Options, type AuthorizationQuery, AuthorizeResponse, type BackupCodeOptions, type BaseCaptchaOptions, BaseOAuthProviderOptions, BearerOptions, type CaptchaFoxOptions, type CaptchaOptions, type Client, type CloudflareTurnstileOptions, type CodeVerificationValue, CustomSessionPluginOptions, DefaultOrganizationPlugin, DeviceAuthorizationOptions, DynamicAccessControlEndpoints, MULTI_SESSION_ERROR_CODES as ERROR_CODES, type EmailOTPOptions, ExactRoleStatements, type FieldSchema, type GenericOAuthConfig, type GenericOAuthOptions, type GoogleRecaptchaOptions, type GumroadOptions, type HCaptchaOptions, HIDE_METADATA, HaveIBeenPwnedOptions, type HubSpotOptions, type InferAdminRolesFromOption, type InferInvitation, type InferMember, InferOptionSchema, type InferOrganization, type InferOrganizationRolesFromOption, type InferOrganizationZodRolesFromOption, InferPluginContext, InferPluginErrorCodes, InferPluginIDs, type InferTeam, type Invitation, type InvitationInput, type InvitationStatus, type JWKOptions, type JWSAlgorithms, type Jwk, type JwtOptions, type KeycloakOptions, LastLoginMethodOptions, type LineOptions, type LoginResult, MagicLinkOptions, type Member, type MemberInput, type MicrosoftEntraIdOptions, MultiSessionConfig, OAUTH_POPUP_COMPLETE_SCRIPT, OAUTH_POPUP_DATA_ELEMENT_ID, OAUTH_POPUP_ERROR_CODES, OAUTH_POPUP_MESSAGE_TYPE, OAUTH_POPUP_SCRIPT_CSP_HASH, type OAuthAccessToken, type OAuthPopupData, type OAuthPopupMessage, OAuthProxyOptions, type OIDCMetadata, type OIDCOptions, type OTPOptions, type OktaOptions, OneTapOptions, OneTimeTokenOptions, type OpenAPIModelSchema, OpenAPIOptions, type OpenAPIParameter, type OpenAPISchema, type Organization, OrganizationCreator, OrganizationEndpoints, type OrganizationInput, type OrganizationOptions, OrganizationPlugin, type OrganizationRole, type OrganizationSchema, POPUP_MARKER_COOKIE, type Path, type PatreonOptions, type PhoneNumberOptions, type Provider, Role, RoleAuthorizeRequest, RoleInput, RoleStatements, SIWEPluginOptions, type SessionWithImpersonatedBy, type SlackOptions, Statements, SubArray, Subset, type TOTPOptions, TWO_FACTOR_ERROR_CODES, type Team, TeamEndpoints, type TeamInput, type TeamMember, type TeamMemberInput, type TestCookie, type TestHelpers, type TestUtilsOptions, type TimeString, type TokenBody, TwoFactorOptions, TwoFactorProvider, TwoFactorTable, USERNAME_ERROR_CODES, type UserWithAnonymous, type UserWithPhoneNumber, type UserWithRole, UserWithTwoFactor, UsernameOptions, type YandexOptions, admin, anonymous, auth0, type backupCode2fa, bearer, captcha, createAccessControl, createJwk, customSession, type defaultRolesSchema, deviceAuthorization, deviceAuthorizationOptionsSchema, emailOTP, type encodeBackupCodes, type generateBackupCodes, generateExportedKeyPair, type generator, genericOAuth, type getBackupCodes, getClient, getJwtToken, getMCPProtectedResourceMetadata, getMCPProviderMetadata, getMetadata, getOrgAdapter, gumroad, hasPermission, haveIBeenPwned, hubspot, type invitationSchema, type invitationStatus, jwt, keycloak, lastLoginMethod, line, magicLink, mcp, type memberSchema, microsoftEntraId, type ms, multiSession, oAuthDiscoveryMetadata, oAuthProtectedResourceMetadata, oAuthProxy, oauthPopup, oidcProvider, okta, oneTap, oneTimeToken, openAPI, organization, type organizationRoleSchema, type organizationSchema, type otp2fa, parseRoles, patreon, phoneNumber, role, type roleSchema, type sec, signJWT, siwe, slack, type teamMemberSchema, type teamSchema, testUtils, toExpJWT, type totp2fa, twoFactor, twoFactorClient, username, type verifyBackupCode, verifyJWT, withMcpAuth, yandex };
|
package/dist/plugins/index.mjs
CHANGED
|
@@ -22,6 +22,7 @@ import { microsoftEntraId } from "./generic-oauth/providers/microsoft-entra-id.m
|
|
|
22
22
|
import { okta } from "./generic-oauth/providers/okta.mjs";
|
|
23
23
|
import { patreon } from "./generic-oauth/providers/patreon.mjs";
|
|
24
24
|
import { slack } from "./generic-oauth/providers/slack.mjs";
|
|
25
|
+
import { yandex } from "./generic-oauth/providers/yandex.mjs";
|
|
25
26
|
import { genericOAuth } from "./generic-oauth/index.mjs";
|
|
26
27
|
import { haveIBeenPwned } from "./haveibeenpwned/index.mjs";
|
|
27
28
|
import { createJwk, generateExportedKeyPair, toExpJWT } from "./jwt/utils.mjs";
|
|
@@ -46,4 +47,4 @@ import { siwe } from "./siwe/index.mjs";
|
|
|
46
47
|
import { testUtils } from "./test-utils/index.mjs";
|
|
47
48
|
import { twoFactor } from "./two-factor/index.mjs";
|
|
48
49
|
import { username } from "./username/index.mjs";
|
|
49
|
-
export { MULTI_SESSION_ERROR_CODES as ERROR_CODES, HIDE_METADATA, OAUTH_POPUP_COMPLETE_SCRIPT, OAUTH_POPUP_DATA_ELEMENT_ID, OAUTH_POPUP_ERROR_CODES, OAUTH_POPUP_MESSAGE_TYPE, OAUTH_POPUP_SCRIPT_CSP_HASH, POPUP_MARKER_COOKIE, TWO_FACTOR_ERROR_CODES, USERNAME_ERROR_CODES, admin, anonymous, auth0, bearer, captcha, createAccessControl, createJwk, customSession, deviceAuthorization, deviceAuthorizationOptionsSchema, emailOTP, generateExportedKeyPair, genericOAuth, getClient, getJwtToken, getMCPProtectedResourceMetadata, getMCPProviderMetadata, getMetadata, getOrgAdapter, gumroad, hasPermission, haveIBeenPwned, hubspot, jwt, keycloak, lastLoginMethod, line, magicLink, mcp, microsoftEntraId, multiSession, oAuthDiscoveryMetadata, oAuthProtectedResourceMetadata, oAuthProxy, oauthPopup, oidcProvider, okta, oneTap, oneTimeToken, openAPI, organization, parseRoles, patreon, phoneNumber, role, signJWT, siwe, slack, testUtils, toExpJWT, twoFactor, twoFactorClient, username, verifyJWT, withMcpAuth };
|
|
50
|
+
export { MULTI_SESSION_ERROR_CODES as ERROR_CODES, HIDE_METADATA, OAUTH_POPUP_COMPLETE_SCRIPT, OAUTH_POPUP_DATA_ELEMENT_ID, OAUTH_POPUP_ERROR_CODES, OAUTH_POPUP_MESSAGE_TYPE, OAUTH_POPUP_SCRIPT_CSP_HASH, POPUP_MARKER_COOKIE, TWO_FACTOR_ERROR_CODES, USERNAME_ERROR_CODES, admin, anonymous, auth0, bearer, captcha, createAccessControl, createJwk, customSession, deviceAuthorization, deviceAuthorizationOptionsSchema, emailOTP, generateExportedKeyPair, genericOAuth, getClient, getJwtToken, getMCPProtectedResourceMetadata, getMCPProviderMetadata, getMetadata, getOrgAdapter, gumroad, hasPermission, haveIBeenPwned, hubspot, jwt, keycloak, lastLoginMethod, line, magicLink, mcp, microsoftEntraId, multiSession, oAuthDiscoveryMetadata, oAuthProtectedResourceMetadata, oAuthProxy, oauthPopup, oidcProvider, okta, oneTap, oneTimeToken, openAPI, organization, parseRoles, patreon, phoneNumber, role, signJWT, siwe, slack, testUtils, toExpJWT, twoFactor, twoFactorClient, username, verifyJWT, withMcpAuth, yandex };
|
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
import { JWKOptions, JWSAlgorithms, Jwk, JwtOptions } from "./types.mjs";
|
|
2
2
|
import { jwt } from "./index.mjs";
|
|
3
3
|
import { JSONWebKeySet } from "jose";
|
|
4
|
-
import * as _better_fetch_fetch0 from "@better-fetch/fetch";
|
|
5
|
-
|
|
6
4
|
//#region src/plugins/jwt/client.d.ts
|
|
7
5
|
interface JwtClientOptions {
|
|
8
6
|
jwks?: {
|
|
@@ -22,7 +20,7 @@ declare const jwtClient: (options?: JwtClientOptions) => {
|
|
|
22
20
|
pathMethods: {
|
|
23
21
|
[x: string]: "GET";
|
|
24
22
|
};
|
|
25
|
-
getActions: ($fetch:
|
|
23
|
+
getActions: ($fetch: import("@better-fetch/fetch").BetterFetch) => {
|
|
26
24
|
jwks: (fetchOptions?: any) => Promise<{
|
|
27
25
|
data: null;
|
|
28
26
|
error: {
|
|
@@ -37,4 +35,4 @@ declare const jwtClient: (options?: JwtClientOptions) => {
|
|
|
37
35
|
};
|
|
38
36
|
};
|
|
39
37
|
//#endregion
|
|
40
|
-
export { jwtClient };
|
|
38
|
+
export { type JWKOptions, type JWSAlgorithms, type Jwk, type JwtOptions, jwtClient };
|
|
@@ -2,11 +2,8 @@ import { JWKOptions, JWSAlgorithms, Jwk, JwtOptions } from "./types.mjs";
|
|
|
2
2
|
import { getJwtToken, signJWT } from "./sign.mjs";
|
|
3
3
|
import { createJwk, generateExportedKeyPair, toExpJWT } from "./utils.mjs";
|
|
4
4
|
import { verifyJWT } from "./verify.mjs";
|
|
5
|
-
import * as _better_auth_core0 from "@better-auth/core";
|
|
6
|
-
import * as better_call0 from "better-call";
|
|
7
5
|
import * as z from "zod";
|
|
8
6
|
import { JSONWebKeySet, JWTPayload } from "jose";
|
|
9
|
-
|
|
10
7
|
//#region src/plugins/jwt/index.d.ts
|
|
11
8
|
declare module "@better-auth/core" {
|
|
12
9
|
interface BetterAuthPluginRegistry<AuthOptions, Options> {
|
|
@@ -20,7 +17,7 @@ declare const jwt: <O extends JwtOptions>(options?: O) => {
|
|
|
20
17
|
version: string;
|
|
21
18
|
options: NoInfer<O>;
|
|
22
19
|
endpoints: {
|
|
23
|
-
getJwks:
|
|
20
|
+
getJwks: import("better-call").StrictEndpoint<string, {
|
|
24
21
|
method: "GET";
|
|
25
22
|
metadata: {
|
|
26
23
|
openapi: {
|
|
@@ -97,10 +94,10 @@ declare const jwt: <O extends JwtOptions>(options?: O) => {
|
|
|
97
94
|
};
|
|
98
95
|
};
|
|
99
96
|
}, JSONWebKeySet>;
|
|
100
|
-
getToken:
|
|
97
|
+
getToken: import("better-call").StrictEndpoint<"/token", {
|
|
101
98
|
method: "GET";
|
|
102
99
|
requireHeaders: true;
|
|
103
|
-
use: ((inputContext:
|
|
100
|
+
use: ((inputContext: import("better-call").MiddlewareInputContext<import("better-call").MiddlewareOptions>) => Promise<{
|
|
104
101
|
session: {
|
|
105
102
|
session: Record<string, any> & {
|
|
106
103
|
id: string;
|
|
@@ -149,7 +146,7 @@ declare const jwt: <O extends JwtOptions>(options?: O) => {
|
|
|
149
146
|
}, {
|
|
150
147
|
token: string;
|
|
151
148
|
}>;
|
|
152
|
-
signJWT:
|
|
149
|
+
signJWT: import("better-call").StrictEndpoint<string, {
|
|
153
150
|
method: "POST";
|
|
154
151
|
metadata: {
|
|
155
152
|
$Infer: {
|
|
@@ -166,7 +163,7 @@ declare const jwt: <O extends JwtOptions>(options?: O) => {
|
|
|
166
163
|
}, {
|
|
167
164
|
token: string;
|
|
168
165
|
}>;
|
|
169
|
-
verifyJWT:
|
|
166
|
+
verifyJWT: import("better-call").StrictEndpoint<string, {
|
|
170
167
|
method: "POST";
|
|
171
168
|
metadata: {
|
|
172
169
|
$Infer: {
|
|
@@ -193,8 +190,8 @@ declare const jwt: <O extends JwtOptions>(options?: O) => {
|
|
|
193
190
|
};
|
|
194
191
|
hooks: {
|
|
195
192
|
after: {
|
|
196
|
-
matcher(context:
|
|
197
|
-
handler: (inputContext:
|
|
193
|
+
matcher(context: import("@better-auth/core").HookEndpointContext): boolean;
|
|
194
|
+
handler: (inputContext: import("better-call").MiddlewareInputContext<import("better-call").MiddlewareOptions>) => Promise<void>;
|
|
198
195
|
}[];
|
|
199
196
|
};
|
|
200
197
|
schema: {
|
|
@@ -221,4 +218,4 @@ declare const jwt: <O extends JwtOptions>(options?: O) => {
|
|
|
221
218
|
};
|
|
222
219
|
};
|
|
223
220
|
//#endregion
|
|
224
|
-
export { JWKOptions, JWSAlgorithms, Jwk, JwtOptions, createJwk, generateExportedKeyPair, getJwtToken, jwt, signJWT, toExpJWT, verifyJWT };
|
|
221
|
+
export { type JWKOptions, type JWSAlgorithms, type Jwk, type JwtOptions, createJwk, generateExportedKeyPair, getJwtToken, jwt, signJWT, toExpJWT, verifyJWT };
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { JwtOptions } from "./types.mjs";
|
|
2
2
|
import { GenericEndpointContext } from "@better-auth/core";
|
|
3
|
-
|
|
4
3
|
//#region src/plugins/jwt/sign.d.ts
|
|
5
4
|
type JWTPayloadWithOptional = {
|
|
6
5
|
/**
|
|
@@ -44,7 +43,8 @@ type JWTPayloadWithOptional = {
|
|
|
44
43
|
*
|
|
45
44
|
* @see {@link https://www.rfc-editor.org/rfc/rfc7519#section-4.1.6 RFC7519#section-4.1.6}
|
|
46
45
|
*/
|
|
47
|
-
iat?: number | undefined;
|
|
46
|
+
iat?: number | undefined;
|
|
47
|
+
/** Any other JWT Claim Set member. */
|
|
48
48
|
[propName: string]: unknown | undefined;
|
|
49
49
|
};
|
|
50
50
|
declare function signJWT(ctx: GenericEndpointContext, config: {
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { Session, User } from "../../types/models.mjs";
|
|
2
2
|
import { InferOptionSchema } from "../../types/plugins.mjs";
|
|
3
|
+
import "../../types/index.mjs";
|
|
3
4
|
import { schema } from "./schema.mjs";
|
|
4
5
|
import { Awaitable, GenericEndpointContext } from "@better-auth/core";
|
|
5
6
|
import { JWTPayload } from "jose";
|
|
6
|
-
|
|
7
7
|
//#region src/plugins/jwt/types.d.ts
|
|
8
8
|
interface JwtOptions {
|
|
9
9
|
jwks?: {
|
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
import { Jwk, JwtOptions } from "./types.mjs";
|
|
2
2
|
import { GenericEndpointContext } from "@better-auth/core";
|
|
3
|
-
import * as jose from "jose";
|
|
4
|
-
|
|
5
3
|
//#region src/plugins/jwt/utils.d.ts
|
|
6
4
|
/**
|
|
7
5
|
* Converts an expirationTime to ISO seconds expiration time (the format of JWT exp)
|
|
@@ -14,8 +12,8 @@ import * as jose from "jose";
|
|
|
14
12
|
*/
|
|
15
13
|
declare function toExpJWT(expirationTime: number | Date | string, iat: number): number;
|
|
16
14
|
declare function generateExportedKeyPair(options?: JwtOptions | undefined): Promise<{
|
|
17
|
-
publicWebKey: jose.JWK;
|
|
18
|
-
privateWebKey: jose.JWK;
|
|
15
|
+
publicWebKey: import("jose").JWK;
|
|
16
|
+
privateWebKey: import("jose").JWK;
|
|
19
17
|
alg: "EdDSA" | "ES256" | "ES512" | "PS256" | "RS256";
|
|
20
18
|
cfg: {
|
|
21
19
|
crv?: "Ed25519" | undefined;
|
|
@@ -15,15 +15,28 @@ const lastLoginMethodClient = (config = {}) => {
|
|
|
15
15
|
version: PACKAGE_VERSION,
|
|
16
16
|
getActions() {
|
|
17
17
|
return {
|
|
18
|
+
/**
|
|
19
|
+
* Get the last used login method from cookies
|
|
20
|
+
* @returns The last used login method or null if not found
|
|
21
|
+
*/
|
|
18
22
|
getLastUsedLoginMethod: () => {
|
|
19
23
|
return getCookieValue(cookieName);
|
|
20
24
|
},
|
|
25
|
+
/**
|
|
26
|
+
* Clear the last used login method cookie
|
|
27
|
+
* This sets the cookie with an expiration date in the past
|
|
28
|
+
*/
|
|
21
29
|
clearLastUsedLoginMethod: () => {
|
|
22
30
|
if (typeof document !== "undefined") {
|
|
23
31
|
const domainPart = config.domain ? ` domain=${config.domain};` : "";
|
|
24
32
|
document.cookie = `${cookieName}=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/;${domainPart}`;
|
|
25
33
|
}
|
|
26
34
|
},
|
|
35
|
+
/**
|
|
36
|
+
* Check if a specific login method was the last used
|
|
37
|
+
* @param method The method to check
|
|
38
|
+
* @returns True if the method was the last used, false otherwise
|
|
39
|
+
*/
|
|
27
40
|
isLastUsedLoginMethod: (method) => {
|
|
28
41
|
return getCookieValue(cookieName) === method;
|
|
29
42
|
}
|
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
import * as _better_auth_core0 from "@better-auth/core";
|
|
2
1
|
import { GenericEndpointContext } from "@better-auth/core";
|
|
3
|
-
import * as better_call0 from "better-call";
|
|
4
|
-
|
|
5
2
|
//#region src/plugins/last-login-method/index.d.ts
|
|
6
3
|
declare module "@better-auth/core" {
|
|
7
4
|
interface BetterAuthPluginRegistry<AuthOptions, Options> {
|
|
@@ -35,6 +32,15 @@ interface LastLoginMethodOptions {
|
|
|
35
32
|
* @default false
|
|
36
33
|
*/
|
|
37
34
|
storeInDatabase?: boolean | undefined;
|
|
35
|
+
/**
|
|
36
|
+
* A hook to run before the last login method is stored in the cookie.
|
|
37
|
+
* Useful if you are required to follow GDPR or other regulations to ensure that you're allowed to store the last login method in the cookie.
|
|
38
|
+
*
|
|
39
|
+
* @param ctx - The context from the hook
|
|
40
|
+
* @param lastUsedLoginMethod - The last login method
|
|
41
|
+
* @returns `true` to store the cookie, `false` to skip storing it (authentication continues either way)
|
|
42
|
+
*/
|
|
43
|
+
beforeStoreCookie?: ((ctx: GenericEndpointContext, lastUsedLoginMethod: string) => Promise<boolean> | boolean) | undefined;
|
|
38
44
|
/**
|
|
39
45
|
* Custom schema for the plugin
|
|
40
46
|
* @default undefined
|
|
@@ -51,7 +57,7 @@ interface LastLoginMethodOptions {
|
|
|
51
57
|
declare const lastLoginMethod: <O extends LastLoginMethodOptions>(userConfig?: O | undefined) => {
|
|
52
58
|
id: "last-login-method";
|
|
53
59
|
version: string;
|
|
54
|
-
init(ctx:
|
|
60
|
+
init(ctx: import("@better-auth/core").AuthContext): {
|
|
55
61
|
options: {
|
|
56
62
|
databaseHooks: {
|
|
57
63
|
user: {
|
|
@@ -98,7 +104,7 @@ declare const lastLoginMethod: <O extends LastLoginMethodOptions>(userConfig?: O
|
|
|
98
104
|
hooks: {
|
|
99
105
|
after: {
|
|
100
106
|
matcher(): true;
|
|
101
|
-
handler: (inputContext:
|
|
107
|
+
handler: (inputContext: import("better-call").MiddlewareInputContext<import("better-call").MiddlewareOptions>) => Promise<void>;
|
|
102
108
|
}[];
|
|
103
109
|
};
|
|
104
110
|
schema: O["storeInDatabase"] extends true ? {
|
|
@@ -71,6 +71,14 @@ const lastLoginMethod = (userConfig) => {
|
|
|
71
71
|
maxAge: config.maxAge,
|
|
72
72
|
httpOnly: false
|
|
73
73
|
};
|
|
74
|
+
let isPermitted = true;
|
|
75
|
+
if (config.beforeStoreCookie) try {
|
|
76
|
+
isPermitted = await config.beforeStoreCookie(ctx, lastUsedLoginMethod);
|
|
77
|
+
} catch (error) {
|
|
78
|
+
if (ctx.context.logger) ctx.context.logger.error?.("[LastLoginMethod] Error in beforeStoreCookie hook", error);
|
|
79
|
+
isPermitted = false;
|
|
80
|
+
}
|
|
81
|
+
if (!isPermitted) return;
|
|
74
82
|
ctx.setCookie(config.cookieName, lastUsedLoginMethod, cookieAttributes);
|
|
75
83
|
}
|
|
76
84
|
}
|
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
import { Awaitable, GenericEndpointContext } from "@better-auth/core";
|
|
2
|
-
import * as better_call0 from "better-call";
|
|
3
2
|
import * as z from "zod";
|
|
4
|
-
|
|
5
3
|
//#region src/plugins/magic-link/index.d.ts
|
|
6
4
|
declare module "@better-auth/core" {
|
|
7
5
|
interface BetterAuthPluginRegistry<AuthOptions, Options> {
|
|
@@ -90,9 +88,10 @@ declare const magicLink: (options: MagicLinkOptions) => {
|
|
|
90
88
|
*
|
|
91
89
|
* @see [Read our docs to learn more.](https://better-auth.com/docs/plugins/sign-in#api-method-sign-in-magic-link)
|
|
92
90
|
*/
|
|
93
|
-
signInMagicLink:
|
|
91
|
+
signInMagicLink: import("better-call").StrictEndpoint<"/sign-in/magic-link", {
|
|
94
92
|
method: "POST";
|
|
95
93
|
requireHeaders: true;
|
|
94
|
+
use: ((inputContext: import("better-call").MiddlewareInputContext<import("better-call").MiddlewareOptions>) => Promise<void>)[];
|
|
96
95
|
body: z.ZodObject<{
|
|
97
96
|
email: z.ZodEmail;
|
|
98
97
|
name: z.ZodOptional<z.ZodString>;
|
|
@@ -142,7 +141,7 @@ declare const magicLink: (options: MagicLinkOptions) => {
|
|
|
142
141
|
*
|
|
143
142
|
* @see [Read our docs to learn more.](https://better-auth.com/docs/plugins/magic-link#api-method-magic-link-verify)
|
|
144
143
|
*/
|
|
145
|
-
magicLinkVerify:
|
|
144
|
+
magicLinkVerify: import("better-call").StrictEndpoint<"/magic-link/verify", {
|
|
146
145
|
method: "GET";
|
|
147
146
|
query: z.ZodObject<{
|
|
148
147
|
token: z.ZodString;
|
|
@@ -150,7 +149,7 @@ declare const magicLink: (options: MagicLinkOptions) => {
|
|
|
150
149
|
errorCallbackURL: z.ZodOptional<z.ZodString>;
|
|
151
150
|
newUserCallbackURL: z.ZodOptional<z.ZodString>;
|
|
152
151
|
}, z.core.$strip>;
|
|
153
|
-
use: ((inputContext:
|
|
152
|
+
use: ((inputContext: import("better-call").MiddlewareInputContext<import("better-call").MiddlewareOptions>) => Promise<void>)[];
|
|
154
153
|
requireHeaders: true;
|
|
155
154
|
metadata: {
|
|
156
155
|
openapi: {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { originCheck } from "../../api/middlewares/origin-check.mjs";
|
|
1
|
+
import { formCsrfMiddleware, originCheck } from "../../api/middlewares/origin-check.mjs";
|
|
2
2
|
import { parseSessionOutput, parseUserOutput } from "../../db/schema.mjs";
|
|
3
3
|
import { generateRandomString } from "../../crypto/random.mjs";
|
|
4
4
|
import { setSessionCookie } from "../../cookies/index.mjs";
|
|
@@ -38,9 +38,25 @@ const magicLink = (options) => {
|
|
|
38
38
|
id: "magic-link",
|
|
39
39
|
version: PACKAGE_VERSION,
|
|
40
40
|
endpoints: {
|
|
41
|
+
/**
|
|
42
|
+
* ### Endpoint
|
|
43
|
+
*
|
|
44
|
+
* POST `/sign-in/magic-link`
|
|
45
|
+
*
|
|
46
|
+
* ### API Methods
|
|
47
|
+
*
|
|
48
|
+
* **server:**
|
|
49
|
+
* `auth.api.signInMagicLink`
|
|
50
|
+
*
|
|
51
|
+
* **client:**
|
|
52
|
+
* `authClient.signIn.magicLink`
|
|
53
|
+
*
|
|
54
|
+
* @see [Read our docs to learn more.](https://better-auth.com/docs/plugins/sign-in#api-method-sign-in-magic-link)
|
|
55
|
+
*/
|
|
41
56
|
signInMagicLink: createAuthEndpoint("/sign-in/magic-link", {
|
|
42
57
|
method: "POST",
|
|
43
58
|
requireHeaders: true,
|
|
59
|
+
use: [formCsrfMiddleware],
|
|
44
60
|
body: signInMagicLinkBodySchema,
|
|
45
61
|
metadata: { openapi: {
|
|
46
62
|
operationId: "signInWithMagicLink",
|
|
@@ -81,6 +97,21 @@ const magicLink = (options) => {
|
|
|
81
97
|
}, ctx);
|
|
82
98
|
return ctx.json({ status: true });
|
|
83
99
|
}),
|
|
100
|
+
/**
|
|
101
|
+
* ### Endpoint
|
|
102
|
+
*
|
|
103
|
+
* GET `/magic-link/verify`
|
|
104
|
+
*
|
|
105
|
+
* ### API Methods
|
|
106
|
+
*
|
|
107
|
+
* **server:**
|
|
108
|
+
* `auth.api.magicLinkVerify`
|
|
109
|
+
*
|
|
110
|
+
* **client:**
|
|
111
|
+
* `authClient.magicLink.verify`
|
|
112
|
+
*
|
|
113
|
+
* @see [Read our docs to learn more.](https://better-auth.com/docs/plugins/magic-link#api-method-magic-link-verify)
|
|
114
|
+
*/
|
|
84
115
|
magicLinkVerify: createAuthEndpoint("/magic-link/verify", {
|
|
85
116
|
method: "GET",
|
|
86
117
|
query: magicLinkVerifyQuerySchema,
|
|
@@ -94,6 +94,18 @@ async function authorizeMCPOAuth(ctx, options) {
|
|
|
94
94
|
scope: requestScope,
|
|
95
95
|
userId: session.user.id,
|
|
96
96
|
authTime: new Date(session.session.createdAt).getTime(),
|
|
97
|
+
/**
|
|
98
|
+
* If the prompt is set to `consent`, then we need
|
|
99
|
+
* to require the user to consent to the scopes.
|
|
100
|
+
*
|
|
101
|
+
* This means the code now needs to be treated as a
|
|
102
|
+
* consent request.
|
|
103
|
+
*
|
|
104
|
+
* once the user consents, the code will be updated
|
|
105
|
+
* with the actual code. This is to prevent the
|
|
106
|
+
* client from using the code before the user
|
|
107
|
+
* consents.
|
|
108
|
+
*/
|
|
97
109
|
requireConsent: query.prompt === "consent",
|
|
98
110
|
state: query.prompt === "consent" ? query.state : null,
|
|
99
111
|
codeChallenge: query.code_challenge,
|
|
@@ -24,7 +24,9 @@ interface NodeLikeRequest {
|
|
|
24
24
|
}
|
|
25
25
|
interface NodeLikeResponse {
|
|
26
26
|
set?: (name: string, value: string) => void;
|
|
27
|
+
get?: (name: string) => string | undefined;
|
|
27
28
|
setHeader?: (name: string, value: string) => void;
|
|
29
|
+
getHeader?: (name: string) => string | number | string[] | undefined;
|
|
28
30
|
status?: (code: number) => {
|
|
29
31
|
json: (body: unknown) => void;
|
|
30
32
|
};
|