better-auth 0.2.11 → 0.3.1
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/drizzle.d.ts +1 -1
- package/dist/adapters/mongodb.d.ts +1 -1
- package/dist/adapters/prisma.d.ts +1 -1
- package/dist/api.d.ts +1 -1
- package/dist/api.js +58 -73
- package/dist/client/plugins.d.ts +12 -4
- package/dist/client/plugins.js +12 -0
- package/dist/client.d.ts +1 -1
- package/dist/{index-CUD_IG9Z.d.ts → index-B-Rb8u6d.d.ts} +135 -2
- package/dist/{index-PjYlcsPD.d.ts → index-BRcc7HbO.d.ts} +7 -7
- package/dist/index.d.ts +1 -1
- package/dist/index.js +58 -73
- package/dist/next-js.d.ts +1 -1
- package/dist/node.d.ts +1 -1
- package/dist/plugins.d.ts +6 -9
- package/dist/plugins.js +199 -126
- package/dist/react.d.ts +1 -1
- package/dist/solid-start.d.ts +1 -1
- package/dist/solid.d.ts +1 -1
- package/dist/svelte-kit.d.ts +1 -1
- package/dist/svelte.d.ts +1 -1
- package/dist/types.d.ts +2 -2
- package/dist/vue.d.ts +1 -1
- package/package.json +1 -1
package/dist/api.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export { f as AuthEndpoint, g as AuthMiddleware, n as callbackOAuth, L as changePassword, e as createAuthEndpoint, d as createAuthMiddleware, D as createEmailVerificationToken, V as csrfMiddleware, N as deleteUser, Q as error, y as forgetPassword, z as forgetPasswordCallback, O as getCSRFToken, l as getEndpoints, p as getSession, q as getSessionFromCtx, u as listSessions, T as ok, o as optionsMiddleware, C as resetPassword, v as revokeSession, w as revokeSessions, r as router, E as sendVerificationEmail, t as sessionMiddleware, M as setPassword, m as signInEmail, s as signInOAuth, x as signOut, U as signUpEmail, K as updateUser, J as verifyEmail } from './index-BRcc7HbO.js';
|
|
2
2
|
import 'zod';
|
|
3
3
|
import './helper-DPDj8Nix.js';
|
|
4
4
|
import 'better-call';
|
package/dist/api.js
CHANGED
|
@@ -773,17 +773,6 @@ function getIp(req) {
|
|
|
773
773
|
}
|
|
774
774
|
|
|
775
775
|
// src/api/routes/session.ts
|
|
776
|
-
function getRequestUniqueKey(ctx, token) {
|
|
777
|
-
if (!ctx.request) {
|
|
778
|
-
return "";
|
|
779
|
-
}
|
|
780
|
-
const { method, url, headers } = ctx.request;
|
|
781
|
-
const userAgent = ctx.request.headers.get("User-Agent") || "";
|
|
782
|
-
const ip = getIp(ctx.request) || "";
|
|
783
|
-
const headerString = JSON.stringify(headers);
|
|
784
|
-
const uniqueString = `${method}:${url}:${headerString}:${userAgent}:${ip}:${token}`;
|
|
785
|
-
return uniqueString;
|
|
786
|
-
}
|
|
787
776
|
var getSession = () => createAuthEndpoint(
|
|
788
777
|
"/session",
|
|
789
778
|
{
|
|
@@ -801,7 +790,6 @@ var getSession = () => createAuthEndpoint(
|
|
|
801
790
|
status: 401
|
|
802
791
|
});
|
|
803
792
|
}
|
|
804
|
-
const key = getRequestUniqueKey(ctx, sessionCookieToken);
|
|
805
793
|
const session = await ctx.context.internalAdapter.findSession(sessionCookieToken);
|
|
806
794
|
if (!session || session.session.expiresAt < /* @__PURE__ */ new Date()) {
|
|
807
795
|
deleteSessionCookie(ctx);
|
|
@@ -1167,10 +1155,66 @@ var verificationSchema = z5.object({
|
|
|
1167
1155
|
identifier: z5.string()
|
|
1168
1156
|
});
|
|
1169
1157
|
|
|
1158
|
+
// src/crypto/random.ts
|
|
1159
|
+
function byteToBinary(byte) {
|
|
1160
|
+
return byte.toString(2).padStart(8, "0");
|
|
1161
|
+
}
|
|
1162
|
+
function bytesToBinary(bytes) {
|
|
1163
|
+
return [...bytes].map((val) => byteToBinary(val)).join("");
|
|
1164
|
+
}
|
|
1165
|
+
function bytesToInteger(bytes) {
|
|
1166
|
+
return parseInt(bytesToBinary(bytes), 2);
|
|
1167
|
+
}
|
|
1168
|
+
function generateRandomInteger(max) {
|
|
1169
|
+
if (max < 0 || !Number.isInteger(max)) {
|
|
1170
|
+
throw new Error(
|
|
1171
|
+
"Argument 'max' must be an integer greater than or equal to 0"
|
|
1172
|
+
);
|
|
1173
|
+
}
|
|
1174
|
+
const bitLength = (max - 1).toString(2).length;
|
|
1175
|
+
const shift = bitLength % 8;
|
|
1176
|
+
const bytes = new Uint8Array(Math.ceil(bitLength / 8));
|
|
1177
|
+
crypto.getRandomValues(bytes);
|
|
1178
|
+
if (shift !== 0) {
|
|
1179
|
+
bytes[0] &= (1 << shift) - 1;
|
|
1180
|
+
}
|
|
1181
|
+
let result = bytesToInteger(bytes);
|
|
1182
|
+
while (result >= max) {
|
|
1183
|
+
crypto.getRandomValues(bytes);
|
|
1184
|
+
if (shift !== 0) {
|
|
1185
|
+
bytes[0] &= (1 << shift) - 1;
|
|
1186
|
+
}
|
|
1187
|
+
result = bytesToInteger(bytes);
|
|
1188
|
+
}
|
|
1189
|
+
return result;
|
|
1190
|
+
}
|
|
1191
|
+
function generateRandomString(length, alphabet2) {
|
|
1192
|
+
let result = "";
|
|
1193
|
+
for (let i = 0; i < length; i++) {
|
|
1194
|
+
result += alphabet2[generateRandomInteger(alphabet2.length)];
|
|
1195
|
+
}
|
|
1196
|
+
return result;
|
|
1197
|
+
}
|
|
1198
|
+
function alphabet(...patterns) {
|
|
1199
|
+
const patternSet = new Set(patterns);
|
|
1200
|
+
let result = "";
|
|
1201
|
+
for (const pattern of patternSet) {
|
|
1202
|
+
if (pattern === "a-z") {
|
|
1203
|
+
result += "abcdefghijklmnopqrstuvwxyz";
|
|
1204
|
+
} else if (pattern === "A-Z") {
|
|
1205
|
+
result += "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
|
|
1206
|
+
} else if (pattern === "0-9") {
|
|
1207
|
+
result += "0123456789";
|
|
1208
|
+
} else {
|
|
1209
|
+
result += pattern;
|
|
1210
|
+
}
|
|
1211
|
+
}
|
|
1212
|
+
return result;
|
|
1213
|
+
}
|
|
1214
|
+
|
|
1170
1215
|
// src/utils/id.ts
|
|
1171
|
-
import { nanoid } from "nanoid";
|
|
1172
1216
|
var generateId = (size) => {
|
|
1173
|
-
return
|
|
1217
|
+
return generateRandomString(size || 21, alphabet("a-z", "0-9", "A-Z"));
|
|
1174
1218
|
};
|
|
1175
1219
|
|
|
1176
1220
|
// src/utils/hide-metadata.ts
|
|
@@ -1736,65 +1780,6 @@ var verifyEmail = createAuthEndpoint(
|
|
|
1736
1780
|
|
|
1737
1781
|
// src/api/routes/update-user.ts
|
|
1738
1782
|
import { z as z10 } from "zod";
|
|
1739
|
-
|
|
1740
|
-
// src/crypto/random.ts
|
|
1741
|
-
function byteToBinary(byte) {
|
|
1742
|
-
return byte.toString(2).padStart(8, "0");
|
|
1743
|
-
}
|
|
1744
|
-
function bytesToBinary(bytes) {
|
|
1745
|
-
return [...bytes].map((val) => byteToBinary(val)).join("");
|
|
1746
|
-
}
|
|
1747
|
-
function bytesToInteger(bytes) {
|
|
1748
|
-
return parseInt(bytesToBinary(bytes), 2);
|
|
1749
|
-
}
|
|
1750
|
-
function generateRandomInteger(max) {
|
|
1751
|
-
if (max < 0 || !Number.isInteger(max)) {
|
|
1752
|
-
throw new Error(
|
|
1753
|
-
"Argument 'max' must be an integer greater than or equal to 0"
|
|
1754
|
-
);
|
|
1755
|
-
}
|
|
1756
|
-
const bitLength = (max - 1).toString(2).length;
|
|
1757
|
-
const shift = bitLength % 8;
|
|
1758
|
-
const bytes = new Uint8Array(Math.ceil(bitLength / 8));
|
|
1759
|
-
crypto.getRandomValues(bytes);
|
|
1760
|
-
if (shift !== 0) {
|
|
1761
|
-
bytes[0] &= (1 << shift) - 1;
|
|
1762
|
-
}
|
|
1763
|
-
let result = bytesToInteger(bytes);
|
|
1764
|
-
while (result >= max) {
|
|
1765
|
-
crypto.getRandomValues(bytes);
|
|
1766
|
-
if (shift !== 0) {
|
|
1767
|
-
bytes[0] &= (1 << shift) - 1;
|
|
1768
|
-
}
|
|
1769
|
-
result = bytesToInteger(bytes);
|
|
1770
|
-
}
|
|
1771
|
-
return result;
|
|
1772
|
-
}
|
|
1773
|
-
function generateRandomString(length, alphabet2) {
|
|
1774
|
-
let result = "";
|
|
1775
|
-
for (let i = 0; i < length; i++) {
|
|
1776
|
-
result += alphabet2[generateRandomInteger(alphabet2.length)];
|
|
1777
|
-
}
|
|
1778
|
-
return result;
|
|
1779
|
-
}
|
|
1780
|
-
function alphabet(...patterns) {
|
|
1781
|
-
const patternSet = new Set(patterns);
|
|
1782
|
-
let result = "";
|
|
1783
|
-
for (const pattern of patternSet) {
|
|
1784
|
-
if (pattern === "a-z") {
|
|
1785
|
-
result += "abcdefghijklmnopqrstuvwxyz";
|
|
1786
|
-
} else if (pattern === "A-Z") {
|
|
1787
|
-
result += "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
|
|
1788
|
-
} else if (pattern === "0-9") {
|
|
1789
|
-
result += "0123456789";
|
|
1790
|
-
} else {
|
|
1791
|
-
result += pattern;
|
|
1792
|
-
}
|
|
1793
|
-
}
|
|
1794
|
-
return result;
|
|
1795
|
-
}
|
|
1796
|
-
|
|
1797
|
-
// src/api/routes/update-user.ts
|
|
1798
1783
|
var updateUser = createAuthEndpoint(
|
|
1799
1784
|
"/user/update",
|
|
1800
1785
|
{
|
package/dist/client/plugins.d.ts
CHANGED
|
@@ -2,14 +2,14 @@ import * as nanostores from 'nanostores';
|
|
|
2
2
|
import { A as AccessControl, S as StatementsPrimitive, R as Role } from '../statement-CfnyN34h.js';
|
|
3
3
|
import * as _better_fetch_fetch from '@better-fetch/fetch';
|
|
4
4
|
import { BetterFetchOption } from '@better-fetch/fetch';
|
|
5
|
-
import { o as organization,
|
|
6
|
-
export { g as getPasskeyActions, c as passkeyClient, a as twoFactorClient } from '../index-
|
|
5
|
+
import { o as organization, f as Organization, M as Member, I as Invitation, u as username, m as magicLink, d as phoneNumber, e as anonymous } from '../index-B-Rb8u6d.js';
|
|
6
|
+
export { g as getPasskeyActions, c as passkeyClient, a as twoFactorClient } from '../index-B-Rb8u6d.js';
|
|
7
7
|
import { P as Prettify } from '../helper-DPDj8Nix.js';
|
|
8
8
|
import '../index-JM-i6hLs.js';
|
|
9
9
|
import 'arctic';
|
|
10
10
|
import 'zod';
|
|
11
11
|
import 'better-call';
|
|
12
|
-
import '../index-
|
|
12
|
+
import '../index-BRcc7HbO.js';
|
|
13
13
|
import 'kysely';
|
|
14
14
|
import 'better-sqlite3';
|
|
15
15
|
import 'mysql2';
|
|
@@ -153,4 +153,12 @@ declare const phoneNumberClient: () => {
|
|
|
153
153
|
}[];
|
|
154
154
|
};
|
|
155
155
|
|
|
156
|
-
|
|
156
|
+
declare const anonymousClient: () => {
|
|
157
|
+
id: "anonymous";
|
|
158
|
+
$InferServerPlugin: ReturnType<typeof anonymous>;
|
|
159
|
+
pathMethods: {
|
|
160
|
+
"/sign-in/anonymous": "POST";
|
|
161
|
+
};
|
|
162
|
+
};
|
|
163
|
+
|
|
164
|
+
export { anonymousClient, magicLinkClient, organizationClient, phoneNumberClient, usernameClient };
|
package/dist/client/plugins.js
CHANGED
|
@@ -493,7 +493,19 @@ var phoneNumberClient = () => {
|
|
|
493
493
|
]
|
|
494
494
|
};
|
|
495
495
|
};
|
|
496
|
+
|
|
497
|
+
// src/plugins/anonymous/client.ts
|
|
498
|
+
var anonymousClient = () => {
|
|
499
|
+
return {
|
|
500
|
+
id: "anonymous",
|
|
501
|
+
$InferServerPlugin: {},
|
|
502
|
+
pathMethods: {
|
|
503
|
+
"/sign-in/anonymous": "POST"
|
|
504
|
+
}
|
|
505
|
+
};
|
|
506
|
+
};
|
|
496
507
|
export {
|
|
508
|
+
anonymousClient,
|
|
497
509
|
getPasskeyActions,
|
|
498
510
|
magicLinkClient,
|
|
499
511
|
organizationClient,
|
package/dist/client.d.ts
CHANGED
|
@@ -6,7 +6,7 @@ import { BetterFetch, BetterFetchError, BetterFetchOption } from '@better-fetch/
|
|
|
6
6
|
import { U as UnionToIntersection, P as Prettify, S as StripEmptyObjects } from './helper-DPDj8Nix.js';
|
|
7
7
|
import { ClientOptions, InferClientAPI, InferActions, InferAdditionalFromClient, InferSessionFromClient, InferUserFromClient, BetterAuthClientPlugin, IsSignal } from './types.js';
|
|
8
8
|
export { AtomListener, InferPluginsFromClient } from './types.js';
|
|
9
|
-
import './index-
|
|
9
|
+
import './index-BRcc7HbO.js';
|
|
10
10
|
import 'kysely';
|
|
11
11
|
import './index-JM-i6hLs.js';
|
|
12
12
|
import 'arctic';
|
|
@@ -5,7 +5,7 @@ import { P as Prettify } from './helper-DPDj8Nix.js';
|
|
|
5
5
|
import { A as AccessControl, R as Role, S as StatementsPrimitive, g as defaultRoles } from './statement-CfnyN34h.js';
|
|
6
6
|
import * as _better_fetch_fetch from '@better-fetch/fetch';
|
|
7
7
|
import { BetterFetch, BetterFetchOption } from '@better-fetch/fetch';
|
|
8
|
-
import { H as HookEndpointContext } from './index-
|
|
8
|
+
import { H as HookEndpointContext } from './index-BRcc7HbO.js';
|
|
9
9
|
import * as nanostores from 'nanostores';
|
|
10
10
|
import { atom } from 'nanostores';
|
|
11
11
|
import * as _simplewebauthn_types from '@simplewebauthn/types';
|
|
@@ -4629,4 +4629,137 @@ declare const phoneNumber: (options?: {
|
|
|
4629
4629
|
};
|
|
4630
4630
|
};
|
|
4631
4631
|
|
|
4632
|
-
|
|
4632
|
+
declare const anonymous: () => {
|
|
4633
|
+
id: "anonymous";
|
|
4634
|
+
endpoints: {
|
|
4635
|
+
signInAnonymous: {
|
|
4636
|
+
(ctx_0?: better_call.Context<"/sign-in/anonymous", {
|
|
4637
|
+
method: "POST";
|
|
4638
|
+
}> | undefined): Promise<{
|
|
4639
|
+
user: {
|
|
4640
|
+
id: string;
|
|
4641
|
+
email: string;
|
|
4642
|
+
emailVerified: boolean;
|
|
4643
|
+
name: string;
|
|
4644
|
+
createdAt: Date;
|
|
4645
|
+
updatedAt: Date;
|
|
4646
|
+
image?: string | undefined;
|
|
4647
|
+
} & Record<string, any>;
|
|
4648
|
+
session: {
|
|
4649
|
+
id: string;
|
|
4650
|
+
userId: string;
|
|
4651
|
+
expiresAt: Date;
|
|
4652
|
+
ipAddress?: string | undefined;
|
|
4653
|
+
userAgent?: string | undefined;
|
|
4654
|
+
};
|
|
4655
|
+
} | null>;
|
|
4656
|
+
path: "/sign-in/anonymous";
|
|
4657
|
+
options: {
|
|
4658
|
+
method: "POST";
|
|
4659
|
+
};
|
|
4660
|
+
method: better_call.Method | better_call.Method[];
|
|
4661
|
+
headers: Headers;
|
|
4662
|
+
};
|
|
4663
|
+
linkAnonymous: {
|
|
4664
|
+
(ctx_0: better_call.Context<"/user/link-anonymous", {
|
|
4665
|
+
method: "POST";
|
|
4666
|
+
body: z.ZodObject<{
|
|
4667
|
+
email: z.ZodOptional<z.ZodString>;
|
|
4668
|
+
password: z.ZodString;
|
|
4669
|
+
}, "strip", z.ZodTypeAny, {
|
|
4670
|
+
password: string;
|
|
4671
|
+
email?: string | undefined;
|
|
4672
|
+
}, {
|
|
4673
|
+
password: string;
|
|
4674
|
+
email?: string | undefined;
|
|
4675
|
+
}>;
|
|
4676
|
+
use: better_call.Endpoint<better_call.Handler<string, better_call.EndpointOptions, {
|
|
4677
|
+
session: {
|
|
4678
|
+
session: {
|
|
4679
|
+
id: string;
|
|
4680
|
+
userId: string;
|
|
4681
|
+
expiresAt: Date;
|
|
4682
|
+
ipAddress?: string | undefined;
|
|
4683
|
+
userAgent?: string | undefined;
|
|
4684
|
+
};
|
|
4685
|
+
user: {
|
|
4686
|
+
id: string;
|
|
4687
|
+
email: string;
|
|
4688
|
+
emailVerified: boolean;
|
|
4689
|
+
name: string;
|
|
4690
|
+
createdAt: Date;
|
|
4691
|
+
updatedAt: Date;
|
|
4692
|
+
image?: string | undefined;
|
|
4693
|
+
};
|
|
4694
|
+
};
|
|
4695
|
+
}>, better_call.EndpointOptions>[];
|
|
4696
|
+
}>): Promise<{
|
|
4697
|
+
session: {
|
|
4698
|
+
id: string;
|
|
4699
|
+
userId: string;
|
|
4700
|
+
expiresAt: Date;
|
|
4701
|
+
ipAddress?: string | undefined;
|
|
4702
|
+
userAgent?: string | undefined;
|
|
4703
|
+
};
|
|
4704
|
+
user: {
|
|
4705
|
+
id: string;
|
|
4706
|
+
email: string;
|
|
4707
|
+
emailVerified: boolean;
|
|
4708
|
+
name: string;
|
|
4709
|
+
createdAt: Date;
|
|
4710
|
+
updatedAt: Date;
|
|
4711
|
+
image?: string | undefined;
|
|
4712
|
+
};
|
|
4713
|
+
} | null>;
|
|
4714
|
+
path: "/user/link-anonymous";
|
|
4715
|
+
options: {
|
|
4716
|
+
method: "POST";
|
|
4717
|
+
body: z.ZodObject<{
|
|
4718
|
+
email: z.ZodOptional<z.ZodString>;
|
|
4719
|
+
password: z.ZodString;
|
|
4720
|
+
}, "strip", z.ZodTypeAny, {
|
|
4721
|
+
password: string;
|
|
4722
|
+
email?: string | undefined;
|
|
4723
|
+
}, {
|
|
4724
|
+
password: string;
|
|
4725
|
+
email?: string | undefined;
|
|
4726
|
+
}>;
|
|
4727
|
+
use: better_call.Endpoint<better_call.Handler<string, better_call.EndpointOptions, {
|
|
4728
|
+
session: {
|
|
4729
|
+
session: {
|
|
4730
|
+
id: string;
|
|
4731
|
+
userId: string;
|
|
4732
|
+
expiresAt: Date;
|
|
4733
|
+
ipAddress?: string | undefined;
|
|
4734
|
+
userAgent?: string | undefined;
|
|
4735
|
+
};
|
|
4736
|
+
user: {
|
|
4737
|
+
id: string;
|
|
4738
|
+
email: string;
|
|
4739
|
+
emailVerified: boolean;
|
|
4740
|
+
name: string;
|
|
4741
|
+
createdAt: Date;
|
|
4742
|
+
updatedAt: Date;
|
|
4743
|
+
image?: string | undefined;
|
|
4744
|
+
};
|
|
4745
|
+
};
|
|
4746
|
+
}>, better_call.EndpointOptions>[];
|
|
4747
|
+
};
|
|
4748
|
+
method: better_call.Method | better_call.Method[];
|
|
4749
|
+
headers: Headers;
|
|
4750
|
+
};
|
|
4751
|
+
};
|
|
4752
|
+
schema: {
|
|
4753
|
+
user: {
|
|
4754
|
+
fields: {
|
|
4755
|
+
isAnonymous: {
|
|
4756
|
+
type: "boolean";
|
|
4757
|
+
defaultValue: true;
|
|
4758
|
+
required: false;
|
|
4759
|
+
};
|
|
4760
|
+
};
|
|
4761
|
+
};
|
|
4762
|
+
};
|
|
4763
|
+
};
|
|
4764
|
+
|
|
4765
|
+
export { type Invitation as I, type Member as M, type OrganizationOptions as O, type PasskeyOptions as P, twoFactorClient as a, type Passkey as b, passkeyClient as c, phoneNumber as d, anonymous as e, type Organization as f, getPasskeyActions as g, magicLink as m, organization as o, passkey as p, twoFactor as t, username as u };
|
|
@@ -100,7 +100,7 @@ declare const createInternalAdapter: (adapter: Adapter, ctx: {
|
|
|
100
100
|
password?: string | null | undefined;
|
|
101
101
|
} | null;
|
|
102
102
|
} | null>;
|
|
103
|
-
createUser: (user: User) => Promise<{
|
|
103
|
+
createUser: (user: User & Record<string, any>) => Promise<({
|
|
104
104
|
id: string;
|
|
105
105
|
email: string;
|
|
106
106
|
emailVerified: boolean;
|
|
@@ -108,7 +108,7 @@ declare const createInternalAdapter: (adapter: Adapter, ctx: {
|
|
|
108
108
|
createdAt: Date;
|
|
109
109
|
updatedAt: Date;
|
|
110
110
|
image?: string | undefined;
|
|
111
|
-
} | null>;
|
|
111
|
+
} & Record<string, any>) | null>;
|
|
112
112
|
deleteUser: (userId: string) => Promise<void>;
|
|
113
113
|
createSession: (userId: string, request?: Request | Headers, dontRememberMe?: boolean) => Promise<{
|
|
114
114
|
id: string;
|
|
@@ -2329,7 +2329,7 @@ declare const signUpEmail: {
|
|
|
2329
2329
|
createdAt: Date;
|
|
2330
2330
|
updatedAt: Date;
|
|
2331
2331
|
image?: string | undefined;
|
|
2332
|
-
}
|
|
2332
|
+
} & Record<string, any>;
|
|
2333
2333
|
session: {
|
|
2334
2334
|
id: string;
|
|
2335
2335
|
userId: string;
|
|
@@ -2669,7 +2669,7 @@ declare function getEndpoints<C extends AuthContext, Option extends BetterAuthOp
|
|
|
2669
2669
|
createdAt: Date;
|
|
2670
2670
|
updatedAt: Date;
|
|
2671
2671
|
image?: string | undefined;
|
|
2672
|
-
}
|
|
2672
|
+
} & Record<string, any>;
|
|
2673
2673
|
session: {
|
|
2674
2674
|
id: string;
|
|
2675
2675
|
userId: string;
|
|
@@ -3731,7 +3731,7 @@ declare const router: <C extends AuthContext, Option extends BetterAuthOptions>(
|
|
|
3731
3731
|
createdAt: Date;
|
|
3732
3732
|
updatedAt: Date;
|
|
3733
3733
|
image?: string | undefined;
|
|
3734
|
-
}
|
|
3734
|
+
} & Record<string, any>;
|
|
3735
3735
|
session: {
|
|
3736
3736
|
id: string;
|
|
3737
3737
|
userId: string;
|
|
@@ -4795,7 +4795,7 @@ declare const betterAuth: <O extends BetterAuthOptions>(options: O) => {
|
|
|
4795
4795
|
createdAt: Date;
|
|
4796
4796
|
updatedAt: Date;
|
|
4797
4797
|
image?: string | undefined;
|
|
4798
|
-
}
|
|
4798
|
+
} & Record<string, any>;
|
|
4799
4799
|
session: {
|
|
4800
4800
|
id: string;
|
|
4801
4801
|
userId: string;
|
|
@@ -5590,4 +5590,4 @@ type Auth = {
|
|
|
5590
5590
|
options: BetterAuthOptions;
|
|
5591
5591
|
};
|
|
5592
5592
|
|
|
5593
|
-
export { type Adapter as A, type BetterAuthOptions as B, resetPassword as C, createEmailVerificationToken as D, sendVerificationEmail as E, type FieldAttribute as F, type GenericEndpointContext as G, type HookEndpointContext as H, type InferFieldOutput as I, verifyEmail as J, updateUser as K, changePassword as L, setPassword as M, deleteUser as N, getCSRFToken as O, type PluginSchema as P, error as Q, type RateLimit as R, type SessionAdapter as S, ok as T, signUpEmail as U, csrfMiddleware as V, type Where as W, betterAuth as X, type Auth as a, type
|
|
5593
|
+
export { type Adapter as A, type BetterAuthOptions as B, resetPassword as C, createEmailVerificationToken as D, sendVerificationEmail as E, type FieldAttribute as F, type GenericEndpointContext as G, type HookEndpointContext as H, type InferFieldOutput as I, verifyEmail as J, updateUser as K, changePassword as L, setPassword as M, deleteUser as N, getCSRFToken as O, type PluginSchema as P, error as Q, type RateLimit as R, type SessionAdapter as S, ok as T, signUpEmail as U, csrfMiddleware as V, type Where as W, betterAuth as X, type Auth as a, type AuthContext as b, type BetterAuthPlugin as c, createAuthMiddleware as d, createAuthEndpoint as e, type AuthEndpoint as f, type AuthMiddleware as g, type InferUser as h, type InferSession as i, type InferPluginTypes as j, init as k, getEndpoints as l, signInEmail as m, callbackOAuth as n, optionsMiddleware as o, getSession as p, getSessionFromCtx as q, router as r, signInOAuth as s, sessionMiddleware as t, listSessions as u, revokeSession as v, revokeSessions as w, signOut as x, forgetPassword as y, forgetPasswordCallback as z };
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -863,17 +863,6 @@ function getIp(req) {
|
|
|
863
863
|
}
|
|
864
864
|
|
|
865
865
|
// src/api/routes/session.ts
|
|
866
|
-
function getRequestUniqueKey(ctx, token) {
|
|
867
|
-
if (!ctx.request) {
|
|
868
|
-
return "";
|
|
869
|
-
}
|
|
870
|
-
const { method, url, headers } = ctx.request;
|
|
871
|
-
const userAgent = ctx.request.headers.get("User-Agent") || "";
|
|
872
|
-
const ip = getIp(ctx.request) || "";
|
|
873
|
-
const headerString = JSON.stringify(headers);
|
|
874
|
-
const uniqueString = `${method}:${url}:${headerString}:${userAgent}:${ip}:${token}`;
|
|
875
|
-
return uniqueString;
|
|
876
|
-
}
|
|
877
866
|
var getSession = () => createAuthEndpoint(
|
|
878
867
|
"/session",
|
|
879
868
|
{
|
|
@@ -891,7 +880,6 @@ var getSession = () => createAuthEndpoint(
|
|
|
891
880
|
status: 401
|
|
892
881
|
});
|
|
893
882
|
}
|
|
894
|
-
const key = getRequestUniqueKey(ctx, sessionCookieToken);
|
|
895
883
|
const session = await ctx.context.internalAdapter.findSession(sessionCookieToken);
|
|
896
884
|
if (!session || session.session.expiresAt < /* @__PURE__ */ new Date()) {
|
|
897
885
|
deleteSessionCookie(ctx);
|
|
@@ -1257,10 +1245,66 @@ var verificationSchema = z5.object({
|
|
|
1257
1245
|
identifier: z5.string()
|
|
1258
1246
|
});
|
|
1259
1247
|
|
|
1248
|
+
// src/crypto/random.ts
|
|
1249
|
+
function byteToBinary(byte) {
|
|
1250
|
+
return byte.toString(2).padStart(8, "0");
|
|
1251
|
+
}
|
|
1252
|
+
function bytesToBinary(bytes) {
|
|
1253
|
+
return [...bytes].map((val) => byteToBinary(val)).join("");
|
|
1254
|
+
}
|
|
1255
|
+
function bytesToInteger(bytes) {
|
|
1256
|
+
return parseInt(bytesToBinary(bytes), 2);
|
|
1257
|
+
}
|
|
1258
|
+
function generateRandomInteger(max) {
|
|
1259
|
+
if (max < 0 || !Number.isInteger(max)) {
|
|
1260
|
+
throw new Error(
|
|
1261
|
+
"Argument 'max' must be an integer greater than or equal to 0"
|
|
1262
|
+
);
|
|
1263
|
+
}
|
|
1264
|
+
const bitLength = (max - 1).toString(2).length;
|
|
1265
|
+
const shift = bitLength % 8;
|
|
1266
|
+
const bytes = new Uint8Array(Math.ceil(bitLength / 8));
|
|
1267
|
+
crypto.getRandomValues(bytes);
|
|
1268
|
+
if (shift !== 0) {
|
|
1269
|
+
bytes[0] &= (1 << shift) - 1;
|
|
1270
|
+
}
|
|
1271
|
+
let result = bytesToInteger(bytes);
|
|
1272
|
+
while (result >= max) {
|
|
1273
|
+
crypto.getRandomValues(bytes);
|
|
1274
|
+
if (shift !== 0) {
|
|
1275
|
+
bytes[0] &= (1 << shift) - 1;
|
|
1276
|
+
}
|
|
1277
|
+
result = bytesToInteger(bytes);
|
|
1278
|
+
}
|
|
1279
|
+
return result;
|
|
1280
|
+
}
|
|
1281
|
+
function generateRandomString(length, alphabet2) {
|
|
1282
|
+
let result = "";
|
|
1283
|
+
for (let i = 0; i < length; i++) {
|
|
1284
|
+
result += alphabet2[generateRandomInteger(alphabet2.length)];
|
|
1285
|
+
}
|
|
1286
|
+
return result;
|
|
1287
|
+
}
|
|
1288
|
+
function alphabet(...patterns) {
|
|
1289
|
+
const patternSet = new Set(patterns);
|
|
1290
|
+
let result = "";
|
|
1291
|
+
for (const pattern of patternSet) {
|
|
1292
|
+
if (pattern === "a-z") {
|
|
1293
|
+
result += "abcdefghijklmnopqrstuvwxyz";
|
|
1294
|
+
} else if (pattern === "A-Z") {
|
|
1295
|
+
result += "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
|
|
1296
|
+
} else if (pattern === "0-9") {
|
|
1297
|
+
result += "0123456789";
|
|
1298
|
+
} else {
|
|
1299
|
+
result += pattern;
|
|
1300
|
+
}
|
|
1301
|
+
}
|
|
1302
|
+
return result;
|
|
1303
|
+
}
|
|
1304
|
+
|
|
1260
1305
|
// src/utils/id.ts
|
|
1261
|
-
import { nanoid } from "nanoid";
|
|
1262
1306
|
var generateId = (size) => {
|
|
1263
|
-
return
|
|
1307
|
+
return generateRandomString(size || 21, alphabet("a-z", "0-9", "A-Z"));
|
|
1264
1308
|
};
|
|
1265
1309
|
|
|
1266
1310
|
// src/utils/hide-metadata.ts
|
|
@@ -1826,65 +1870,6 @@ var verifyEmail = createAuthEndpoint(
|
|
|
1826
1870
|
|
|
1827
1871
|
// src/api/routes/update-user.ts
|
|
1828
1872
|
import { z as z10 } from "zod";
|
|
1829
|
-
|
|
1830
|
-
// src/crypto/random.ts
|
|
1831
|
-
function byteToBinary(byte) {
|
|
1832
|
-
return byte.toString(2).padStart(8, "0");
|
|
1833
|
-
}
|
|
1834
|
-
function bytesToBinary(bytes) {
|
|
1835
|
-
return [...bytes].map((val) => byteToBinary(val)).join("");
|
|
1836
|
-
}
|
|
1837
|
-
function bytesToInteger(bytes) {
|
|
1838
|
-
return parseInt(bytesToBinary(bytes), 2);
|
|
1839
|
-
}
|
|
1840
|
-
function generateRandomInteger(max) {
|
|
1841
|
-
if (max < 0 || !Number.isInteger(max)) {
|
|
1842
|
-
throw new Error(
|
|
1843
|
-
"Argument 'max' must be an integer greater than or equal to 0"
|
|
1844
|
-
);
|
|
1845
|
-
}
|
|
1846
|
-
const bitLength = (max - 1).toString(2).length;
|
|
1847
|
-
const shift = bitLength % 8;
|
|
1848
|
-
const bytes = new Uint8Array(Math.ceil(bitLength / 8));
|
|
1849
|
-
crypto.getRandomValues(bytes);
|
|
1850
|
-
if (shift !== 0) {
|
|
1851
|
-
bytes[0] &= (1 << shift) - 1;
|
|
1852
|
-
}
|
|
1853
|
-
let result = bytesToInteger(bytes);
|
|
1854
|
-
while (result >= max) {
|
|
1855
|
-
crypto.getRandomValues(bytes);
|
|
1856
|
-
if (shift !== 0) {
|
|
1857
|
-
bytes[0] &= (1 << shift) - 1;
|
|
1858
|
-
}
|
|
1859
|
-
result = bytesToInteger(bytes);
|
|
1860
|
-
}
|
|
1861
|
-
return result;
|
|
1862
|
-
}
|
|
1863
|
-
function generateRandomString(length, alphabet2) {
|
|
1864
|
-
let result = "";
|
|
1865
|
-
for (let i = 0; i < length; i++) {
|
|
1866
|
-
result += alphabet2[generateRandomInteger(alphabet2.length)];
|
|
1867
|
-
}
|
|
1868
|
-
return result;
|
|
1869
|
-
}
|
|
1870
|
-
function alphabet(...patterns) {
|
|
1871
|
-
const patternSet = new Set(patterns);
|
|
1872
|
-
let result = "";
|
|
1873
|
-
for (const pattern of patternSet) {
|
|
1874
|
-
if (pattern === "a-z") {
|
|
1875
|
-
result += "abcdefghijklmnopqrstuvwxyz";
|
|
1876
|
-
} else if (pattern === "A-Z") {
|
|
1877
|
-
result += "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
|
|
1878
|
-
} else if (pattern === "0-9") {
|
|
1879
|
-
result += "0123456789";
|
|
1880
|
-
} else {
|
|
1881
|
-
result += pattern;
|
|
1882
|
-
}
|
|
1883
|
-
}
|
|
1884
|
-
return result;
|
|
1885
|
-
}
|
|
1886
|
-
|
|
1887
|
-
// src/api/routes/update-user.ts
|
|
1888
1873
|
var updateUser = createAuthEndpoint(
|
|
1889
1874
|
"/user/update",
|
|
1890
1875
|
{
|
package/dist/next-js.d.ts
CHANGED
package/dist/node.d.ts
CHANGED
package/dist/plugins.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
export { O as OrganizationOptions, b as Passkey, P as PasskeyOptions, g as getPasskeyActions, m as magicLink, o as organization, p as passkey, c as passkeyClient, d as phoneNumber, t as twoFactor, a as twoFactorClient, u as username } from './index-
|
|
1
|
+
export { O as OrganizationOptions, b as Passkey, P as PasskeyOptions, e as anonymous, g as getPasskeyActions, m as magicLink, o as organization, p as passkey, c as passkeyClient, d as phoneNumber, t as twoFactor, a as twoFactorClient, u as username } from './index-B-Rb8u6d.js';
|
|
2
2
|
export { i as ac } from './index-DfAHOgpj.js';
|
|
3
|
-
import {
|
|
4
|
-
export {
|
|
3
|
+
import { b as AuthContext } from './index-BRcc7HbO.js';
|
|
4
|
+
export { f as AuthEndpoint, g as AuthMiddleware, c as BetterAuthPlugin, P as PluginSchema, e as createAuthEndpoint, d as createAuthMiddleware, o as optionsMiddleware } from './index-BRcc7HbO.js';
|
|
5
5
|
import './index-JM-i6hLs.js';
|
|
6
6
|
import 'arctic';
|
|
7
7
|
import 'zod';
|
|
@@ -20,12 +20,9 @@ import 'mysql2';
|
|
|
20
20
|
*/
|
|
21
21
|
declare const bearer: () => {
|
|
22
22
|
id: "bearer";
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
handler: (ctx: HookEndpointContext) => Promise<void>;
|
|
27
|
-
}[];
|
|
28
|
-
};
|
|
23
|
+
onRequest(request: Request, ctx: AuthContext): Promise<{
|
|
24
|
+
request: Request;
|
|
25
|
+
} | undefined>;
|
|
29
26
|
};
|
|
30
27
|
|
|
31
28
|
declare const HIDE_METADATA: {
|
package/dist/plugins.js
CHANGED
|
@@ -682,46 +682,6 @@ function deleteSessionCookie(ctx) {
|
|
|
682
682
|
|
|
683
683
|
// src/api/routes/session.ts
|
|
684
684
|
import { z as z2 } from "zod";
|
|
685
|
-
|
|
686
|
-
// src/utils/get-request-ip.ts
|
|
687
|
-
function getIp(req) {
|
|
688
|
-
const testIP = "127.0.0.1";
|
|
689
|
-
if (process.env.NODE_ENV === "test") {
|
|
690
|
-
return testIP;
|
|
691
|
-
}
|
|
692
|
-
const headers = [
|
|
693
|
-
"x-client-ip",
|
|
694
|
-
"x-forwarded-for",
|
|
695
|
-
"cf-connecting-ip",
|
|
696
|
-
"fastly-client-ip",
|
|
697
|
-
"x-real-ip",
|
|
698
|
-
"x-cluster-client-ip",
|
|
699
|
-
"x-forwarded",
|
|
700
|
-
"forwarded-for",
|
|
701
|
-
"forwarded"
|
|
702
|
-
];
|
|
703
|
-
for (const header of headers) {
|
|
704
|
-
const value = req.headers.get(header);
|
|
705
|
-
if (typeof value === "string") {
|
|
706
|
-
const ip = value.split(",")[0].trim();
|
|
707
|
-
if (ip) return ip;
|
|
708
|
-
}
|
|
709
|
-
}
|
|
710
|
-
return null;
|
|
711
|
-
}
|
|
712
|
-
|
|
713
|
-
// src/api/routes/session.ts
|
|
714
|
-
function getRequestUniqueKey(ctx, token) {
|
|
715
|
-
if (!ctx.request) {
|
|
716
|
-
return "";
|
|
717
|
-
}
|
|
718
|
-
const { method, url, headers } = ctx.request;
|
|
719
|
-
const userAgent = ctx.request.headers.get("User-Agent") || "";
|
|
720
|
-
const ip = getIp(ctx.request) || "";
|
|
721
|
-
const headerString = JSON.stringify(headers);
|
|
722
|
-
const uniqueString = `${method}:${url}:${headerString}:${userAgent}:${ip}:${token}`;
|
|
723
|
-
return uniqueString;
|
|
724
|
-
}
|
|
725
685
|
var getSession = () => createAuthEndpoint(
|
|
726
686
|
"/session",
|
|
727
687
|
{
|
|
@@ -739,7 +699,6 @@ var getSession = () => createAuthEndpoint(
|
|
|
739
699
|
status: 401
|
|
740
700
|
});
|
|
741
701
|
}
|
|
742
|
-
const key = getRequestUniqueKey(ctx, sessionCookieToken);
|
|
743
702
|
const session = await ctx.context.internalAdapter.findSession(sessionCookieToken);
|
|
744
703
|
if (!session || session.session.expiresAt < /* @__PURE__ */ new Date()) {
|
|
745
704
|
deleteSessionCookie(ctx);
|
|
@@ -1080,10 +1039,66 @@ var verificationSchema = z4.object({
|
|
|
1080
1039
|
identifier: z4.string()
|
|
1081
1040
|
});
|
|
1082
1041
|
|
|
1042
|
+
// src/crypto/random.ts
|
|
1043
|
+
function byteToBinary(byte) {
|
|
1044
|
+
return byte.toString(2).padStart(8, "0");
|
|
1045
|
+
}
|
|
1046
|
+
function bytesToBinary(bytes) {
|
|
1047
|
+
return [...bytes].map((val) => byteToBinary(val)).join("");
|
|
1048
|
+
}
|
|
1049
|
+
function bytesToInteger(bytes) {
|
|
1050
|
+
return parseInt(bytesToBinary(bytes), 2);
|
|
1051
|
+
}
|
|
1052
|
+
function generateRandomInteger(max) {
|
|
1053
|
+
if (max < 0 || !Number.isInteger(max)) {
|
|
1054
|
+
throw new Error(
|
|
1055
|
+
"Argument 'max' must be an integer greater than or equal to 0"
|
|
1056
|
+
);
|
|
1057
|
+
}
|
|
1058
|
+
const bitLength = (max - 1).toString(2).length;
|
|
1059
|
+
const shift = bitLength % 8;
|
|
1060
|
+
const bytes = new Uint8Array(Math.ceil(bitLength / 8));
|
|
1061
|
+
crypto.getRandomValues(bytes);
|
|
1062
|
+
if (shift !== 0) {
|
|
1063
|
+
bytes[0] &= (1 << shift) - 1;
|
|
1064
|
+
}
|
|
1065
|
+
let result = bytesToInteger(bytes);
|
|
1066
|
+
while (result >= max) {
|
|
1067
|
+
crypto.getRandomValues(bytes);
|
|
1068
|
+
if (shift !== 0) {
|
|
1069
|
+
bytes[0] &= (1 << shift) - 1;
|
|
1070
|
+
}
|
|
1071
|
+
result = bytesToInteger(bytes);
|
|
1072
|
+
}
|
|
1073
|
+
return result;
|
|
1074
|
+
}
|
|
1075
|
+
function generateRandomString(length, alphabet2) {
|
|
1076
|
+
let result = "";
|
|
1077
|
+
for (let i = 0; i < length; i++) {
|
|
1078
|
+
result += alphabet2[generateRandomInteger(alphabet2.length)];
|
|
1079
|
+
}
|
|
1080
|
+
return result;
|
|
1081
|
+
}
|
|
1082
|
+
function alphabet(...patterns) {
|
|
1083
|
+
const patternSet = new Set(patterns);
|
|
1084
|
+
let result = "";
|
|
1085
|
+
for (const pattern of patternSet) {
|
|
1086
|
+
if (pattern === "a-z") {
|
|
1087
|
+
result += "abcdefghijklmnopqrstuvwxyz";
|
|
1088
|
+
} else if (pattern === "A-Z") {
|
|
1089
|
+
result += "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
|
|
1090
|
+
} else if (pattern === "0-9") {
|
|
1091
|
+
result += "0123456789";
|
|
1092
|
+
} else {
|
|
1093
|
+
result += pattern;
|
|
1094
|
+
}
|
|
1095
|
+
}
|
|
1096
|
+
return result;
|
|
1097
|
+
}
|
|
1098
|
+
|
|
1083
1099
|
// src/utils/id.ts
|
|
1084
|
-
import { nanoid } from "nanoid";
|
|
1085
1100
|
var generateId = (size) => {
|
|
1086
|
-
return
|
|
1101
|
+
return generateRandomString(size || 21, alphabet("a-z", "0-9", "A-Z"));
|
|
1087
1102
|
};
|
|
1088
1103
|
|
|
1089
1104
|
// src/utils/hide-metadata.ts
|
|
@@ -1649,65 +1664,6 @@ var verifyEmail = createAuthEndpoint(
|
|
|
1649
1664
|
|
|
1650
1665
|
// src/api/routes/update-user.ts
|
|
1651
1666
|
import { z as z9 } from "zod";
|
|
1652
|
-
|
|
1653
|
-
// src/crypto/random.ts
|
|
1654
|
-
function byteToBinary(byte) {
|
|
1655
|
-
return byte.toString(2).padStart(8, "0");
|
|
1656
|
-
}
|
|
1657
|
-
function bytesToBinary(bytes) {
|
|
1658
|
-
return [...bytes].map((val) => byteToBinary(val)).join("");
|
|
1659
|
-
}
|
|
1660
|
-
function bytesToInteger(bytes) {
|
|
1661
|
-
return parseInt(bytesToBinary(bytes), 2);
|
|
1662
|
-
}
|
|
1663
|
-
function generateRandomInteger(max) {
|
|
1664
|
-
if (max < 0 || !Number.isInteger(max)) {
|
|
1665
|
-
throw new Error(
|
|
1666
|
-
"Argument 'max' must be an integer greater than or equal to 0"
|
|
1667
|
-
);
|
|
1668
|
-
}
|
|
1669
|
-
const bitLength = (max - 1).toString(2).length;
|
|
1670
|
-
const shift = bitLength % 8;
|
|
1671
|
-
const bytes = new Uint8Array(Math.ceil(bitLength / 8));
|
|
1672
|
-
crypto.getRandomValues(bytes);
|
|
1673
|
-
if (shift !== 0) {
|
|
1674
|
-
bytes[0] &= (1 << shift) - 1;
|
|
1675
|
-
}
|
|
1676
|
-
let result = bytesToInteger(bytes);
|
|
1677
|
-
while (result >= max) {
|
|
1678
|
-
crypto.getRandomValues(bytes);
|
|
1679
|
-
if (shift !== 0) {
|
|
1680
|
-
bytes[0] &= (1 << shift) - 1;
|
|
1681
|
-
}
|
|
1682
|
-
result = bytesToInteger(bytes);
|
|
1683
|
-
}
|
|
1684
|
-
return result;
|
|
1685
|
-
}
|
|
1686
|
-
function generateRandomString(length, alphabet2) {
|
|
1687
|
-
let result = "";
|
|
1688
|
-
for (let i = 0; i < length; i++) {
|
|
1689
|
-
result += alphabet2[generateRandomInteger(alphabet2.length)];
|
|
1690
|
-
}
|
|
1691
|
-
return result;
|
|
1692
|
-
}
|
|
1693
|
-
function alphabet(...patterns) {
|
|
1694
|
-
const patternSet = new Set(patterns);
|
|
1695
|
-
let result = "";
|
|
1696
|
-
for (const pattern of patternSet) {
|
|
1697
|
-
if (pattern === "a-z") {
|
|
1698
|
-
result += "abcdefghijklmnopqrstuvwxyz";
|
|
1699
|
-
} else if (pattern === "A-Z") {
|
|
1700
|
-
result += "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
|
|
1701
|
-
} else if (pattern === "0-9") {
|
|
1702
|
-
result += "0123456789";
|
|
1703
|
-
} else {
|
|
1704
|
-
result += pattern;
|
|
1705
|
-
}
|
|
1706
|
-
}
|
|
1707
|
-
return result;
|
|
1708
|
-
}
|
|
1709
|
-
|
|
1710
|
-
// src/api/routes/update-user.ts
|
|
1711
1667
|
var updateUser = createAuthEndpoint(
|
|
1712
1668
|
"/user/update",
|
|
1713
1669
|
{
|
|
@@ -5617,30 +5573,23 @@ import { serializeSigned } from "better-call";
|
|
|
5617
5573
|
var bearer = () => {
|
|
5618
5574
|
return {
|
|
5619
5575
|
id: "bearer",
|
|
5620
|
-
|
|
5621
|
-
|
|
5622
|
-
|
|
5623
|
-
|
|
5624
|
-
|
|
5625
|
-
|
|
5626
|
-
|
|
5627
|
-
|
|
5628
|
-
|
|
5629
|
-
|
|
5630
|
-
|
|
5631
|
-
|
|
5632
|
-
|
|
5633
|
-
|
|
5634
|
-
|
|
5635
|
-
|
|
5636
|
-
|
|
5637
|
-
headers.set(
|
|
5638
|
-
"cookie",
|
|
5639
|
-
`${ctx.context.authCookies.sessionToken.name}=${signedToken.replace("=", "")}`
|
|
5640
|
-
);
|
|
5641
|
-
}
|
|
5642
|
-
}
|
|
5643
|
-
]
|
|
5576
|
+
async onRequest(request, ctx) {
|
|
5577
|
+
const token = request.headers.get("authorization")?.replace("Bearer ", "");
|
|
5578
|
+
if (!token) {
|
|
5579
|
+
return;
|
|
5580
|
+
}
|
|
5581
|
+
const headers = request.headers || new Headers();
|
|
5582
|
+
const signedToken = await serializeSigned("", token, ctx.secret);
|
|
5583
|
+
headers.set(
|
|
5584
|
+
"cookie",
|
|
5585
|
+
`${ctx.authCookies.sessionToken.name}=${signedToken.replace("=", "")}`
|
|
5586
|
+
);
|
|
5587
|
+
return {
|
|
5588
|
+
request: new Request(request.url, {
|
|
5589
|
+
method: request.method,
|
|
5590
|
+
headers
|
|
5591
|
+
})
|
|
5592
|
+
};
|
|
5644
5593
|
}
|
|
5645
5594
|
};
|
|
5646
5595
|
};
|
|
@@ -6139,9 +6088,133 @@ var phoneNumber = (options) => {
|
|
|
6139
6088
|
}
|
|
6140
6089
|
};
|
|
6141
6090
|
};
|
|
6091
|
+
|
|
6092
|
+
// src/plugins/anonymous/index.ts
|
|
6093
|
+
import { z as z26 } from "zod";
|
|
6094
|
+
var anonymous = () => {
|
|
6095
|
+
return {
|
|
6096
|
+
id: "anonymous",
|
|
6097
|
+
endpoints: {
|
|
6098
|
+
signInAnonymous: createAuthEndpoint(
|
|
6099
|
+
"/sign-in/anonymous",
|
|
6100
|
+
{
|
|
6101
|
+
method: "POST"
|
|
6102
|
+
},
|
|
6103
|
+
async (ctx) => {
|
|
6104
|
+
const tempEmail = "temporary-" + Date.now().toString() + "-better-auth@email.com";
|
|
6105
|
+
const newUser = await ctx.context.internalAdapter.createUser({
|
|
6106
|
+
id: generateId(),
|
|
6107
|
+
email: tempEmail,
|
|
6108
|
+
emailVerified: false,
|
|
6109
|
+
isAnonymous: true,
|
|
6110
|
+
name: "Anonymous",
|
|
6111
|
+
createdAt: /* @__PURE__ */ new Date(),
|
|
6112
|
+
updatedAt: /* @__PURE__ */ new Date()
|
|
6113
|
+
});
|
|
6114
|
+
if (!newUser) {
|
|
6115
|
+
return ctx.json(null, {
|
|
6116
|
+
status: 500,
|
|
6117
|
+
body: {
|
|
6118
|
+
message: "Failed to create user",
|
|
6119
|
+
status: 500
|
|
6120
|
+
}
|
|
6121
|
+
});
|
|
6122
|
+
}
|
|
6123
|
+
const session = await ctx.context.internalAdapter.createSession(
|
|
6124
|
+
newUser.id,
|
|
6125
|
+
ctx.request
|
|
6126
|
+
);
|
|
6127
|
+
if (!session) {
|
|
6128
|
+
return ctx.json(null, {
|
|
6129
|
+
status: 400,
|
|
6130
|
+
body: {
|
|
6131
|
+
message: "Could not create session"
|
|
6132
|
+
}
|
|
6133
|
+
});
|
|
6134
|
+
}
|
|
6135
|
+
await setSessionCookie(ctx, session.id);
|
|
6136
|
+
return ctx.json({ user: newUser, session });
|
|
6137
|
+
}
|
|
6138
|
+
),
|
|
6139
|
+
linkAnonymous: createAuthEndpoint(
|
|
6140
|
+
"/user/link-anonymous",
|
|
6141
|
+
{
|
|
6142
|
+
method: "POST",
|
|
6143
|
+
body: z26.object({
|
|
6144
|
+
email: z26.string().email().optional(),
|
|
6145
|
+
password: z26.string().min(6)
|
|
6146
|
+
}),
|
|
6147
|
+
use: [sessionMiddleware]
|
|
6148
|
+
},
|
|
6149
|
+
async (ctx) => {
|
|
6150
|
+
const userId = ctx.context.session.user.id;
|
|
6151
|
+
const { email, password } = ctx.body;
|
|
6152
|
+
let updatedUser = null;
|
|
6153
|
+
if (email && password) {
|
|
6154
|
+
updatedUser = await ctx.context.internalAdapter.updateUser(userId, {
|
|
6155
|
+
email
|
|
6156
|
+
});
|
|
6157
|
+
}
|
|
6158
|
+
if (!updatedUser) {
|
|
6159
|
+
return ctx.json(null, {
|
|
6160
|
+
status: 500,
|
|
6161
|
+
body: {
|
|
6162
|
+
message: "Failed to update user",
|
|
6163
|
+
status: 500
|
|
6164
|
+
}
|
|
6165
|
+
});
|
|
6166
|
+
}
|
|
6167
|
+
const hash = await ctx.context.password.hash(password);
|
|
6168
|
+
const updateUserAccount = await ctx.context.internalAdapter.linkAccount({
|
|
6169
|
+
id: generateRandomString(32, alphabet("a-z", "0-9", "A-Z")),
|
|
6170
|
+
userId: updatedUser.id,
|
|
6171
|
+
providerId: "credential",
|
|
6172
|
+
password: hash,
|
|
6173
|
+
accountId: updatedUser.id
|
|
6174
|
+
});
|
|
6175
|
+
if (!updateUserAccount) {
|
|
6176
|
+
return ctx.json(null, {
|
|
6177
|
+
status: 500,
|
|
6178
|
+
body: {
|
|
6179
|
+
message: "Failed to update account",
|
|
6180
|
+
status: 500
|
|
6181
|
+
}
|
|
6182
|
+
});
|
|
6183
|
+
}
|
|
6184
|
+
const session = await ctx.context.internalAdapter.createSession(
|
|
6185
|
+
updatedUser.id,
|
|
6186
|
+
ctx.request
|
|
6187
|
+
);
|
|
6188
|
+
if (!session) {
|
|
6189
|
+
return ctx.json(null, {
|
|
6190
|
+
status: 400,
|
|
6191
|
+
body: {
|
|
6192
|
+
message: "Could not create session"
|
|
6193
|
+
}
|
|
6194
|
+
});
|
|
6195
|
+
}
|
|
6196
|
+
await setSessionCookie(ctx, session.id);
|
|
6197
|
+
return ctx.json({ session, user: updatedUser });
|
|
6198
|
+
}
|
|
6199
|
+
)
|
|
6200
|
+
},
|
|
6201
|
+
schema: {
|
|
6202
|
+
user: {
|
|
6203
|
+
fields: {
|
|
6204
|
+
isAnonymous: {
|
|
6205
|
+
type: "boolean",
|
|
6206
|
+
defaultValue: true,
|
|
6207
|
+
required: false
|
|
6208
|
+
}
|
|
6209
|
+
}
|
|
6210
|
+
}
|
|
6211
|
+
}
|
|
6212
|
+
};
|
|
6213
|
+
};
|
|
6142
6214
|
export {
|
|
6143
6215
|
HIDE_METADATA,
|
|
6144
6216
|
access_exports as ac,
|
|
6217
|
+
anonymous,
|
|
6145
6218
|
bearer,
|
|
6146
6219
|
createAuthEndpoint,
|
|
6147
6220
|
createAuthMiddleware,
|
package/dist/react.d.ts
CHANGED
|
@@ -3,7 +3,7 @@ import { U as UnionToIntersection, P as Prettify, S as StripEmptyObjects } from
|
|
|
3
3
|
import { ClientOptions, InferClientAPI, InferActions, InferAdditionalFromClient, BetterAuthClientPlugin, IsSignal } from './types.js';
|
|
4
4
|
import { useStore } from '@nanostores/react';
|
|
5
5
|
import 'zod';
|
|
6
|
-
import './index-
|
|
6
|
+
import './index-BRcc7HbO.js';
|
|
7
7
|
import 'kysely';
|
|
8
8
|
import './index-JM-i6hLs.js';
|
|
9
9
|
import 'arctic';
|
package/dist/solid-start.d.ts
CHANGED
package/dist/solid.d.ts
CHANGED
|
@@ -3,7 +3,7 @@ import { U as UnionToIntersection, P as Prettify, S as StripEmptyObjects } from
|
|
|
3
3
|
import { ClientOptions, InferClientAPI, InferActions, InferAdditionalFromClient, BetterAuthClientPlugin, IsSignal } from './types.js';
|
|
4
4
|
import { Accessor } from 'solid-js';
|
|
5
5
|
import 'zod';
|
|
6
|
-
import './index-
|
|
6
|
+
import './index-BRcc7HbO.js';
|
|
7
7
|
import 'kysely';
|
|
8
8
|
import './index-JM-i6hLs.js';
|
|
9
9
|
import 'arctic';
|
package/dist/svelte-kit.d.ts
CHANGED
package/dist/svelte.d.ts
CHANGED
|
@@ -3,7 +3,7 @@ import * as _better_fetch_fetch from '@better-fetch/fetch';
|
|
|
3
3
|
import { U as UnionToIntersection, P as Prettify, S as StripEmptyObjects } from './helper-DPDj8Nix.js';
|
|
4
4
|
import { ClientOptions, InferClientAPI, InferActions, InferAdditionalFromClient, BetterAuthClientPlugin, IsSignal } from './types.js';
|
|
5
5
|
import 'zod';
|
|
6
|
-
import './index-
|
|
6
|
+
import './index-BRcc7HbO.js';
|
|
7
7
|
import 'kysely';
|
|
8
8
|
import './index-JM-i6hLs.js';
|
|
9
9
|
import 'arctic';
|
package/dist/types.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export { A as Adapter,
|
|
1
|
+
import { c as BetterAuthPlugin, a as Auth, F as FieldAttribute, I as InferFieldOutput } from './index-BRcc7HbO.js';
|
|
2
|
+
export { A as Adapter, b as AuthContext, B as BetterAuthOptions, G as GenericEndpointContext, H as HookEndpointContext, j as InferPluginTypes, i as InferSession, h as InferUser, P as PluginSchema, R as RateLimit, S as SessionAdapter, W as Where, k as init } from './index-BRcc7HbO.js';
|
|
3
3
|
import { U as UnionToIntersection, H as HasRequiredKeys, P as Prettify, S as StripEmptyObjects, L as LiteralString } from './helper-DPDj8Nix.js';
|
|
4
4
|
export { D as DeepPartial, a as LiteralUnion, R as RequiredKeysOf, W as WithoutEmpty } from './helper-DPDj8Nix.js';
|
|
5
5
|
import { S as Session, U as User } from './index-JM-i6hLs.js';
|
package/dist/vue.d.ts
CHANGED
|
@@ -3,7 +3,7 @@ import { U as UnionToIntersection, P as Prettify, S as StripEmptyObjects } from
|
|
|
3
3
|
import { ClientOptions, InferClientAPI, InferActions, InferAdditionalFromClient, BetterAuthClientPlugin, IsSignal } from './types.js';
|
|
4
4
|
import { Ref, DeepReadonly } from 'vue';
|
|
5
5
|
import 'zod';
|
|
6
|
-
import './index-
|
|
6
|
+
import './index-BRcc7HbO.js';
|
|
7
7
|
import 'kysely';
|
|
8
8
|
import './index-JM-i6hLs.js';
|
|
9
9
|
import 'arctic';
|