better-auth 1.6.26 → 1.6.27
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/api/index.d.mts +74 -73
- package/dist/api/middlewares/authorization.d.mts +4 -4
- package/dist/api/middlewares/origin-check.d.mts +3 -3
- package/dist/api/routes/account.d.mts +6 -6
- package/dist/api/routes/email-verification.d.mts +1 -1
- package/dist/api/routes/password.d.mts +4 -4
- package/dist/api/routes/session.d.mts +16 -16
- package/dist/api/routes/session.mjs +2 -3
- package/dist/api/routes/sign-in.d.mts +1 -1
- package/dist/api/routes/sign-up.d.mts +1 -1
- package/dist/api/routes/update-session.d.mts +2 -2
- package/dist/api/routes/update-user.d.mts +11 -11
- package/dist/client/session-atom.mjs +33 -44
- package/dist/integrations/next-js.d.mts +2 -2
- package/dist/integrations/svelte-kit.d.mts +1 -1
- package/dist/integrations/tanstack-start-solid.d.mts +1 -1
- package/dist/integrations/tanstack-start.d.mts +1 -1
- package/dist/package.mjs +1 -1
- package/dist/plugins/admin/admin.d.mts +25 -25
- package/dist/plugins/anonymous/index.d.mts +3 -3
- package/dist/plugins/bearer/index.d.mts +3 -3
- package/dist/plugins/custom-session/index.d.mts +1 -1
- package/dist/plugins/email-otp/index.d.mts +6 -6
- package/dist/plugins/generic-oauth/index.d.mts +2 -2
- package/dist/plugins/jwt/index.d.mts +3 -3
- package/dist/plugins/last-login-method/index.d.mts +2 -2
- package/dist/plugins/magic-link/index.d.mts +2 -2
- package/dist/plugins/mcp/index.d.mts +3 -3
- package/dist/plugins/multi-session/index.d.mts +3 -3
- package/dist/plugins/oauth-popup/index.d.mts +1 -1
- package/dist/plugins/oauth-proxy/index.d.mts +3 -3
- package/dist/plugins/oidc-provider/index.d.mts +6 -6
- package/dist/plugins/one-time-token/index.d.mts +3 -3
- package/dist/plugins/organization/organization.d.mts +28 -4
- package/dist/plugins/organization/routes/crud-access-control.d.mts +140 -20
- package/dist/plugins/organization/routes/crud-invites.d.mts +149 -29
- package/dist/plugins/organization/routes/crud-members.d.mts +150 -30
- package/dist/plugins/organization/routes/crud-org.d.mts +96 -24
- package/dist/plugins/organization/routes/crud-team.d.mts +207 -39
- package/dist/plugins/phone-number/index.d.mts +1 -1
- package/dist/plugins/two-factor/backup-codes/index.d.mts +2 -2
- package/dist/plugins/two-factor/index.d.mts +10 -10
- package/dist/plugins/two-factor/totp/index.d.mts +2 -2
- package/dist/plugins/username/index.d.mts +1 -1
- package/package.json +10 -9
|
@@ -43,9 +43,9 @@ declare function requireResourceOwnership(config: {
|
|
|
43
43
|
* @default "FORBIDDEN" (403)
|
|
44
44
|
*/
|
|
45
45
|
forbiddenStatus?: "FORBIDDEN" | "UNAUTHORIZED";
|
|
46
|
-
}): (inputContext: import("better-call").MiddlewareInputContext<import("better-call").MiddlewareOptions>) => Promise<{
|
|
46
|
+
}): import("better-call").Middleware<import("better-call").MiddlewareOptions, (inputContext: import("better-call").MiddlewareInputContext<import("better-call").MiddlewareOptions>) => Promise<{
|
|
47
47
|
verifiedResource: {};
|
|
48
|
-
}
|
|
48
|
+
}>>;
|
|
49
49
|
/**
|
|
50
50
|
* Middleware that verifies the authenticated user is a member of a
|
|
51
51
|
* specific organization with one of the allowed roles.
|
|
@@ -66,8 +66,8 @@ declare function requireOrgRole(config: {
|
|
|
66
66
|
* any org membership is sufficient.
|
|
67
67
|
*/
|
|
68
68
|
allowedRoles?: string[];
|
|
69
|
-
}): (inputContext: import("better-call").MiddlewareInputContext<import("better-call").MiddlewareOptions>) => Promise<{
|
|
69
|
+
}): import("better-call").Middleware<import("better-call").MiddlewareOptions, (inputContext: import("better-call").MiddlewareInputContext<import("better-call").MiddlewareOptions>) => Promise<{
|
|
70
70
|
verifiedMember: {};
|
|
71
|
-
}
|
|
71
|
+
}>>;
|
|
72
72
|
//#endregion
|
|
73
73
|
export { requireOrgRole, requireResourceOwnership };
|
|
@@ -4,12 +4,12 @@ import { GenericEndpointContext } from "@better-auth/core";
|
|
|
4
4
|
* A middleware to validate callbackURL and origin against trustedOrigins.
|
|
5
5
|
* Also handles CSRF protection using Fetch Metadata for first-login scenarios.
|
|
6
6
|
*/
|
|
7
|
-
declare const originCheckMiddleware: (inputContext: import("better-call").MiddlewareInputContext<import("better-call").MiddlewareOptions>) => Promise<void
|
|
8
|
-
declare const originCheck: (getValue: (ctx: GenericEndpointContext) => string | string[]) => (inputContext: import("better-call").MiddlewareInputContext<import("better-call").MiddlewareOptions>) => Promise<void
|
|
7
|
+
declare const originCheckMiddleware: import("better-call").Middleware<import("better-call").MiddlewareOptions, (inputContext: import("better-call").MiddlewareInputContext<import("better-call").MiddlewareOptions>) => Promise<void>>;
|
|
8
|
+
declare const originCheck: (getValue: (ctx: GenericEndpointContext) => string | string[]) => import("better-call").Middleware<import("better-call").MiddlewareOptions, (inputContext: import("better-call").MiddlewareInputContext<import("better-call").MiddlewareOptions>) => Promise<void>>;
|
|
9
9
|
/**
|
|
10
10
|
* Middleware for CSRF protection using Fetch Metadata headers.
|
|
11
11
|
* This prevents cross-site navigation login attacks while supporting progressive enhancement.
|
|
12
12
|
*/
|
|
13
|
-
declare const formCsrfMiddleware: (inputContext: import("better-call").MiddlewareInputContext<import("better-call").MiddlewareOptions>) => Promise<void
|
|
13
|
+
declare const formCsrfMiddleware: import("better-call").Middleware<import("better-call").MiddlewareOptions, (inputContext: import("better-call").MiddlewareInputContext<import("better-call").MiddlewareOptions>) => Promise<void>>;
|
|
14
14
|
//#endregion
|
|
15
15
|
export { formCsrfMiddleware, originCheck, originCheckMiddleware };
|
|
@@ -2,7 +2,7 @@ import * as z from "zod";
|
|
|
2
2
|
//#region src/api/routes/account.d.ts
|
|
3
3
|
declare const listUserAccounts: import("better-call").StrictEndpoint<"/list-accounts", {
|
|
4
4
|
method: "GET";
|
|
5
|
-
use: ((inputContext: import("better-call").MiddlewareInputContext<import("better-call").MiddlewareOptions>) => Promise<{
|
|
5
|
+
use: import("better-call").Middleware<import("better-call").MiddlewareOptions, (inputContext: import("better-call").MiddlewareInputContext<import("better-call").MiddlewareOptions>) => Promise<{
|
|
6
6
|
session: {
|
|
7
7
|
session: Record<string, any> & {
|
|
8
8
|
id: string;
|
|
@@ -24,7 +24,7 @@ declare const listUserAccounts: import("better-call").StrictEndpoint<"/list-acco
|
|
|
24
24
|
image?: string | null | undefined;
|
|
25
25
|
};
|
|
26
26
|
};
|
|
27
|
-
}
|
|
27
|
+
}>>[];
|
|
28
28
|
metadata: {
|
|
29
29
|
openapi: {
|
|
30
30
|
operationId: string;
|
|
@@ -103,7 +103,7 @@ declare const linkSocialAccount: import("better-call").StrictEndpoint<"/link-soc
|
|
|
103
103
|
disableRedirect: z.ZodOptional<z.ZodBoolean>;
|
|
104
104
|
additionalData: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodAny>>;
|
|
105
105
|
}, z.core.$strip>;
|
|
106
|
-
use: ((inputContext: import("better-call").MiddlewareInputContext<import("better-call").MiddlewareOptions>) => Promise<{
|
|
106
|
+
use: import("better-call").Middleware<import("better-call").MiddlewareOptions, (inputContext: import("better-call").MiddlewareInputContext<import("better-call").MiddlewareOptions>) => Promise<{
|
|
107
107
|
session: {
|
|
108
108
|
session: Record<string, any> & {
|
|
109
109
|
id: string;
|
|
@@ -125,7 +125,7 @@ declare const linkSocialAccount: import("better-call").StrictEndpoint<"/link-soc
|
|
|
125
125
|
image?: string | null | undefined;
|
|
126
126
|
};
|
|
127
127
|
};
|
|
128
|
-
}
|
|
128
|
+
}>>[];
|
|
129
129
|
metadata: {
|
|
130
130
|
openapi: {
|
|
131
131
|
description: string;
|
|
@@ -168,7 +168,7 @@ declare const unlinkAccount: import("better-call").StrictEndpoint<"/unlink-accou
|
|
|
168
168
|
providerId: z.ZodString;
|
|
169
169
|
accountId: z.ZodOptional<z.ZodString>;
|
|
170
170
|
}, z.core.$strip>;
|
|
171
|
-
use: ((inputContext: import("better-call").MiddlewareInputContext<import("better-call").MiddlewareOptions>) => Promise<{
|
|
171
|
+
use: import("better-call").Middleware<import("better-call").MiddlewareOptions, (inputContext: import("better-call").MiddlewareInputContext<import("better-call").MiddlewareOptions>) => Promise<{
|
|
172
172
|
session: {
|
|
173
173
|
session: Record<string, any> & {
|
|
174
174
|
id: string;
|
|
@@ -190,7 +190,7 @@ declare const unlinkAccount: import("better-call").StrictEndpoint<"/unlink-accou
|
|
|
190
190
|
image?: string | null | undefined;
|
|
191
191
|
};
|
|
192
192
|
};
|
|
193
|
-
}
|
|
193
|
+
}>>[];
|
|
194
194
|
metadata: {
|
|
195
195
|
openapi: {
|
|
196
196
|
description: string;
|
|
@@ -103,7 +103,7 @@ declare const verifyEmail: import("better-call").StrictEndpoint<"/verify-email",
|
|
|
103
103
|
token: z.ZodString;
|
|
104
104
|
callbackURL: z.ZodOptional<z.ZodString>;
|
|
105
105
|
}, z.core.$strip>;
|
|
106
|
-
use: ((inputContext: import("better-call").MiddlewareInputContext<import("better-call").MiddlewareOptions>) => Promise<void
|
|
106
|
+
use: import("better-call").Middleware<import("better-call").MiddlewareOptions, (inputContext: import("better-call").MiddlewareInputContext<import("better-call").MiddlewareOptions>) => Promise<void>>[];
|
|
107
107
|
metadata: {
|
|
108
108
|
openapi: {
|
|
109
109
|
description: string;
|
|
@@ -32,7 +32,7 @@ declare const requestPasswordReset: import("better-call").StrictEndpoint<"/reque
|
|
|
32
32
|
};
|
|
33
33
|
};
|
|
34
34
|
};
|
|
35
|
-
use: ((inputContext: import("better-call").MiddlewareInputContext<import("better-call").MiddlewareOptions>) => Promise<void
|
|
35
|
+
use: import("better-call").Middleware<import("better-call").MiddlewareOptions, (inputContext: import("better-call").MiddlewareInputContext<import("better-call").MiddlewareOptions>) => Promise<void>>[];
|
|
36
36
|
}, {
|
|
37
37
|
status: boolean;
|
|
38
38
|
message: string;
|
|
@@ -43,7 +43,7 @@ declare const requestPasswordResetCallback: import("better-call").StrictEndpoint
|
|
|
43
43
|
query: z.ZodObject<{
|
|
44
44
|
callbackURL: z.ZodString;
|
|
45
45
|
}, z.core.$strip>;
|
|
46
|
-
use: ((inputContext: import("better-call").MiddlewareInputContext<import("better-call").MiddlewareOptions>) => Promise<void
|
|
46
|
+
use: import("better-call").Middleware<import("better-call").MiddlewareOptions, (inputContext: import("better-call").MiddlewareInputContext<import("better-call").MiddlewareOptions>) => Promise<void>>[];
|
|
47
47
|
metadata: {
|
|
48
48
|
openapi: {
|
|
49
49
|
operationId: string;
|
|
@@ -150,7 +150,7 @@ declare const verifyPassword: import("better-call").StrictEndpoint<"/verify-pass
|
|
|
150
150
|
};
|
|
151
151
|
};
|
|
152
152
|
};
|
|
153
|
-
use: ((inputContext: import("better-call").MiddlewareInputContext<import("better-call").MiddlewareOptions>) => Promise<{
|
|
153
|
+
use: import("better-call").Middleware<import("better-call").MiddlewareOptions, (inputContext: import("better-call").MiddlewareInputContext<import("better-call").MiddlewareOptions>) => Promise<{
|
|
154
154
|
session: {
|
|
155
155
|
session: Record<string, any> & {
|
|
156
156
|
id: string;
|
|
@@ -172,7 +172,7 @@ declare const verifyPassword: import("better-call").StrictEndpoint<"/verify-pass
|
|
|
172
172
|
image?: string | null | undefined;
|
|
173
173
|
};
|
|
174
174
|
};
|
|
175
|
-
}
|
|
175
|
+
}>>[];
|
|
176
176
|
}, {
|
|
177
177
|
status: boolean;
|
|
178
178
|
}>;
|
|
@@ -92,7 +92,7 @@ declare const getAuthoritativeSessionFromCtx: <U extends Record<string, any> = R
|
|
|
92
92
|
/**
|
|
93
93
|
* The middleware forces the endpoint to require a valid session.
|
|
94
94
|
*/
|
|
95
|
-
declare const sessionMiddleware: (inputContext: import("better-call").MiddlewareInputContext<import("better-call").MiddlewareOptions>) => Promise<{
|
|
95
|
+
declare const sessionMiddleware: import("better-call").Middleware<import("better-call").MiddlewareOptions, (inputContext: import("better-call").MiddlewareInputContext<import("better-call").MiddlewareOptions>) => Promise<{
|
|
96
96
|
session: {
|
|
97
97
|
session: Record<string, any> & {
|
|
98
98
|
id: string;
|
|
@@ -114,12 +114,12 @@ declare const sessionMiddleware: (inputContext: import("better-call").Middleware
|
|
|
114
114
|
image?: string | null | undefined;
|
|
115
115
|
};
|
|
116
116
|
};
|
|
117
|
-
}
|
|
117
|
+
}>>;
|
|
118
118
|
/**
|
|
119
119
|
* This middleware forces the endpoint to require a valid authoritative session.
|
|
120
120
|
* This should be used for sensitive operations like password changes, account deletion, etc.
|
|
121
121
|
*/
|
|
122
|
-
declare const sensitiveSessionMiddleware: (inputContext: import("better-call").MiddlewareInputContext<import("better-call").MiddlewareOptions>) => Promise<{
|
|
122
|
+
declare const sensitiveSessionMiddleware: import("better-call").Middleware<import("better-call").MiddlewareOptions, (inputContext: import("better-call").MiddlewareInputContext<import("better-call").MiddlewareOptions>) => Promise<{
|
|
123
123
|
session: {
|
|
124
124
|
session: Record<string, any> & {
|
|
125
125
|
id: string;
|
|
@@ -141,12 +141,12 @@ declare const sensitiveSessionMiddleware: (inputContext: import("better-call").M
|
|
|
141
141
|
image?: string | null | undefined;
|
|
142
142
|
};
|
|
143
143
|
};
|
|
144
|
-
}
|
|
144
|
+
}>>;
|
|
145
145
|
/**
|
|
146
146
|
* This middleware allows you to call the endpoint on the client if session is valid.
|
|
147
147
|
* However, if called on the server, no session is required.
|
|
148
148
|
*/
|
|
149
|
-
declare const requestOnlySessionMiddleware: (inputContext: import("better-call").MiddlewareInputContext<import("better-call").MiddlewareOptions>) => Promise<{
|
|
149
|
+
declare const requestOnlySessionMiddleware: import("better-call").Middleware<import("better-call").MiddlewareOptions, (inputContext: import("better-call").MiddlewareInputContext<import("better-call").MiddlewareOptions>) => Promise<{
|
|
150
150
|
session: {
|
|
151
151
|
session: Record<string, any> & {
|
|
152
152
|
id: string;
|
|
@@ -168,7 +168,7 @@ declare const requestOnlySessionMiddleware: (inputContext: import("better-call")
|
|
|
168
168
|
image?: string | null | undefined;
|
|
169
169
|
};
|
|
170
170
|
} | null;
|
|
171
|
-
}
|
|
171
|
+
}>>;
|
|
172
172
|
/**
|
|
173
173
|
* This middleware forces the endpoint to require a valid session,
|
|
174
174
|
* as well as making sure the session is fresh before proceeding.
|
|
@@ -176,7 +176,7 @@ declare const requestOnlySessionMiddleware: (inputContext: import("better-call")
|
|
|
176
176
|
* Session freshness check will be skipped if the session config's freshAge
|
|
177
177
|
* is set to 0
|
|
178
178
|
*/
|
|
179
|
-
declare const freshSessionMiddleware: (inputContext: import("better-call").MiddlewareInputContext<import("better-call").MiddlewareOptions>) => Promise<{
|
|
179
|
+
declare const freshSessionMiddleware: import("better-call").Middleware<import("better-call").MiddlewareOptions, (inputContext: import("better-call").MiddlewareInputContext<import("better-call").MiddlewareOptions>) => Promise<{
|
|
180
180
|
session: {
|
|
181
181
|
session: Record<string, any> & {
|
|
182
182
|
id: string;
|
|
@@ -198,14 +198,14 @@ declare const freshSessionMiddleware: (inputContext: import("better-call").Middl
|
|
|
198
198
|
image?: string | null | undefined;
|
|
199
199
|
};
|
|
200
200
|
};
|
|
201
|
-
}
|
|
201
|
+
}>>;
|
|
202
202
|
/**
|
|
203
203
|
* user active sessions list
|
|
204
204
|
*/
|
|
205
205
|
declare const listSessions: <Option extends BetterAuthOptions>() => import("better-call").StrictEndpoint<"/list-sessions", {
|
|
206
206
|
method: "GET";
|
|
207
207
|
operationId: string;
|
|
208
|
-
use: ((inputContext: import("better-call").MiddlewareInputContext<import("better-call").MiddlewareOptions>) => Promise<{
|
|
208
|
+
use: import("better-call").Middleware<import("better-call").MiddlewareOptions, (inputContext: import("better-call").MiddlewareInputContext<import("better-call").MiddlewareOptions>) => Promise<{
|
|
209
209
|
session: {
|
|
210
210
|
session: Record<string, any> & {
|
|
211
211
|
id: string;
|
|
@@ -227,7 +227,7 @@ declare const listSessions: <Option extends BetterAuthOptions>() => import("bett
|
|
|
227
227
|
image?: string | null | undefined;
|
|
228
228
|
};
|
|
229
229
|
};
|
|
230
|
-
}
|
|
230
|
+
}>>[];
|
|
231
231
|
requireHeaders: true;
|
|
232
232
|
metadata: {
|
|
233
233
|
openapi: {
|
|
@@ -268,7 +268,7 @@ declare const revokeSession: import("better-call").StrictEndpoint<"/revoke-sessi
|
|
|
268
268
|
body: z.ZodObject<{
|
|
269
269
|
token: z.ZodString;
|
|
270
270
|
}, z.core.$strip>;
|
|
271
|
-
use: ((inputContext: import("better-call").MiddlewareInputContext<import("better-call").MiddlewareOptions>) => Promise<{
|
|
271
|
+
use: import("better-call").Middleware<import("better-call").MiddlewareOptions, (inputContext: import("better-call").MiddlewareInputContext<import("better-call").MiddlewareOptions>) => Promise<{
|
|
272
272
|
session: {
|
|
273
273
|
session: Record<string, any> & {
|
|
274
274
|
id: string;
|
|
@@ -290,7 +290,7 @@ declare const revokeSession: import("better-call").StrictEndpoint<"/revoke-sessi
|
|
|
290
290
|
image?: string | null | undefined;
|
|
291
291
|
};
|
|
292
292
|
};
|
|
293
|
-
}
|
|
293
|
+
}>>[];
|
|
294
294
|
requireHeaders: true;
|
|
295
295
|
metadata: {
|
|
296
296
|
openapi: {
|
|
@@ -340,7 +340,7 @@ declare const revokeSession: import("better-call").StrictEndpoint<"/revoke-sessi
|
|
|
340
340
|
*/
|
|
341
341
|
declare const revokeSessions: import("better-call").StrictEndpoint<"/revoke-sessions", {
|
|
342
342
|
method: "POST";
|
|
343
|
-
use: ((inputContext: import("better-call").MiddlewareInputContext<import("better-call").MiddlewareOptions>) => Promise<{
|
|
343
|
+
use: import("better-call").Middleware<import("better-call").MiddlewareOptions, (inputContext: import("better-call").MiddlewareInputContext<import("better-call").MiddlewareOptions>) => Promise<{
|
|
344
344
|
session: {
|
|
345
345
|
session: Record<string, any> & {
|
|
346
346
|
id: string;
|
|
@@ -362,7 +362,7 @@ declare const revokeSessions: import("better-call").StrictEndpoint<"/revoke-sess
|
|
|
362
362
|
image?: string | null | undefined;
|
|
363
363
|
};
|
|
364
364
|
};
|
|
365
|
-
}
|
|
365
|
+
}>>[];
|
|
366
366
|
requireHeaders: true;
|
|
367
367
|
metadata: {
|
|
368
368
|
openapi: {
|
|
@@ -394,7 +394,7 @@ declare const revokeSessions: import("better-call").StrictEndpoint<"/revoke-sess
|
|
|
394
394
|
declare const revokeOtherSessions: import("better-call").StrictEndpoint<"/revoke-other-sessions", {
|
|
395
395
|
method: "POST";
|
|
396
396
|
requireHeaders: true;
|
|
397
|
-
use: ((inputContext: import("better-call").MiddlewareInputContext<import("better-call").MiddlewareOptions>) => Promise<{
|
|
397
|
+
use: import("better-call").Middleware<import("better-call").MiddlewareOptions, (inputContext: import("better-call").MiddlewareInputContext<import("better-call").MiddlewareOptions>) => Promise<{
|
|
398
398
|
session: {
|
|
399
399
|
session: Record<string, any> & {
|
|
400
400
|
id: string;
|
|
@@ -416,7 +416,7 @@ declare const revokeOtherSessions: import("better-call").StrictEndpoint<"/revoke
|
|
|
416
416
|
image?: string | null | undefined;
|
|
417
417
|
};
|
|
418
418
|
};
|
|
419
|
-
}
|
|
419
|
+
}>>[];
|
|
420
420
|
metadata: {
|
|
421
421
|
openapi: {
|
|
422
422
|
description: string;
|
|
@@ -295,9 +295,8 @@ const getSessionFromCtx = async (ctx, config) => {
|
|
|
295
295
|
if (session.headers) session.headers.forEach((value, key) => {
|
|
296
296
|
const lowerKey = key.toLowerCase();
|
|
297
297
|
if (lowerKey === "cache-control" || lowerKey === "pragma") return;
|
|
298
|
-
if (
|
|
299
|
-
else
|
|
300
|
-
else ctx.context.responseHeaders.set(key, value);
|
|
298
|
+
if (lowerKey === "set-cookie") ctx.responseHeaders.append(key, value);
|
|
299
|
+
else ctx.responseHeaders.set(key, value);
|
|
301
300
|
});
|
|
302
301
|
ctx.context.session = session.response;
|
|
303
302
|
return session.response;
|
|
@@ -111,7 +111,7 @@ declare const signInSocial: <O extends BetterAuthOptions>() => import("better-ca
|
|
|
111
111
|
declare const signInEmail: <O extends BetterAuthOptions>() => import("better-call").StrictEndpoint<"/sign-in/email", {
|
|
112
112
|
method: "POST";
|
|
113
113
|
operationId: string;
|
|
114
|
-
use: ((inputContext: import("better-call").MiddlewareInputContext<import("better-call").MiddlewareOptions>) => Promise<void
|
|
114
|
+
use: import("better-call").Middleware<import("better-call").MiddlewareOptions, (inputContext: import("better-call").MiddlewareInputContext<import("better-call").MiddlewareOptions>) => Promise<void>>[];
|
|
115
115
|
cloneRequest: true;
|
|
116
116
|
body: z.ZodObject<{
|
|
117
117
|
email: z.ZodString;
|
|
@@ -6,7 +6,7 @@ import * as z from "zod";
|
|
|
6
6
|
declare const signUpEmail: <O extends BetterAuthOptions>() => import("better-call").StrictEndpoint<"/sign-up/email", {
|
|
7
7
|
method: "POST";
|
|
8
8
|
operationId: string;
|
|
9
|
-
use: ((inputContext: import("better-call").MiddlewareInputContext<import("better-call").MiddlewareOptions>) => Promise<void
|
|
9
|
+
use: import("better-call").Middleware<import("better-call").MiddlewareOptions, (inputContext: import("better-call").MiddlewareInputContext<import("better-call").MiddlewareOptions>) => Promise<void>>[];
|
|
10
10
|
body: z.ZodIntersection<z.ZodObject<{
|
|
11
11
|
name: z.ZodString;
|
|
12
12
|
email: z.ZodEmail;
|
|
@@ -7,7 +7,7 @@ declare const updateSession: <O extends BetterAuthOptions>() => import("better-c
|
|
|
7
7
|
method: "POST";
|
|
8
8
|
operationId: string;
|
|
9
9
|
body: z.ZodRecord<z.ZodString, z.ZodAny>;
|
|
10
|
-
use: ((inputContext: import("better-call").MiddlewareInputContext<import("better-call").MiddlewareOptions>) => Promise<{
|
|
10
|
+
use: import("better-call").Middleware<import("better-call").MiddlewareOptions, (inputContext: import("better-call").MiddlewareInputContext<import("better-call").MiddlewareOptions>) => Promise<{
|
|
11
11
|
session: {
|
|
12
12
|
session: Record<string, any> & {
|
|
13
13
|
id: string;
|
|
@@ -29,7 +29,7 @@ declare const updateSession: <O extends BetterAuthOptions>() => import("better-c
|
|
|
29
29
|
image?: string | null | undefined;
|
|
30
30
|
};
|
|
31
31
|
};
|
|
32
|
-
}
|
|
32
|
+
}>>[];
|
|
33
33
|
metadata: {
|
|
34
34
|
$Infer: {
|
|
35
35
|
body: Partial<AdditionalSessionFieldsInput<O>>;
|
|
@@ -7,7 +7,7 @@ declare const updateUser: <O extends BetterAuthOptions>() => import("better-call
|
|
|
7
7
|
method: "POST";
|
|
8
8
|
operationId: string;
|
|
9
9
|
body: z.ZodRecord<z.ZodString, z.ZodAny>;
|
|
10
|
-
use: ((inputContext: import("better-call").MiddlewareInputContext<import("better-call").MiddlewareOptions>) => Promise<{
|
|
10
|
+
use: import("better-call").Middleware<import("better-call").MiddlewareOptions, (inputContext: import("better-call").MiddlewareInputContext<import("better-call").MiddlewareOptions>) => Promise<{
|
|
11
11
|
session: {
|
|
12
12
|
session: Record<string, any> & {
|
|
13
13
|
id: string;
|
|
@@ -29,7 +29,7 @@ declare const updateUser: <O extends BetterAuthOptions>() => import("better-call
|
|
|
29
29
|
image?: string | null | undefined;
|
|
30
30
|
};
|
|
31
31
|
};
|
|
32
|
-
}
|
|
32
|
+
}>>[];
|
|
33
33
|
metadata: {
|
|
34
34
|
$Infer: {
|
|
35
35
|
body: Partial<AdditionalUserFieldsInput<O>> & {
|
|
@@ -91,7 +91,7 @@ declare const changePassword: import("better-call").StrictEndpoint<"/change-pass
|
|
|
91
91
|
currentPassword: z.ZodString;
|
|
92
92
|
revokeOtherSessions: z.ZodOptional<z.ZodBoolean>;
|
|
93
93
|
}, z.core.$strip>;
|
|
94
|
-
use: ((inputContext: import("better-call").MiddlewareInputContext<import("better-call").MiddlewareOptions>) => Promise<{
|
|
94
|
+
use: import("better-call").Middleware<import("better-call").MiddlewareOptions, (inputContext: import("better-call").MiddlewareInputContext<import("better-call").MiddlewareOptions>) => Promise<{
|
|
95
95
|
session: {
|
|
96
96
|
session: Record<string, any> & {
|
|
97
97
|
id: string;
|
|
@@ -113,7 +113,7 @@ declare const changePassword: import("better-call").StrictEndpoint<"/change-pass
|
|
|
113
113
|
image?: string | null | undefined;
|
|
114
114
|
};
|
|
115
115
|
};
|
|
116
|
-
}
|
|
116
|
+
}>>[];
|
|
117
117
|
metadata: {
|
|
118
118
|
openapi: {
|
|
119
119
|
operationId: string;
|
|
@@ -204,7 +204,7 @@ declare const setPassword: import("better-call").StrictEndpoint<string, {
|
|
|
204
204
|
body: z.ZodObject<{
|
|
205
205
|
newPassword: z.ZodString;
|
|
206
206
|
}, z.core.$strip>;
|
|
207
|
-
use: ((inputContext: import("better-call").MiddlewareInputContext<import("better-call").MiddlewareOptions>) => Promise<{
|
|
207
|
+
use: import("better-call").Middleware<import("better-call").MiddlewareOptions, (inputContext: import("better-call").MiddlewareInputContext<import("better-call").MiddlewareOptions>) => Promise<{
|
|
208
208
|
session: {
|
|
209
209
|
session: Record<string, any> & {
|
|
210
210
|
id: string;
|
|
@@ -226,13 +226,13 @@ declare const setPassword: import("better-call").StrictEndpoint<string, {
|
|
|
226
226
|
image?: string | null | undefined;
|
|
227
227
|
};
|
|
228
228
|
};
|
|
229
|
-
}
|
|
229
|
+
}>>[];
|
|
230
230
|
}, {
|
|
231
231
|
status: boolean;
|
|
232
232
|
}>;
|
|
233
233
|
declare const deleteUser: import("better-call").StrictEndpoint<"/delete-user", {
|
|
234
234
|
method: "POST";
|
|
235
|
-
use: ((inputContext: import("better-call").MiddlewareInputContext<import("better-call").MiddlewareOptions>) => Promise<{
|
|
235
|
+
use: import("better-call").Middleware<import("better-call").MiddlewareOptions, (inputContext: import("better-call").MiddlewareInputContext<import("better-call").MiddlewareOptions>) => Promise<{
|
|
236
236
|
session: {
|
|
237
237
|
session: Record<string, any> & {
|
|
238
238
|
id: string;
|
|
@@ -254,7 +254,7 @@ declare const deleteUser: import("better-call").StrictEndpoint<"/delete-user", {
|
|
|
254
254
|
image?: string | null | undefined;
|
|
255
255
|
};
|
|
256
256
|
};
|
|
257
|
-
}
|
|
257
|
+
}>>[];
|
|
258
258
|
body: z.ZodObject<{
|
|
259
259
|
callbackURL: z.ZodOptional<z.ZodString>;
|
|
260
260
|
password: z.ZodOptional<z.ZodString>;
|
|
@@ -323,7 +323,7 @@ declare const deleteUserCallback: import("better-call").StrictEndpoint<"/delete-
|
|
|
323
323
|
token: z.ZodString;
|
|
324
324
|
callbackURL: z.ZodOptional<z.ZodString>;
|
|
325
325
|
}, z.core.$strip>;
|
|
326
|
-
use: ((inputContext: import("better-call").MiddlewareInputContext<import("better-call").MiddlewareOptions>) => Promise<void
|
|
326
|
+
use: import("better-call").Middleware<import("better-call").MiddlewareOptions, (inputContext: import("better-call").MiddlewareInputContext<import("better-call").MiddlewareOptions>) => Promise<void>>[];
|
|
327
327
|
metadata: {
|
|
328
328
|
openapi: {
|
|
329
329
|
description: string;
|
|
@@ -363,7 +363,7 @@ declare const changeEmail: import("better-call").StrictEndpoint<"/change-email",
|
|
|
363
363
|
newEmail: z.ZodEmail;
|
|
364
364
|
callbackURL: z.ZodOptional<z.ZodString>;
|
|
365
365
|
}, z.core.$strip>;
|
|
366
|
-
use: ((inputContext: import("better-call").MiddlewareInputContext<import("better-call").MiddlewareOptions>) => Promise<{
|
|
366
|
+
use: import("better-call").Middleware<import("better-call").MiddlewareOptions, (inputContext: import("better-call").MiddlewareInputContext<import("better-call").MiddlewareOptions>) => Promise<{
|
|
367
367
|
session: {
|
|
368
368
|
session: Record<string, any> & {
|
|
369
369
|
id: string;
|
|
@@ -385,7 +385,7 @@ declare const changeEmail: import("better-call").StrictEndpoint<"/change-email",
|
|
|
385
385
|
image?: string | null | undefined;
|
|
386
386
|
};
|
|
387
387
|
};
|
|
388
|
-
}
|
|
388
|
+
}>>[];
|
|
389
389
|
metadata: {
|
|
390
390
|
openapi: {
|
|
391
391
|
operationId: string;
|
|
@@ -24,7 +24,7 @@ function isSessionAtomEqual(a, b) {
|
|
|
24
24
|
}
|
|
25
25
|
function getSessionAtom($fetch, options) {
|
|
26
26
|
const $signal = atom(false);
|
|
27
|
-
let
|
|
27
|
+
let activeRequest;
|
|
28
28
|
const refetch = (queryParams) => fetchSession(queryParams);
|
|
29
29
|
const session = atom({
|
|
30
30
|
data: null,
|
|
@@ -34,23 +34,8 @@ function getSessionAtom($fetch, options) {
|
|
|
34
34
|
refetch
|
|
35
35
|
});
|
|
36
36
|
withEquality(session, isSessionAtomEqual);
|
|
37
|
-
const
|
|
38
|
-
|
|
39
|
-
const current = session.get();
|
|
40
|
-
abortController = void 0;
|
|
41
|
-
if (!current.isPending && !current.isRefetching) return;
|
|
42
|
-
session.set({
|
|
43
|
-
...current,
|
|
44
|
-
isPending: false,
|
|
45
|
-
isRefetching: false,
|
|
46
|
-
refetch
|
|
47
|
-
});
|
|
48
|
-
};
|
|
49
|
-
const fetchSession = async (queryParams) => {
|
|
50
|
-
abortController?.abort();
|
|
51
|
-
const controller = new AbortController();
|
|
52
|
-
abortController = controller;
|
|
53
|
-
const current = session.get();
|
|
37
|
+
const executeSessionFetch = async (signal, queryParams) => {
|
|
38
|
+
const current = session.value;
|
|
54
39
|
session.set({
|
|
55
40
|
...current,
|
|
56
41
|
isPending: current.data === null,
|
|
@@ -58,35 +43,27 @@ function getSessionAtom($fetch, options) {
|
|
|
58
43
|
error: null,
|
|
59
44
|
refetch
|
|
60
45
|
});
|
|
46
|
+
if (signal.aborted) return;
|
|
61
47
|
try {
|
|
62
48
|
const res = await $fetch("/get-session", {
|
|
63
49
|
method: "GET",
|
|
64
50
|
query: queryParams?.query,
|
|
65
|
-
signal
|
|
51
|
+
signal
|
|
66
52
|
});
|
|
67
|
-
if (
|
|
68
|
-
settleAbortedFetch(controller);
|
|
69
|
-
return;
|
|
70
|
-
}
|
|
53
|
+
if (signal.aborted) return;
|
|
71
54
|
let { data, error } = normalizeSessionResponse(res);
|
|
72
55
|
if (data?.needsRefresh) try {
|
|
73
56
|
const refreshRes = await $fetch("/get-session", {
|
|
74
57
|
method: "POST",
|
|
75
|
-
signal
|
|
58
|
+
signal
|
|
76
59
|
});
|
|
77
|
-
if (
|
|
78
|
-
settleAbortedFetch(controller);
|
|
79
|
-
return;
|
|
80
|
-
}
|
|
60
|
+
if (signal.aborted) return;
|
|
81
61
|
({data, error} = normalizeSessionResponse(refreshRes));
|
|
82
62
|
} catch {
|
|
83
|
-
if (
|
|
84
|
-
settleAbortedFetch(controller);
|
|
85
|
-
return;
|
|
86
|
-
}
|
|
63
|
+
if (signal.aborted) return;
|
|
87
64
|
}
|
|
88
65
|
if (error) {
|
|
89
|
-
const latest = session.
|
|
66
|
+
const latest = session.value;
|
|
90
67
|
const isUnauthorized = error?.status === 401;
|
|
91
68
|
session.set({
|
|
92
69
|
data: isUnauthorized ? null : latest.data,
|
|
@@ -98,7 +75,7 @@ function getSessionAtom($fetch, options) {
|
|
|
98
75
|
return;
|
|
99
76
|
}
|
|
100
77
|
const sessionData = normalizeSessionData(data);
|
|
101
|
-
const current = session.
|
|
78
|
+
const current = session.value;
|
|
102
79
|
const stableData = current.data != null && sessionData != null && isJsonEqual(current.data, sessionData) ? current.data : sessionData;
|
|
103
80
|
session.set({
|
|
104
81
|
data: stableData,
|
|
@@ -108,11 +85,8 @@ function getSessionAtom($fetch, options) {
|
|
|
108
85
|
refetch
|
|
109
86
|
});
|
|
110
87
|
} catch (fetchError) {
|
|
111
|
-
if (
|
|
112
|
-
|
|
113
|
-
return;
|
|
114
|
-
}
|
|
115
|
-
const latest = session.get();
|
|
88
|
+
if (signal.aborted) return;
|
|
89
|
+
const latest = session.value;
|
|
116
90
|
session.set({
|
|
117
91
|
data: latest.data,
|
|
118
92
|
error: fetchError,
|
|
@@ -122,15 +96,33 @@ function getSessionAtom($fetch, options) {
|
|
|
122
96
|
});
|
|
123
97
|
}
|
|
124
98
|
};
|
|
99
|
+
const fetchSession = (queryParams) => {
|
|
100
|
+
activeRequest?.cancel();
|
|
101
|
+
const controller = new AbortController();
|
|
102
|
+
const request = {
|
|
103
|
+
cancel: () => controller.abort(),
|
|
104
|
+
promise: Promise.resolve().then(() => {
|
|
105
|
+
if (controller.signal.aborted) return;
|
|
106
|
+
return executeSessionFetch(controller.signal, queryParams);
|
|
107
|
+
})
|
|
108
|
+
};
|
|
109
|
+
activeRequest = request;
|
|
110
|
+
const clearActiveRequest = () => {
|
|
111
|
+
if (activeRequest === request) activeRequest = void 0;
|
|
112
|
+
};
|
|
113
|
+
request.promise.then(clearActiveRequest, clearActiveRequest);
|
|
114
|
+
return request.promise;
|
|
115
|
+
};
|
|
116
|
+
const fetchSessionOnMount = () => activeRequest?.promise ?? fetchSession();
|
|
125
117
|
let broadcastSessionUpdate = () => {};
|
|
126
118
|
onMount(session, () => {
|
|
127
119
|
let timeoutId;
|
|
128
120
|
if (!isServer()) timeoutId = setTimeout(() => {
|
|
129
|
-
|
|
121
|
+
fetchSessionOnMount();
|
|
130
122
|
}, 0);
|
|
131
123
|
const refreshManager = createSessionRefreshManager({
|
|
132
124
|
fetchSession,
|
|
133
|
-
shouldPollSession: () => session.
|
|
125
|
+
shouldPollSession: () => session.value.data != null,
|
|
134
126
|
sessionSignal: $signal,
|
|
135
127
|
options
|
|
136
128
|
});
|
|
@@ -138,9 +130,6 @@ function getSessionAtom($fetch, options) {
|
|
|
138
130
|
broadcastSessionUpdate = refreshManager.broadcastSessionUpdate;
|
|
139
131
|
return () => {
|
|
140
132
|
if (timeoutId) clearTimeout(timeoutId);
|
|
141
|
-
const controller = abortController;
|
|
142
|
-
controller?.abort();
|
|
143
|
-
if (controller) settleAbortedFetch(controller);
|
|
144
133
|
refreshManager.cleanup();
|
|
145
134
|
};
|
|
146
135
|
});
|
|
@@ -14,11 +14,11 @@ declare const nextCookies: () => {
|
|
|
14
14
|
hooks: {
|
|
15
15
|
before: {
|
|
16
16
|
matcher(ctx: import("@better-auth/core").HookEndpointContext): boolean;
|
|
17
|
-
handler: (inputContext: import("better-call").MiddlewareInputContext<import("better-call").MiddlewareOptions>) => Promise<void
|
|
17
|
+
handler: import("better-call").Middleware<import("better-call").MiddlewareOptions, (inputContext: import("better-call").MiddlewareInputContext<import("better-call").MiddlewareOptions>) => Promise<void>>;
|
|
18
18
|
}[];
|
|
19
19
|
after: {
|
|
20
20
|
matcher(ctx: import("@better-auth/core").HookEndpointContext): true;
|
|
21
|
-
handler: (inputContext: import("better-call").MiddlewareInputContext<import("better-call").MiddlewareOptions>) => Promise<void
|
|
21
|
+
handler: import("better-call").Middleware<import("better-call").MiddlewareOptions, (inputContext: import("better-call").MiddlewareInputContext<import("better-call").MiddlewareOptions>) => Promise<void>>;
|
|
22
22
|
}[];
|
|
23
23
|
};
|
|
24
24
|
};
|
|
@@ -23,7 +23,7 @@ declare const sveltekitCookies: (getRequestEvent: () => RequestEvent<any, any>)
|
|
|
23
23
|
hooks: {
|
|
24
24
|
after: {
|
|
25
25
|
matcher(): true;
|
|
26
|
-
handler: (inputContext: import("better-call").MiddlewareInputContext<import("better-call").MiddlewareOptions>) => Promise<void
|
|
26
|
+
handler: import("better-call").Middleware<import("better-call").MiddlewareOptions, (inputContext: import("better-call").MiddlewareInputContext<import("better-call").MiddlewareOptions>) => Promise<void>>;
|
|
27
27
|
}[];
|
|
28
28
|
};
|
|
29
29
|
};
|
|
@@ -22,7 +22,7 @@ declare const tanstackStartCookies: () => {
|
|
|
22
22
|
hooks: {
|
|
23
23
|
after: {
|
|
24
24
|
matcher(ctx: import("@better-auth/core").HookEndpointContext): true;
|
|
25
|
-
handler: (inputContext: import("better-call").MiddlewareInputContext<import("better-call").MiddlewareOptions>) => Promise<void
|
|
25
|
+
handler: import("better-call").Middleware<import("better-call").MiddlewareOptions, (inputContext: import("better-call").MiddlewareInputContext<import("better-call").MiddlewareOptions>) => Promise<void>>;
|
|
26
26
|
}[];
|
|
27
27
|
};
|
|
28
28
|
};
|
|
@@ -22,7 +22,7 @@ declare const tanstackStartCookies: () => {
|
|
|
22
22
|
hooks: {
|
|
23
23
|
after: {
|
|
24
24
|
matcher(ctx: import("@better-auth/core").HookEndpointContext): true;
|
|
25
|
-
handler: (inputContext: import("better-call").MiddlewareInputContext<import("better-call").MiddlewareOptions>) => Promise<void
|
|
25
|
+
handler: import("better-call").Middleware<import("better-call").MiddlewareOptions, (inputContext: import("better-call").MiddlewareInputContext<import("better-call").MiddlewareOptions>) => Promise<void>>;
|
|
26
26
|
}[];
|
|
27
27
|
};
|
|
28
28
|
};
|
package/dist/package.mjs
CHANGED