@convex-dev/better-auth 0.7.0-alpha.11 → 0.7.0-alpha.2
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/commonjs/client/adapter.d.ts +1 -10
- package/dist/commonjs/client/adapter.d.ts.map +1 -1
- package/dist/commonjs/client/adapter.js +192 -183
- package/dist/commonjs/client/adapter.js.map +1 -1
- package/dist/commonjs/client/index.d.ts +179 -238
- package/dist/commonjs/client/index.d.ts.map +1 -1
- package/dist/commonjs/client/index.js +67 -60
- package/dist/commonjs/client/index.js.map +1 -1
- package/dist/commonjs/component/lib.d.ts +548 -218
- package/dist/commonjs/component/lib.d.ts.map +1 -1
- package/dist/commonjs/component/lib.js +286 -315
- package/dist/commonjs/component/lib.js.map +1 -1
- package/dist/commonjs/component/schema.d.ts +28 -90
- package/dist/commonjs/component/schema.d.ts.map +1 -1
- package/dist/commonjs/component/schema.js +18 -76
- package/dist/commonjs/component/schema.js.map +1 -1
- package/dist/commonjs/component/util.d.ts +86 -148
- package/dist/commonjs/component/util.d.ts.map +1 -1
- package/dist/commonjs/nextjs/index.d.ts.map +1 -1
- package/dist/commonjs/nextjs/index.js +0 -12
- package/dist/commonjs/nextjs/index.js.map +1 -1
- package/dist/commonjs/plugins/convex/index.d.ts +11 -14
- package/dist/commonjs/plugins/convex/index.d.ts.map +1 -1
- package/dist/commonjs/plugins/convex/index.js +4 -10
- package/dist/commonjs/plugins/convex/index.js.map +1 -1
- package/dist/commonjs/plugins/cross-domain/client.d.ts +1 -1
- package/dist/commonjs/plugins/cross-domain/index.d.ts +3 -5
- package/dist/commonjs/plugins/cross-domain/index.d.ts.map +1 -1
- package/dist/commonjs/plugins/cross-domain/index.js +5 -19
- package/dist/commonjs/plugins/cross-domain/index.js.map +1 -1
- package/dist/commonjs/react/client.d.ts +1 -1
- package/dist/commonjs/react/client.d.ts.map +1 -1
- package/dist/commonjs/react/client.js +9 -3
- package/dist/commonjs/react/client.js.map +1 -1
- package/dist/commonjs/react-start/index.d.ts +3 -37
- package/dist/commonjs/react-start/index.d.ts.map +1 -1
- package/dist/commonjs/react-start/index.js +4 -20
- package/dist/commonjs/react-start/index.js.map +1 -1
- package/dist/esm/client/adapter.d.ts +1 -10
- package/dist/esm/client/adapter.d.ts.map +1 -1
- package/dist/esm/client/adapter.js +192 -183
- package/dist/esm/client/adapter.js.map +1 -1
- package/dist/esm/client/index.d.ts +179 -238
- package/dist/esm/client/index.d.ts.map +1 -1
- package/dist/esm/client/index.js +67 -60
- package/dist/esm/client/index.js.map +1 -1
- package/dist/esm/component/lib.d.ts +548 -218
- package/dist/esm/component/lib.d.ts.map +1 -1
- package/dist/esm/component/lib.js +286 -315
- package/dist/esm/component/lib.js.map +1 -1
- package/dist/esm/component/schema.d.ts +28 -90
- package/dist/esm/component/schema.d.ts.map +1 -1
- package/dist/esm/component/schema.js +18 -76
- package/dist/esm/component/schema.js.map +1 -1
- package/dist/esm/component/util.d.ts +86 -148
- package/dist/esm/component/util.d.ts.map +1 -1
- package/dist/esm/nextjs/index.d.ts.map +1 -1
- package/dist/esm/nextjs/index.js +0 -12
- package/dist/esm/nextjs/index.js.map +1 -1
- package/dist/esm/plugins/convex/index.d.ts +11 -14
- package/dist/esm/plugins/convex/index.d.ts.map +1 -1
- package/dist/esm/plugins/convex/index.js +4 -10
- package/dist/esm/plugins/convex/index.js.map +1 -1
- package/dist/esm/plugins/cross-domain/client.d.ts +1 -1
- package/dist/esm/plugins/cross-domain/index.d.ts +3 -5
- package/dist/esm/plugins/cross-domain/index.d.ts.map +1 -1
- package/dist/esm/plugins/cross-domain/index.js +5 -19
- package/dist/esm/plugins/cross-domain/index.js.map +1 -1
- package/dist/esm/react/client.d.ts +1 -1
- package/dist/esm/react/client.d.ts.map +1 -1
- package/dist/esm/react/client.js +9 -3
- package/dist/esm/react/client.js.map +1 -1
- package/dist/esm/react-start/index.d.ts +3 -37
- package/dist/esm/react-start/index.d.ts.map +1 -1
- package/dist/esm/react-start/index.js +4 -20
- package/dist/esm/react-start/index.js.map +1 -1
- package/package.json +5 -20
- package/src/client/adapter.ts +195 -191
- package/src/client/cors.ts +425 -0
- package/src/client/index.ts +80 -61
- package/src/component/_generated/api.d.ts +149 -605
- package/src/component/lib.ts +335 -444
- package/src/component/schema.ts +19 -81
- package/src/nextjs/index.ts +0 -17
- package/src/plugins/convex/index.ts +4 -12
- package/src/plugins/cross-domain/index.ts +5 -19
- package/src/react/client.tsx +11 -5
- package/src/react-start/index.ts +6 -33
- package/dist/commonjs/component/adapterTest.d.ts +0 -19
- package/dist/commonjs/component/adapterTest.d.ts.map +0 -1
- package/dist/commonjs/component/adapterTest.js +0 -82
- package/dist/commonjs/component/adapterTest.js.map +0 -1
- package/dist/commonjs/utils/index.d.ts +0 -2
- package/dist/commonjs/utils/index.d.ts.map +0 -1
- package/dist/commonjs/utils/index.js +0 -8
- package/dist/commonjs/utils/index.js.map +0 -1
- package/dist/esm/component/adapterTest.d.ts +0 -19
- package/dist/esm/component/adapterTest.d.ts.map +0 -1
- package/dist/esm/component/adapterTest.js +0 -82
- package/dist/esm/component/adapterTest.js.map +0 -1
- package/dist/esm/utils/index.d.ts +0 -2
- package/dist/esm/utils/index.d.ts.map +0 -1
- package/dist/esm/utils/index.js +0 -8
- package/dist/esm/utils/index.js.map +0 -1
- package/src/client/adapter.test.ts +0 -144
- package/src/component/adapterTest.ts +0 -141
- package/src/react-start/vite-env.d.ts +0 -2
- /package/src/{utils/index.ts → util.ts} +0 -0
package/src/component/schema.ts
CHANGED
|
@@ -1,7 +1,3 @@
|
|
|
1
|
-
// This file is auto-generated from auth.ts by generate-schema.ts. Do not edit this file manually.
|
|
2
|
-
// To regenerate the schema, run:
|
|
3
|
-
// npx tsx generate-schema.ts
|
|
4
|
-
|
|
5
1
|
import { defineSchema, defineTable } from "convex/server";
|
|
6
2
|
import { v } from "convex/values";
|
|
7
3
|
|
|
@@ -11,19 +7,13 @@ const schema = defineSchema({
|
|
|
11
7
|
email: v.string(),
|
|
12
8
|
emailVerified: v.boolean(),
|
|
13
9
|
image: v.optional(v.string()),
|
|
10
|
+
twoFactorEnabled: v.optional(v.boolean()),
|
|
11
|
+
userId: v.string(),
|
|
14
12
|
createdAt: v.number(),
|
|
15
13
|
updatedAt: v.number(),
|
|
16
|
-
twoFactorEnabled: v.optional(v.boolean()),
|
|
17
|
-
isAnonymous: v.optional(v.boolean()),
|
|
18
|
-
username: v.optional(v.string()),
|
|
19
|
-
displayUsername: v.optional(v.string()),
|
|
20
|
-
userId: v.optional(v.string()),
|
|
21
14
|
})
|
|
22
|
-
.index("email_name", ["email","name"])
|
|
23
|
-
.index("name", ["name"])
|
|
24
|
-
.index("userId", ["userId"])
|
|
25
15
|
.index("email", ["email"])
|
|
26
|
-
.index("
|
|
16
|
+
.index("userId", ["userId"]),
|
|
27
17
|
|
|
28
18
|
session: defineTable({
|
|
29
19
|
expiresAt: v.number(),
|
|
@@ -34,10 +24,10 @@ const schema = defineSchema({
|
|
|
34
24
|
userAgent: v.optional(v.string()),
|
|
35
25
|
userId: v.string(),
|
|
36
26
|
})
|
|
37
|
-
.index("expiresAt", ["expiresAt"])
|
|
38
|
-
.index("expiresAt_userId", ["expiresAt","userId"])
|
|
39
27
|
.index("token", ["token"])
|
|
40
|
-
.index("userId", ["userId"])
|
|
28
|
+
.index("userId", ["userId"])
|
|
29
|
+
.index("expiresAt", ["expiresAt"])
|
|
30
|
+
.index("userId_expiresAt", ["userId", "expiresAt"]),
|
|
41
31
|
|
|
42
32
|
account: defineTable({
|
|
43
33
|
accountId: v.string(),
|
|
@@ -53,10 +43,16 @@ const schema = defineSchema({
|
|
|
53
43
|
createdAt: v.number(),
|
|
54
44
|
updatedAt: v.number(),
|
|
55
45
|
})
|
|
46
|
+
.index("userId", ["userId"])
|
|
56
47
|
.index("accountId", ["accountId"])
|
|
57
|
-
.index("
|
|
58
|
-
.index("
|
|
59
|
-
|
|
48
|
+
.index("providerId_accountId", ["providerId", "accountId"])
|
|
49
|
+
.index("userId_providerId", ["userId", "providerId"]),
|
|
50
|
+
|
|
51
|
+
twoFactor: defineTable({
|
|
52
|
+
secret: v.string(),
|
|
53
|
+
backupCodes: v.string(),
|
|
54
|
+
userId: v.string(),
|
|
55
|
+
}).index("userId", ["userId"]),
|
|
60
56
|
|
|
61
57
|
verification: defineTable({
|
|
62
58
|
identifier: v.string(),
|
|
@@ -65,74 +61,16 @@ const schema = defineSchema({
|
|
|
65
61
|
createdAt: v.optional(v.number()),
|
|
66
62
|
updatedAt: v.optional(v.number()),
|
|
67
63
|
})
|
|
68
|
-
.index("
|
|
69
|
-
.index("
|
|
70
|
-
|
|
71
|
-
twoFactor: defineTable({
|
|
72
|
-
secret: v.string(),
|
|
73
|
-
backupCodes: v.string(),
|
|
74
|
-
userId: v.string(),
|
|
75
|
-
})
|
|
76
|
-
.index("userId", ["userId"]),
|
|
64
|
+
.index("identifier", ["identifier"])
|
|
65
|
+
.index("expiresAt", ["expiresAt"]),
|
|
77
66
|
|
|
78
67
|
jwks: defineTable({
|
|
79
68
|
publicKey: v.string(),
|
|
80
69
|
privateKey: v.string(),
|
|
81
70
|
createdAt: v.number(),
|
|
71
|
+
// no longer used
|
|
72
|
+
id: v.optional(v.string()),
|
|
82
73
|
}),
|
|
83
|
-
|
|
84
|
-
rateLimit: defineTable({
|
|
85
|
-
key: v.optional(v.string()),
|
|
86
|
-
count: v.optional(v.number()),
|
|
87
|
-
lastRequest: v.optional(v.number()),
|
|
88
|
-
})
|
|
89
|
-
.index("key", ["key"]),
|
|
90
|
-
|
|
91
74
|
});
|
|
92
75
|
|
|
93
76
|
export default schema;
|
|
94
|
-
|
|
95
|
-
export const specialFields = {
|
|
96
|
-
user: {
|
|
97
|
-
name: {
|
|
98
|
-
sortable: true
|
|
99
|
-
},
|
|
100
|
-
email: {
|
|
101
|
-
sortable: true,
|
|
102
|
-
unique: true
|
|
103
|
-
},
|
|
104
|
-
username: {
|
|
105
|
-
sortable: true,
|
|
106
|
-
unique: true
|
|
107
|
-
}
|
|
108
|
-
},
|
|
109
|
-
session: {
|
|
110
|
-
token: {
|
|
111
|
-
unique: true
|
|
112
|
-
},
|
|
113
|
-
userId: {
|
|
114
|
-
references: {
|
|
115
|
-
model: "user",
|
|
116
|
-
field: "id",
|
|
117
|
-
onDelete: "cascade"
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
},
|
|
121
|
-
account: {
|
|
122
|
-
userId: {
|
|
123
|
-
references: {
|
|
124
|
-
model: "user",
|
|
125
|
-
field: "id",
|
|
126
|
-
onDelete: "cascade"
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
},
|
|
130
|
-
twoFactor: {
|
|
131
|
-
userId: {
|
|
132
|
-
references: {
|
|
133
|
-
model: "user",
|
|
134
|
-
field: "id"
|
|
135
|
-
}
|
|
136
|
-
}
|
|
137
|
-
}
|
|
138
|
-
};
|
package/src/nextjs/index.ts
CHANGED
|
@@ -3,23 +3,9 @@ import { createCookieGetter } from "better-auth/cookies";
|
|
|
3
3
|
import { GenericActionCtx } from "convex/server";
|
|
4
4
|
import { JWT_COOKIE_NAME } from "../plugins/convex";
|
|
5
5
|
|
|
6
|
-
const requireBaseURL = (
|
|
7
|
-
createAuth: (ctx: GenericActionCtx<any>) => ReturnType<typeof betterAuth>
|
|
8
|
-
) => {
|
|
9
|
-
if (!createAuth({} as any).options.baseURL) {
|
|
10
|
-
throw new Error(
|
|
11
|
-
"No baseURL found in Better Auth config. baseUrl should be set to your Convex Site URL."
|
|
12
|
-
);
|
|
13
|
-
}
|
|
14
|
-
return createAuth({} as any).options.baseURL;
|
|
15
|
-
};
|
|
16
|
-
|
|
17
6
|
export const getToken = async (
|
|
18
7
|
createAuth: (ctx: GenericActionCtx<any>) => ReturnType<typeof betterAuth>
|
|
19
8
|
) => {
|
|
20
|
-
// Require baseURL here because it's protocol determines cookie secure mode,
|
|
21
|
-
// and must be set to ensure cookies work between Next.js and Convex.
|
|
22
|
-
requireBaseURL(createAuth);
|
|
23
9
|
const { cookies } = await import("next/headers");
|
|
24
10
|
const cookieStore = await cookies();
|
|
25
11
|
const auth = createAuth({} as any);
|
|
@@ -33,9 +19,6 @@ const handler = (request: Request, opts?: { convexSiteUrl?: string }) => {
|
|
|
33
19
|
const requestUrl = new URL(request.url);
|
|
34
20
|
const convexSiteUrl =
|
|
35
21
|
opts?.convexSiteUrl ?? process.env.NEXT_PUBLIC_CONVEX_SITE_URL;
|
|
36
|
-
if (!convexSiteUrl) {
|
|
37
|
-
throw new Error("NEXT_PUBLIC_CONVEX_SITE_URL is not set");
|
|
38
|
-
}
|
|
39
22
|
const nextUrl = `${convexSiteUrl}${requestUrl.pathname}${requestUrl.search}`;
|
|
40
23
|
const newRequest = new Request(nextUrl, request);
|
|
41
24
|
newRequest.headers.set("accept-encoding", "application/json");
|
|
@@ -51,7 +51,7 @@ export const convex = (
|
|
|
51
51
|
return session.user.userId;
|
|
52
52
|
},
|
|
53
53
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
54
|
-
definePayload: ({ user: { id, userId,
|
|
54
|
+
definePayload: ({ user: { id, userId, ...user }, session }) => ({
|
|
55
55
|
...user,
|
|
56
56
|
sessionId: session.id,
|
|
57
57
|
}),
|
|
@@ -108,13 +108,8 @@ export const convex = (
|
|
|
108
108
|
{
|
|
109
109
|
matcher: (ctx) => {
|
|
110
110
|
return (
|
|
111
|
-
ctx.path
|
|
112
|
-
ctx.path
|
|
113
|
-
ctx.path.startsWith("/callback") ||
|
|
114
|
-
ctx.path.startsWith("/oauth2/callback") ||
|
|
115
|
-
ctx.path.startsWith("/magic-link/verify") ||
|
|
116
|
-
ctx.path.startsWith("/email-otp/verify-email") ||
|
|
117
|
-
ctx.path.startsWith("/phone-number/verify")
|
|
111
|
+
ctx.path?.startsWith("/sign-in") ||
|
|
112
|
+
ctx.path?.startsWith("/callback")
|
|
118
113
|
);
|
|
119
114
|
},
|
|
120
115
|
handler: createAuthMiddleware(async (ctx) => {
|
|
@@ -144,10 +139,7 @@ export const convex = (
|
|
|
144
139
|
},
|
|
145
140
|
{
|
|
146
141
|
matcher: (ctx) => {
|
|
147
|
-
return (
|
|
148
|
-
ctx.path?.startsWith("/sign-out") ||
|
|
149
|
-
ctx.path?.startsWith("/delete-user")
|
|
150
|
-
);
|
|
142
|
+
return ctx.path?.startsWith("/sign-out");
|
|
151
143
|
},
|
|
152
144
|
handler: createAuthMiddleware(async (ctx) => {
|
|
153
145
|
const jwtCookie = ctx.context.createAuthCookie(JWT_COOKIE_NAME, {
|
|
@@ -21,13 +21,6 @@ export const crossDomain = ({ siteUrl }: { siteUrl: string }) => {
|
|
|
21
21
|
|
|
22
22
|
return {
|
|
23
23
|
id: "cross-domain",
|
|
24
|
-
init(ctx) {
|
|
25
|
-
return {
|
|
26
|
-
options: {
|
|
27
|
-
trustedOrigins: [siteUrl],
|
|
28
|
-
},
|
|
29
|
-
};
|
|
30
|
-
},
|
|
31
24
|
hooks: {
|
|
32
25
|
before: [
|
|
33
26
|
{
|
|
@@ -59,22 +52,12 @@ export const crossDomain = ({ siteUrl }: { siteUrl: string }) => {
|
|
|
59
52
|
};
|
|
60
53
|
}),
|
|
61
54
|
},
|
|
62
|
-
{
|
|
63
|
-
matcher: (ctx) => {
|
|
64
|
-
return ctx.method === "GET" && ctx.path.startsWith("/verify-email");
|
|
65
|
-
},
|
|
66
|
-
handler: createAuthMiddleware(async (ctx) => {
|
|
67
|
-
if (ctx.query?.callbackURL) {
|
|
68
|
-
ctx.query.callbackURL = rewriteCallbackURL(ctx.query.callbackURL);
|
|
69
|
-
}
|
|
70
|
-
return { context: ctx };
|
|
71
|
-
}),
|
|
72
|
-
},
|
|
73
55
|
{
|
|
74
56
|
matcher: (ctx) => {
|
|
75
57
|
return (
|
|
76
|
-
|
|
58
|
+
ctx.path.startsWith("/link-social") ||
|
|
77
59
|
ctx.path.startsWith("/send-verification-email") ||
|
|
60
|
+
ctx.path.startsWith("/verify-email") ||
|
|
78
61
|
ctx.path.startsWith("/sign-in/email") ||
|
|
79
62
|
ctx.path.startsWith("/sign-in/social") ||
|
|
80
63
|
ctx.path.startsWith("/sign-in/magic-link") ||
|
|
@@ -166,5 +149,8 @@ export const crossDomain = ({ siteUrl }: { siteUrl: string }) => {
|
|
|
166
149
|
}
|
|
167
150
|
),
|
|
168
151
|
},
|
|
152
|
+
options: {
|
|
153
|
+
trustedOrigins: [siteUrl],
|
|
154
|
+
},
|
|
169
155
|
} satisfies BetterAuthPlugin;
|
|
170
156
|
};
|
package/src/react/client.tsx
CHANGED
|
@@ -27,7 +27,7 @@ export function useAuth() {
|
|
|
27
27
|
}
|
|
28
28
|
|
|
29
29
|
export type ConvexAuthClient = {
|
|
30
|
-
verbose
|
|
30
|
+
verbose: boolean | undefined;
|
|
31
31
|
logger?: ConvexReactClient["logger"];
|
|
32
32
|
};
|
|
33
33
|
|
|
@@ -64,7 +64,7 @@ export function AuthProvider({
|
|
|
64
64
|
const { data: session, isPending: isSessionPending } =
|
|
65
65
|
authClient.useSession();
|
|
66
66
|
|
|
67
|
-
const verbose: boolean = client.verbose ?? false;
|
|
67
|
+
const verbose: boolean = (client as any).options?.verbose ?? false;
|
|
68
68
|
const logVerbose = useCallback(
|
|
69
69
|
(message: string) => {
|
|
70
70
|
if (verbose) {
|
|
@@ -128,11 +128,17 @@ export function AuthProvider({
|
|
|
128
128
|
() => {
|
|
129
129
|
// eslint-disable-next-line @typescript-eslint/no-floating-promises
|
|
130
130
|
(async () => {
|
|
131
|
-
|
|
131
|
+
// Return early if cross domain plugin is not configured.
|
|
132
|
+
// Apparently there's no sane way to do this type check. Only the in
|
|
133
|
+
// keyword narrows the type effectively but it doesn't work on functions.
|
|
134
|
+
if (!(authClient as any)["crossDomain"]) {
|
|
135
|
+
return;
|
|
136
|
+
}
|
|
137
|
+
const authClientWithCrossDomain =
|
|
138
|
+
authClient as AuthClientWithPlugins<PluginsWithCrossDomain>;
|
|
139
|
+
const url = new URL(window.location.href);
|
|
132
140
|
const token = url.searchParams.get("ott");
|
|
133
141
|
if (token) {
|
|
134
|
-
const authClientWithCrossDomain =
|
|
135
|
-
authClient as AuthClientWithPlugins<PluginsWithCrossDomain>;
|
|
136
142
|
url.searchParams.delete("ott");
|
|
137
143
|
const result =
|
|
138
144
|
await authClientWithCrossDomain.crossDomain.oneTimeToken.verify({
|
package/src/react-start/index.ts
CHANGED
|
@@ -13,38 +13,22 @@ export const getCookieName = async (
|
|
|
13
13
|
return cookie.name;
|
|
14
14
|
};
|
|
15
15
|
|
|
16
|
-
const requireConvexSiteUrl = (
|
|
17
|
-
opts: { convexSiteUrl: string; verbose?: boolean },
|
|
18
|
-
calledFrom: string
|
|
19
|
-
) => {
|
|
20
|
-
if (!opts.convexSiteUrl) {
|
|
21
|
-
throw new Error(`${calledFrom}: opts.convexSiteUrl is required`);
|
|
22
|
-
}
|
|
23
|
-
if (opts.verbose) {
|
|
24
|
-
console.log(`${calledFrom}: opts.convexSiteUrl: ${opts.convexSiteUrl}`);
|
|
25
|
-
}
|
|
26
|
-
return opts.convexSiteUrl;
|
|
27
|
-
};
|
|
28
|
-
|
|
29
16
|
export const fetchSession = async <
|
|
30
17
|
T extends (ctx: GenericActionCtx<any>) => ReturnType<typeof betterAuth>,
|
|
31
18
|
>(
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
convexSiteUrl: string;
|
|
35
|
-
verbose?: boolean;
|
|
36
|
-
}
|
|
19
|
+
createAuth: T,
|
|
20
|
+
request?: Request
|
|
37
21
|
) => {
|
|
38
22
|
type Session = ReturnType<T>["$Infer"]["Session"];
|
|
39
23
|
|
|
40
24
|
if (!request) {
|
|
41
25
|
throw new Error("No request found");
|
|
42
26
|
}
|
|
43
|
-
const
|
|
27
|
+
const baseURL = new URL(request.url).origin;
|
|
44
28
|
const { data: session } = await betterFetch<Session>(
|
|
45
29
|
"/api/auth/get-session",
|
|
46
30
|
{
|
|
47
|
-
baseURL
|
|
31
|
+
baseURL,
|
|
48
32
|
headers: {
|
|
49
33
|
cookie: request.headers.get("cookie") ?? "",
|
|
50
34
|
},
|
|
@@ -57,22 +41,11 @@ export const fetchSession = async <
|
|
|
57
41
|
|
|
58
42
|
export const reactStartHandler = (
|
|
59
43
|
request: Request,
|
|
60
|
-
opts
|
|
44
|
+
opts?: { convexSiteUrl?: string }
|
|
61
45
|
) => {
|
|
46
|
+
const convexSiteUrl = opts?.convexSiteUrl ?? process.env.VITE_CONVEX_SITE_URL;
|
|
62
47
|
const requestUrl = new URL(request.url);
|
|
63
|
-
const convexSiteUrl = requireConvexSiteUrl(opts, "reactStartHandler");
|
|
64
48
|
const nextUrl = `${convexSiteUrl}${requestUrl.pathname}${requestUrl.search}`;
|
|
65
49
|
request.headers.set("accept-encoding", "application/json");
|
|
66
50
|
return fetch(nextUrl, new Request(request, { redirect: "manual" }));
|
|
67
51
|
};
|
|
68
|
-
|
|
69
|
-
export const reactStartHelpers = (
|
|
70
|
-
createAuth: (ctx: GenericActionCtx<any>) => ReturnType<typeof betterAuth>,
|
|
71
|
-
opts: { convexSiteUrl: string; verbose?: boolean }
|
|
72
|
-
) => {
|
|
73
|
-
return {
|
|
74
|
-
fetchSession: (request: Request) => fetchSession(request, opts),
|
|
75
|
-
reactStartHandler: (request: Request) => reactStartHandler(request, opts),
|
|
76
|
-
getCookieName: () => getCookieName(createAuth),
|
|
77
|
-
};
|
|
78
|
-
};
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import { GenericCtx } from "./_generated/server";
|
|
2
|
-
import { RegisteredMutation, RegisteredQuery } from "convex/server";
|
|
3
|
-
export declare const betterAuthComponent: any;
|
|
4
|
-
export declare const createAdapter: (ctx: GenericCtx) => (options: import("better-auth").BetterAuthOptions) => import("better-auth").Adapter;
|
|
5
|
-
export declare const createUser: any, deleteUser: any, updateUser: any, createSession: any, isAuthenticated: any;
|
|
6
|
-
export declare const deserialize: (data: any) => {
|
|
7
|
-
[k: string]: unknown;
|
|
8
|
-
};
|
|
9
|
-
export declare const serialize: (data: any) => any;
|
|
10
|
-
export declare const create: RegisteredMutation<"public", any, Promise<any>>;
|
|
11
|
-
export declare const findOne: RegisteredQuery<"public", any, Promise<any>>;
|
|
12
|
-
export declare const findMany: RegisteredQuery<"public", any, Promise<any>>;
|
|
13
|
-
export declare const count: RegisteredQuery<"public", any, Promise<any>>;
|
|
14
|
-
export declare const update: RegisteredMutation<"public", any, Promise<any>>;
|
|
15
|
-
export declare const updateMany: RegisteredMutation<"public", any, Promise<any>>;
|
|
16
|
-
declare const deleteMutation: RegisteredMutation<"public", any, Promise<any>>;
|
|
17
|
-
export { deleteMutation as delete };
|
|
18
|
-
export declare const deleteMany: RegisteredMutation<"public", any, Promise<any>>;
|
|
19
|
-
//# sourceMappingURL=adapterTest.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"adapterTest.d.ts","sourceRoot":"","sources":["../../../src/component/adapterTest.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,UAAU,EAAmB,MAAM,qBAAqB,CAAC;AAClE,OAAO,EAGL,kBAAkB,EAClB,eAAe,EAChB,MAAM,eAAe,CAAC;AAOvB,eAAO,MAAM,mBAAmB,EAI1B,GAAG,CAAC;AAEV,eAAO,MAAM,aAAa,GAAI,KAAK,UAAU,wFAKzC,CAAC;AAEL,eAAO,MACL,UAAU,OACV,UAAU,OACV,UAAU,OACV,aAAa,OACb,eAAe,KAMf,CAAC;AAEH,eAAO,MAAM,WAAW,GAAI,MAAM,GAAG;;CASpC,CAAC;AAEF,eAAO,MAAM,SAAS,GAAI,MAAM,GAAG,QAUlC,CAAC;AAEF,eAAO,MAAM,MAAM,EAAE,kBAAkB,CAAC,QAAQ,EAAE,GAAG,EAAE,OAAO,CAAC,GAAG,CAAC,CASlE,CAAC;AAEF,eAAO,MAAM,OAAO,EAAE,eAAe,CAAC,QAAQ,EAAE,GAAG,EAAE,OAAO,CAAC,GAAG,CAAC,CAMhE,CAAC;AAEF,eAAO,MAAM,QAAQ,EAAE,eAAe,CAAC,QAAQ,EAAE,GAAG,EAAE,OAAO,CAAC,GAAG,CAAC,CAMjE,CAAC;AAEF,eAAO,MAAM,KAAK,EAAE,eAAe,CAAC,QAAQ,EAAE,GAAG,EAAE,OAAO,CAAC,GAAG,CAAC,CAK9D,CAAC;AAEF,eAAO,MAAM,MAAM,EAAE,kBAAkB,CAAC,QAAQ,EAAE,GAAG,EAAE,OAAO,CAAC,GAAG,CAAC,CASlE,CAAC;AAEF,eAAO,MAAM,UAAU,EAAE,kBAAkB,CACzC,QAAQ,EACR,GAAG,EACH,OAAO,CAAC,GAAG,CAAC,CAIZ,CAAC;AAEH,QAAA,MAAM,cAAc,EAAE,kBAAkB,CACtC,QAAQ,EACR,GAAG,EACH,OAAO,CAAC,GAAG,CAAC,CAIZ,CAAC;AACH,OAAO,EAAE,cAAc,IAAI,MAAM,EAAE,CAAC;AAEpC,eAAO,MAAM,UAAU,EAAE,kBAAkB,CACzC,QAAQ,EACR,GAAG,EACH,OAAO,CAAC,GAAG,CAAC,CAIZ,CAAC"}
|
|
@@ -1,82 +0,0 @@
|
|
|
1
|
-
import { convexAdapter, BetterAuth, } from "../client";
|
|
2
|
-
import { api, internal } from "./_generated/api";
|
|
3
|
-
import { mutation, query } from "./_generated/server";
|
|
4
|
-
// @ts-expect-error - this is a test
|
|
5
|
-
const authFunctions = internal.adapterTest;
|
|
6
|
-
const publicAuthFunctions = api.adapterTest;
|
|
7
|
-
export const betterAuthComponent = new BetterAuth(api, {
|
|
8
|
-
authFunctions,
|
|
9
|
-
publicAuthFunctions,
|
|
10
|
-
verbose: false,
|
|
11
|
-
});
|
|
12
|
-
export const createAdapter = (ctx) => convexAdapter(ctx, betterAuthComponent, {
|
|
13
|
-
debugLogs: {
|
|
14
|
-
isRunningAdapterTests: true,
|
|
15
|
-
},
|
|
16
|
-
});
|
|
17
|
-
export const { createUser, deleteUser, updateUser, createSession, isAuthenticated, } = betterAuthComponent.createAuthFunctions({
|
|
18
|
-
onCreateUser: async (ctx, args) => {
|
|
19
|
-
// noop
|
|
20
|
-
// not required for the adapter test
|
|
21
|
-
},
|
|
22
|
-
});
|
|
23
|
-
export const deserialize = (data) => {
|
|
24
|
-
const dateStringRegex = /\d{4}-[01]\d-[0-3]\dT[0-2]\d:[0-5]\d:[0-5]\d\.\d+([+-][0-2]\d:[0-5]\d|Z)/;
|
|
25
|
-
return Object.fromEntries(Object.entries(data).map(([key, value]) => [
|
|
26
|
-
key,
|
|
27
|
-
dateStringRegex.test(value) ? new Date(value) : value,
|
|
28
|
-
]));
|
|
29
|
-
};
|
|
30
|
-
export const serialize = (data) => {
|
|
31
|
-
if (!data) {
|
|
32
|
-
return data;
|
|
33
|
-
}
|
|
34
|
-
return Object.fromEntries(Object.entries(data).map(([key, value]) => [
|
|
35
|
-
key,
|
|
36
|
-
value instanceof Date ? value.toISOString() : value,
|
|
37
|
-
]));
|
|
38
|
-
};
|
|
39
|
-
export const create = mutation(async (ctx, args) => {
|
|
40
|
-
const adapter = createAdapter(ctx);
|
|
41
|
-
const result = await adapter({}).create({
|
|
42
|
-
...args,
|
|
43
|
-
data: deserialize(args.data),
|
|
44
|
-
});
|
|
45
|
-
return serialize(result);
|
|
46
|
-
});
|
|
47
|
-
export const findOne = query(async (ctx, args) => {
|
|
48
|
-
const adapter = createAdapter(ctx);
|
|
49
|
-
const result = await adapter({}).findOne(args);
|
|
50
|
-
return serialize(result);
|
|
51
|
-
});
|
|
52
|
-
export const findMany = query(async (ctx, args) => {
|
|
53
|
-
const adapter = createAdapter(ctx);
|
|
54
|
-
const result = await adapter({}).findMany(args);
|
|
55
|
-
return result.map(serialize);
|
|
56
|
-
});
|
|
57
|
-
export const count = query(async (ctx, args) => {
|
|
58
|
-
const adapter = createAdapter(ctx);
|
|
59
|
-
return adapter({}).count(args);
|
|
60
|
-
});
|
|
61
|
-
export const update = mutation(async (ctx, args) => {
|
|
62
|
-
const adapter = createAdapter(ctx);
|
|
63
|
-
const result = await adapter({}).update({
|
|
64
|
-
...args,
|
|
65
|
-
update: deserialize(args.update),
|
|
66
|
-
});
|
|
67
|
-
return serialize(result);
|
|
68
|
-
});
|
|
69
|
-
export const updateMany = mutation(async (ctx, args) => {
|
|
70
|
-
const adapter = createAdapter(ctx);
|
|
71
|
-
return adapter({}).updateMany(args);
|
|
72
|
-
});
|
|
73
|
-
const deleteMutation = mutation(async (ctx, args) => {
|
|
74
|
-
const adapter = createAdapter(ctx);
|
|
75
|
-
await adapter({}).delete(args);
|
|
76
|
-
});
|
|
77
|
-
export { deleteMutation as delete };
|
|
78
|
-
export const deleteMany = mutation(async (ctx, args) => {
|
|
79
|
-
const adapter = createAdapter(ctx);
|
|
80
|
-
return adapter({}).deleteMany(args);
|
|
81
|
-
});
|
|
82
|
-
//# sourceMappingURL=adapterTest.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"adapterTest.js","sourceRoot":"","sources":["../../../src/component/adapterTest.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,aAAa,EAEb,UAAU,GAEX,MAAM,WAAW,CAAC;AACnB,OAAO,EAAE,GAAG,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AACjD,OAAO,EAAc,QAAQ,EAAE,KAAK,EAAE,MAAM,qBAAqB,CAAC;AAQlE,oCAAoC;AACpC,MAAM,aAAa,GAAkB,QAAQ,CAAC,WAAkB,CAAC;AAEjE,MAAM,mBAAmB,GAAwB,GAAG,CAAC,WAAkB,CAAC;AAExE,MAAM,CAAC,MAAM,mBAAmB,GAAG,IAAI,UAAU,CAAC,GAAU,EAAE;IAC5D,aAAa;IACb,mBAAmB;IACnB,OAAO,EAAE,KAAK;CACf,CAAQ,CAAC;AAEV,MAAM,CAAC,MAAM,aAAa,GAAG,CAAC,GAAe,EAAE,EAAE,CAC/C,aAAa,CAAC,GAAG,EAAE,mBAAmB,EAAE;IACtC,SAAS,EAAE;QACT,qBAAqB,EAAE,IAAI;KAC5B;CACF,CAAC,CAAC;AAEL,MAAM,CAAC,MAAM,EACX,UAAU,EACV,U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AC,CAAC,MAAM,CAAC;QACtC,GAAG,IAAI;QACP,MAAM,EAAE,WAAW,CAAC,IAAI,CAAC,MAAM,CAAC;KACjC,CAAC,CAAC;IACH,OAAO,SAAS,CAAC,MAAM,CAAC,CAAC;AAC3B,CAAC,CACF,CAAC;AAEF,MAAM,CAAC,MAAM,UAAU,GAInB,QAAQ,CAAC,KAAK,EAAE,GAA4B,EAAE,IAAS,EAAE,EAAE;IAC7D,MAAM,OAAO,GAAG,aAAa,CAAC,GAAG,CAAC,CAAC;IACnC,OAAO,OAAO,CAAC,EAAE,CAAC,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC;AACtC,CAAC,CAAC,CAAC;AAEH,MAAM,cAAc,GAIhB,QAAQ,CAAC,KAAK,EAAE,GAA4B,EAAE,IAAS,EAAE,EAAE;IAC7D,MAAM,OAAO,GAAG,aAAa,CAAC,GAAG,CAAC,CAAC;IACnC,MAAM,OAAO,CAAC,EAAE,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;AACjC,CAAC,CAAC,CAAC;AACH,OAAO,EAAE,cAAc,IAAI,MAAM,EAAE,CAAC;AAEpC,MAAM,CAAC,MAAM,UAAU,GAInB,QAAQ,CAAC,KAAK,EAAE,GAA4B,EAAE,IAAS,EAAE,EAAE;IAC7D,MAAM,OAAO,GAAG,aAAa,CAAC,GAAG,CAAC,CAAC;IACnC,OAAO,OAAO,CAAC,EAAE,CAAC,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC;AACtC,CAAC,CAAC,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/utils/index.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,UAAU,GAAI,MAAM,MAAM,WAMtC,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/utils/index.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,UAAU,GAAG,CAAC,IAAY,EAAE,EAAE;IACzC,MAAM,KAAK,GAAG,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;IAChC,IAAI,KAAK,KAAK,SAAS,EAAE,CAAC;QACxB,MAAM,IAAI,KAAK,CAAC,kCAAkC,IAAI,IAAI,CAAC,CAAC;IAC9D,CAAC;IACD,OAAO,KAAK,CAAC;AACf,CAAC,CAAC"}
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import { GenericCtx } from "./_generated/server.js";
|
|
2
|
-
import { RegisteredMutation, RegisteredQuery } from "convex/server";
|
|
3
|
-
export declare const betterAuthComponent: any;
|
|
4
|
-
export declare const createAdapter: (ctx: GenericCtx) => (options: import("better-auth").BetterAuthOptions) => import("better-auth").Adapter;
|
|
5
|
-
export declare const createUser: any, deleteUser: any, updateUser: any, createSession: any, isAuthenticated: any;
|
|
6
|
-
export declare const deserialize: (data: any) => {
|
|
7
|
-
[k: string]: unknown;
|
|
8
|
-
};
|
|
9
|
-
export declare const serialize: (data: any) => any;
|
|
10
|
-
export declare const create: RegisteredMutation<"public", any, Promise<any>>;
|
|
11
|
-
export declare const findOne: RegisteredQuery<"public", any, Promise<any>>;
|
|
12
|
-
export declare const findMany: RegisteredQuery<"public", any, Promise<any>>;
|
|
13
|
-
export declare const count: RegisteredQuery<"public", any, Promise<any>>;
|
|
14
|
-
export declare const update: RegisteredMutation<"public", any, Promise<any>>;
|
|
15
|
-
export declare const updateMany: RegisteredMutation<"public", any, Promise<any>>;
|
|
16
|
-
declare const deleteMutation: RegisteredMutation<"public", any, Promise<any>>;
|
|
17
|
-
export { deleteMutation as delete };
|
|
18
|
-
export declare const deleteMany: RegisteredMutation<"public", any, Promise<any>>;
|
|
19
|
-
//# sourceMappingURL=adapterTest.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"adapterTest.d.ts","sourceRoot":"","sources":["../../../src/component/adapterTest.ts"],"names":[],"mappings":"AAOA,OAA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,EACR,GAAG,EACH,OAAO,CAAC,GAAG,CAAC,CAIZ,CAAC"}
|
|
@@ -1,82 +0,0 @@
|
|
|
1
|
-
import { convexAdapter, BetterAuth, } from "../client/index.js";
|
|
2
|
-
import { api, internal } from "./_generated/api.js";
|
|
3
|
-
import { mutation, query } from "./_generated/server.js";
|
|
4
|
-
// @ts-expect-error - this is a test
|
|
5
|
-
const authFunctions = internal.adapterTest;
|
|
6
|
-
const publicAuthFunctions = api.adapterTest;
|
|
7
|
-
export const betterAuthComponent = new BetterAuth(api, {
|
|
8
|
-
authFunctions,
|
|
9
|
-
publicAuthFunctions,
|
|
10
|
-
verbose: false,
|
|
11
|
-
});
|
|
12
|
-
export const createAdapter = (ctx) => convexAdapter(ctx, betterAuthComponent, {
|
|
13
|
-
debugLogs: {
|
|
14
|
-
isRunningAdapterTests: true,
|
|
15
|
-
},
|
|
16
|
-
});
|
|
17
|
-
export const { createUser, deleteUser, updateUser, createSession, isAuthenticated, } = betterAuthComponent.createAuthFunctions({
|
|
18
|
-
onCreateUser: async (ctx, args) => {
|
|
19
|
-
// noop
|
|
20
|
-
// not required for the adapter test
|
|
21
|
-
},
|
|
22
|
-
});
|
|
23
|
-
export const deserialize = (data) => {
|
|
24
|
-
const dateStringRegex = /\d{4}-[01]\d-[0-3]\dT[0-2]\d:[0-5]\d:[0-5]\d\.\d+([+-][0-2]\d:[0-5]\d|Z)/;
|
|
25
|
-
return Object.fromEntries(Object.entries(data).map(([key, value]) => [
|
|
26
|
-
key,
|
|
27
|
-
dateStringRegex.test(value) ? new Date(value) : value,
|
|
28
|
-
]));
|
|
29
|
-
};
|
|
30
|
-
export const serialize = (data) => {
|
|
31
|
-
if (!data) {
|
|
32
|
-
return data;
|
|
33
|
-
}
|
|
34
|
-
return Object.fromEntries(Object.entries(data).map(([key, value]) => [
|
|
35
|
-
key,
|
|
36
|
-
value instanceof Date ? value.toISOString() : value,
|
|
37
|
-
]));
|
|
38
|
-
};
|
|
39
|
-
export const create = mutation(async (ctx, args) => {
|
|
40
|
-
const adapter = createAdapter(ctx);
|
|
41
|
-
const result = await adapter({}).create({
|
|
42
|
-
...args,
|
|
43
|
-
data: deserialize(args.data),
|
|
44
|
-
});
|
|
45
|
-
return serialize(result);
|
|
46
|
-
});
|
|
47
|
-
export const findOne = query(async (ctx, args) => {
|
|
48
|
-
const adapter = createAdapter(ctx);
|
|
49
|
-
const result = await adapter({}).findOne(args);
|
|
50
|
-
return serialize(result);
|
|
51
|
-
});
|
|
52
|
-
export const findMany = query(async (ctx, args) => {
|
|
53
|
-
const adapter = createAdapter(ctx);
|
|
54
|
-
const result = await adapter({}).findMany(args);
|
|
55
|
-
return result.map(serialize);
|
|
56
|
-
});
|
|
57
|
-
export const count = query(async (ctx, args) => {
|
|
58
|
-
const adapter = createAdapter(ctx);
|
|
59
|
-
return adapter({}).count(args);
|
|
60
|
-
});
|
|
61
|
-
export const update = mutation(async (ctx, args) => {
|
|
62
|
-
const adapter = createAdapter(ctx);
|
|
63
|
-
const result = await adapter({}).update({
|
|
64
|
-
...args,
|
|
65
|
-
update: deserialize(args.update),
|
|
66
|
-
});
|
|
67
|
-
return serialize(result);
|
|
68
|
-
});
|
|
69
|
-
export const updateMany = mutation(async (ctx, args) => {
|
|
70
|
-
const adapter = createAdapter(ctx);
|
|
71
|
-
return adapter({}).updateMany(args);
|
|
72
|
-
});
|
|
73
|
-
const deleteMutation = mutation(async (ctx, args) => {
|
|
74
|
-
const adapter = createAdapter(ctx);
|
|
75
|
-
await adapter({}).delete(args);
|
|
76
|
-
});
|
|
77
|
-
export { deleteMutation as delete };
|
|
78
|
-
export const deleteMany = mutation(async (ctx, args) => {
|
|
79
|
-
const adapter = createAdapter(ctx);
|
|
80
|
-
return adapter({}).deleteMany(args);
|
|
81
|
-
});
|
|
82
|
-
//# sourceMappingURL=adapterTest.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"adapterTest.js","sourceRoot":"","sources":["../../../src/component/adapterTest.ts"],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nC,MAAM,OAAO,CAAC,EAAE,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;AACjC,CAAC,CAAC,CAAC;AACH,OAAO,EAAE,cAAc,IAAI,MAAM,EAAE,CAAC;AAEpC,MAAM,CAAC,MAAM,UAAU,GAInB,QAAQ,CAAC,KAAK,EAAE,GAA4B,EAAE,IAAS,EAAE,EAAE;IAC7D,MAAM,OAAO,GAAG,aAAa,CAAC,GAAG,CAAC,CAAC;IACnC,OAAO,OAAO,CAAC,EAAE,CAAC,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC;AACtC,CAAC,CAAC,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/utils/index.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,UAAU,GAAI,MAAM,MAAM,WAMtC,CAAC"}
|
package/dist/esm/utils/index.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/utils/index.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,UAAU,GAAG,CAAC,IAAY,EAAE,EAAE;IACzC,MAAM,KAAK,GAAG,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;IAChC,IAAI,KAAK,KAAK,SAAS,EAAE,CAAC;QACxB,MAAM,IAAI,KAAK,CAAC,kCAAkC,IAAI,IAAI,CAAC,CAAC;IAC9D,CAAC;IACD,OAAO,KAAK,CAAC;AACf,CAAC,CAAC"}
|