@convex-dev/better-auth 0.6.2 → 0.7.0-alpha.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/README.md +8 -2
- package/dist/commonjs/client/adapter.d.ts.map +1 -1
- package/dist/commonjs/client/adapter.js +27 -9
- package/dist/commonjs/client/adapter.js.map +1 -1
- package/dist/commonjs/client/cors.d.ts +9 -4
- package/dist/commonjs/client/cors.d.ts.map +1 -1
- package/dist/commonjs/client/cors.js +44 -28
- package/dist/commonjs/client/cors.js.map +1 -1
- package/dist/commonjs/client/index.d.ts +1 -2
- package/dist/commonjs/client/index.d.ts.map +1 -1
- package/dist/commonjs/client/index.js +58 -61
- package/dist/commonjs/client/index.js.map +1 -1
- package/dist/commonjs/component/lib.d.ts +58 -0
- package/dist/commonjs/component/lib.d.ts.map +1 -1
- package/dist/commonjs/component/lib.js +28 -0
- package/dist/commonjs/component/lib.js.map +1 -1
- package/dist/commonjs/component/schema.d.ts +2 -0
- package/dist/commonjs/component/schema.d.ts.map +1 -1
- package/dist/commonjs/component/schema.js +3 -1
- package/dist/commonjs/component/schema.js.map +1 -1
- package/dist/commonjs/component/util.d.ts +6 -0
- 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 +3 -2
- package/dist/commonjs/nextjs/index.js.map +1 -1
- package/dist/commonjs/plugins/convex/index.d.ts +111 -2
- package/dist/commonjs/plugins/convex/index.d.ts.map +1 -1
- package/dist/commonjs/plugins/convex/index.js +66 -5
- package/dist/commonjs/plugins/convex/index.js.map +1 -1
- package/dist/commonjs/plugins/cross-domain/index.d.ts.map +1 -1
- package/dist/commonjs/plugins/cross-domain/index.js +2 -12
- package/dist/commonjs/plugins/cross-domain/index.js.map +1 -1
- package/dist/commonjs/react-start/index.d.ts.map +1 -1
- package/dist/commonjs/react-start/index.js +2 -2
- package/dist/commonjs/react-start/index.js.map +1 -1
- package/dist/esm/client/adapter.d.ts.map +1 -1
- package/dist/esm/client/adapter.js +27 -9
- package/dist/esm/client/adapter.js.map +1 -1
- package/dist/esm/client/cors.d.ts +9 -4
- package/dist/esm/client/cors.d.ts.map +1 -1
- package/dist/esm/client/cors.js +44 -28
- package/dist/esm/client/cors.js.map +1 -1
- package/dist/esm/client/index.d.ts +1 -2
- package/dist/esm/client/index.d.ts.map +1 -1
- package/dist/esm/client/index.js +58 -61
- package/dist/esm/client/index.js.map +1 -1
- package/dist/esm/component/lib.d.ts +58 -0
- package/dist/esm/component/lib.d.ts.map +1 -1
- package/dist/esm/component/lib.js +28 -0
- package/dist/esm/component/lib.js.map +1 -1
- package/dist/esm/component/schema.d.ts +2 -0
- package/dist/esm/component/schema.d.ts.map +1 -1
- package/dist/esm/component/schema.js +3 -1
- package/dist/esm/component/schema.js.map +1 -1
- package/dist/esm/component/util.d.ts +6 -0
- 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 +3 -2
- package/dist/esm/nextjs/index.js.map +1 -1
- package/dist/esm/plugins/convex/index.d.ts +111 -2
- package/dist/esm/plugins/convex/index.d.ts.map +1 -1
- package/dist/esm/plugins/convex/index.js +66 -5
- package/dist/esm/plugins/convex/index.js.map +1 -1
- package/dist/esm/plugins/cross-domain/index.d.ts.map +1 -1
- package/dist/esm/plugins/cross-domain/index.js +2 -12
- package/dist/esm/plugins/cross-domain/index.js.map +1 -1
- package/dist/esm/react-start/index.d.ts.map +1 -1
- package/dist/esm/react-start/index.js +2 -2
- package/dist/esm/react-start/index.js.map +1 -1
- package/package.json +1 -1
- package/src/client/adapter.ts +36 -11
- package/src/client/cors.ts +60 -38
- package/src/client/index.ts +66 -72
- package/src/component/_generated/api.d.ts +12 -0
- package/src/component/lib.ts +32 -0
- package/src/component/schema.ts +3 -1
- package/src/nextjs/index.ts +3 -2
- package/src/plugins/convex/index.ts +79 -11
- package/src/plugins/cross-domain/index.ts +2 -12
- package/src/react-start/index.ts +2 -2
- package/src/util.ts +7 -0
- package/dist/commonjs/component/adapterTest.d.ts +0 -15
- package/dist/commonjs/component/adapterTest.d.ts.map +0 -1
- package/dist/commonjs/component/adapterTest.js +0 -63
- 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 -21
- package/dist/esm/component/adapterTest.d.ts.map +0 -1
- package/dist/esm/component/adapterTest.js +0 -73
- 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
|
@@ -1,8 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
createAuthMiddleware,
|
|
3
|
-
getSession,
|
|
4
|
-
sessionMiddleware,
|
|
5
|
-
} from "better-auth/api";
|
|
1
|
+
import { createAuthMiddleware, sessionMiddleware } from "better-auth/api";
|
|
6
2
|
import {
|
|
7
3
|
BetterAuthPlugin,
|
|
8
4
|
createAuthEndpoint,
|
|
@@ -14,10 +10,18 @@ import {
|
|
|
14
10
|
import { omit } from "convex-helpers";
|
|
15
11
|
import { z } from "zod";
|
|
16
12
|
|
|
17
|
-
const JWT_COOKIE_NAME = "convex_jwt";
|
|
13
|
+
export const JWT_COOKIE_NAME = "convex_jwt";
|
|
18
14
|
|
|
19
|
-
export const convex = (
|
|
20
|
-
|
|
15
|
+
export const convex = (
|
|
16
|
+
opts: {
|
|
17
|
+
jwtExpirationSeconds?: number;
|
|
18
|
+
deleteExpiredSessionsOnLogin?: boolean;
|
|
19
|
+
} = {}
|
|
20
|
+
) => {
|
|
21
|
+
const {
|
|
22
|
+
jwtExpirationSeconds = 60 * 15,
|
|
23
|
+
deleteExpiredSessionsOnLogin = false,
|
|
24
|
+
} = opts;
|
|
21
25
|
const customSession = customSessionPlugin(async ({ user, session }) => {
|
|
22
26
|
const { userId, ...userData } = omit(user, ["id"]) as typeof user & {
|
|
23
27
|
userId: string;
|
|
@@ -54,8 +58,8 @@ export const convex = (opts: { jwtExpirationSeconds?: number } = {}) => {
|
|
|
54
58
|
},
|
|
55
59
|
});
|
|
56
60
|
// Bearer plugin converts the session token to a cookie
|
|
57
|
-
// for cross domain social login after code verification,
|
|
58
|
-
// the headers() helper to work.
|
|
61
|
+
// for cross domain social login after code verification,
|
|
62
|
+
// and is required for the headers() helper to work.
|
|
59
63
|
const bearer = bearerPlugin();
|
|
60
64
|
const schema = {
|
|
61
65
|
user: {
|
|
@@ -69,6 +73,70 @@ export const convex = (opts: { jwtExpirationSeconds?: number } = {}) => {
|
|
|
69
73
|
before: [...bearer.hooks.before],
|
|
70
74
|
after: [
|
|
71
75
|
...oidcProvider.hooks.after,
|
|
76
|
+
{
|
|
77
|
+
matcher: (ctx) => {
|
|
78
|
+
return (
|
|
79
|
+
deleteExpiredSessionsOnLogin &&
|
|
80
|
+
(ctx.path?.startsWith("/sign-in") ||
|
|
81
|
+
ctx.path?.startsWith("/callback"))
|
|
82
|
+
);
|
|
83
|
+
},
|
|
84
|
+
handler: createAuthMiddleware(async (ctx) => {
|
|
85
|
+
// Delete expired sessions at login
|
|
86
|
+
const userId = ctx.context.newSession?.user.id;
|
|
87
|
+
if (!userId) {
|
|
88
|
+
return;
|
|
89
|
+
}
|
|
90
|
+
await ctx.context.adapter.deleteMany({
|
|
91
|
+
model: "session",
|
|
92
|
+
where: [
|
|
93
|
+
{
|
|
94
|
+
field: "userId",
|
|
95
|
+
operator: "eq",
|
|
96
|
+
value: userId,
|
|
97
|
+
connector: "AND",
|
|
98
|
+
},
|
|
99
|
+
{
|
|
100
|
+
operator: "lte",
|
|
101
|
+
field: "expiresAt",
|
|
102
|
+
value: new Date().getTime(),
|
|
103
|
+
},
|
|
104
|
+
],
|
|
105
|
+
});
|
|
106
|
+
}),
|
|
107
|
+
},
|
|
108
|
+
{
|
|
109
|
+
matcher: (ctx) => {
|
|
110
|
+
return (
|
|
111
|
+
ctx.path?.startsWith("/sign-in") ||
|
|
112
|
+
ctx.path?.startsWith("/callback")
|
|
113
|
+
);
|
|
114
|
+
},
|
|
115
|
+
handler: createAuthMiddleware(async (ctx) => {
|
|
116
|
+
// Set jwt cookie at login for ssa
|
|
117
|
+
const cookie = ctx.context.responseHeaders?.get("set-cookie") ?? "";
|
|
118
|
+
if (!cookie) {
|
|
119
|
+
return;
|
|
120
|
+
}
|
|
121
|
+
try {
|
|
122
|
+
const { token } = await jwt.endpoints.getToken({
|
|
123
|
+
...ctx,
|
|
124
|
+
method: "GET",
|
|
125
|
+
headers: {
|
|
126
|
+
cookie,
|
|
127
|
+
},
|
|
128
|
+
returnHeaders: false,
|
|
129
|
+
});
|
|
130
|
+
const jwtCookie = ctx.context.createAuthCookie(JWT_COOKIE_NAME, {
|
|
131
|
+
maxAge: jwtExpirationSeconds,
|
|
132
|
+
});
|
|
133
|
+
ctx.setCookie(jwtCookie.name, token, jwtCookie.attributes);
|
|
134
|
+
} catch (err) {
|
|
135
|
+
// no-op, some sign-in calls (eg., when redirecting to 2fa)
|
|
136
|
+
// 401 here
|
|
137
|
+
}
|
|
138
|
+
}),
|
|
139
|
+
},
|
|
72
140
|
{
|
|
73
141
|
matcher: (ctx) => {
|
|
74
142
|
return ctx.path?.startsWith("/sign-out");
|
|
@@ -137,7 +205,7 @@ export const convex = (opts: { jwtExpirationSeconds?: number } = {}) => {
|
|
|
137
205
|
});
|
|
138
206
|
return response;
|
|
139
207
|
}
|
|
140
|
-
)
|
|
208
|
+
),
|
|
141
209
|
getOpenIdConfig: createAuthEndpoint(
|
|
142
210
|
"/convex/.well-known/openid-configuration",
|
|
143
211
|
{
|
|
@@ -52,22 +52,12 @@ export const crossDomain = ({ siteUrl }: { siteUrl: string }) => {
|
|
|
52
52
|
};
|
|
53
53
|
}),
|
|
54
54
|
},
|
|
55
|
-
{
|
|
56
|
-
matcher: (ctx) => {
|
|
57
|
-
return ctx.method === "GET" && ctx.path.startsWith("/verify-email");
|
|
58
|
-
},
|
|
59
|
-
handler: createAuthMiddleware(async (ctx) => {
|
|
60
|
-
if (ctx.query?.callbackURL) {
|
|
61
|
-
ctx.query.callbackURL = rewriteCallbackURL(ctx.query.callbackURL);
|
|
62
|
-
}
|
|
63
|
-
return { context: ctx };
|
|
64
|
-
}),
|
|
65
|
-
},
|
|
66
55
|
{
|
|
67
56
|
matcher: (ctx) => {
|
|
68
57
|
return (
|
|
69
|
-
|
|
58
|
+
ctx.path.startsWith("/link-social") ||
|
|
70
59
|
ctx.path.startsWith("/send-verification-email") ||
|
|
60
|
+
ctx.path.startsWith("/verify-email") ||
|
|
71
61
|
ctx.path.startsWith("/sign-in/email") ||
|
|
72
62
|
ctx.path.startsWith("/sign-in/social") ||
|
|
73
63
|
ctx.path.startsWith("/sign-in/magic-link") ||
|
package/src/react-start/index.ts
CHANGED
|
@@ -2,13 +2,14 @@ import { betterAuth } from "better-auth";
|
|
|
2
2
|
import { createCookieGetter } from "better-auth/cookies";
|
|
3
3
|
import { betterFetch } from "@better-fetch/fetch";
|
|
4
4
|
import { GenericActionCtx } from "convex/server";
|
|
5
|
+
import { JWT_COOKIE_NAME } from "../plugins/convex";
|
|
5
6
|
|
|
6
7
|
export const getCookieName = async (
|
|
7
8
|
createAuth: (ctx: GenericActionCtx<any>) => ReturnType<typeof betterAuth>
|
|
8
9
|
) => {
|
|
9
10
|
const auth = createAuth({} as any);
|
|
10
11
|
const createCookie = createCookieGetter(auth.options);
|
|
11
|
-
const cookie = createCookie(
|
|
12
|
+
const cookie = createCookie(JWT_COOKIE_NAME);
|
|
12
13
|
return cookie.name;
|
|
13
14
|
};
|
|
14
15
|
|
|
@@ -30,7 +31,6 @@ export const fetchSession = async <
|
|
|
30
31
|
baseURL,
|
|
31
32
|
headers: {
|
|
32
33
|
cookie: request.headers.get("cookie") ?? "",
|
|
33
|
-
origin: baseURL,
|
|
34
34
|
},
|
|
35
35
|
}
|
|
36
36
|
);
|
package/src/util.ts
ADDED
|
@@ -1,15 +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 create: RegisteredMutation<"public", any, Promise<any>>;
|
|
7
|
-
export declare const findOne: RegisteredQuery<"public", any, Promise<any>>;
|
|
8
|
-
export declare const findMany: RegisteredQuery<"public", any, Promise<any>>;
|
|
9
|
-
export declare const count: RegisteredQuery<"public", any, Promise<any>>;
|
|
10
|
-
export declare const update: RegisteredMutation<"public", any, Promise<any>>;
|
|
11
|
-
export declare const updateMany: RegisteredMutation<"public", any, Promise<any>>;
|
|
12
|
-
declare const deleteMutation: RegisteredMutation<"public", any, Promise<any>>;
|
|
13
|
-
export { deleteMutation as delete };
|
|
14
|
-
export declare const deleteMany: RegisteredMutation<"public", any, Promise<any>>;
|
|
15
|
-
//# 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,wFACJ,CAAC;AAE1C,eAAO,MACL,UAAU,OACV,UAAU,OACV,UAAU,OACV,aAAa,OACb,eAAe,KAKf,CAAC;AAaH,eAAO,MAAM,MAAM,EAAE,kBAAkB,CAAC,QAAQ,EAAE,GAAG,EAAE,OAAO,CAAC,GAAG,CAAC,CAUlE,CAAC;AAEF,eAAO,MAAM,OAAO,EAAE,eAAe,CAAC,QAAQ,EAAE,GAAG,EAAE,OAAO,CAAC,GAAG,CAAC,CAKhE,CAAC;AAEF,eAAO,MAAM,QAAQ,EAAE,eAAe,CAAC,QAAQ,EAAE,GAAG,EAAE,OAAO,CAAC,GAAG,CAAC,CAKjE,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,CAKlE,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,63 +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
|
-
export const { createUser, deleteUser, updateUser, createSession, isAuthenticated, } = betterAuthComponent.createAuthFunctions({
|
|
14
|
-
onCreateUser: async () => {
|
|
15
|
-
return "foo";
|
|
16
|
-
},
|
|
17
|
-
});
|
|
18
|
-
const mapData = (data) => {
|
|
19
|
-
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)/;
|
|
20
|
-
return Object.fromEntries(Object.entries(data).map(([key, value]) => [
|
|
21
|
-
key,
|
|
22
|
-
dateStringRegex.test(value) ? new Date(value) : value,
|
|
23
|
-
]));
|
|
24
|
-
};
|
|
25
|
-
export const create = mutation(async (ctx, args) => {
|
|
26
|
-
const adapter = createAdapter(ctx);
|
|
27
|
-
const result = await adapter({}).create({
|
|
28
|
-
...args,
|
|
29
|
-
data: mapData(args.data),
|
|
30
|
-
});
|
|
31
|
-
console.log("result from create", result);
|
|
32
|
-
return result;
|
|
33
|
-
});
|
|
34
|
-
export const findOne = query(async (ctx, args) => {
|
|
35
|
-
const adapter = createAdapter(ctx);
|
|
36
|
-
return adapter({}).findOne(args);
|
|
37
|
-
});
|
|
38
|
-
export const findMany = query(async (ctx, args) => {
|
|
39
|
-
const adapter = createAdapter(ctx);
|
|
40
|
-
return adapter({}).findMany(args);
|
|
41
|
-
});
|
|
42
|
-
export const count = query(async (ctx, args) => {
|
|
43
|
-
const adapter = createAdapter(ctx);
|
|
44
|
-
return adapter({}).count(args);
|
|
45
|
-
});
|
|
46
|
-
export const update = mutation(async (ctx, args) => {
|
|
47
|
-
const adapter = createAdapter(ctx);
|
|
48
|
-
return adapter({}).update(args);
|
|
49
|
-
});
|
|
50
|
-
export const updateMany = mutation(async (ctx, args) => {
|
|
51
|
-
const adapter = createAdapter(ctx);
|
|
52
|
-
return adapter({}).updateMany(args);
|
|
53
|
-
});
|
|
54
|
-
const deleteMutation = mutation(async (ctx, args) => {
|
|
55
|
-
const adapter = createAdapter(ctx);
|
|
56
|
-
return adapter({}).delete(args);
|
|
57
|
-
});
|
|
58
|
-
export { deleteMutation as delete };
|
|
59
|
-
export const deleteMany = mutation(async (ctx, args) => {
|
|
60
|
-
const adapter = createAdapter(ctx);
|
|
61
|
-
return adapter({}).deleteMany(args);
|
|
62
|
-
});
|
|
63
|
-
//# 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,CAAC,CAAC;AAE1C,MAAM,CAAC,MAAM,EACX,UAAU,EACV,UAAU,EACV,UAAU,EACV,aAAa,EACb,eAAe,GAChB,GAAG,mBAAmB,CAAC,mBAAmB,CAAC;IAC1C,YAAY,EAAE,KAAK,IAAI,EAAE;QACvB,OAAO,KAAK,CAAC;IACf,CAAC;CACF,CAAC,CAAC;AAEH,MAAM,OAAO,GAAG,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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,21 +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) => {
|
|
10
|
-
[k: string]: unknown;
|
|
11
|
-
};
|
|
12
|
-
export declare const create: RegisteredMutation<"public", any, Promise<any>>;
|
|
13
|
-
export declare const findOne: RegisteredQuery<"public", any, Promise<any>>;
|
|
14
|
-
export declare const findMany: RegisteredQuery<"public", any, Promise<any>>;
|
|
15
|
-
export declare const count: RegisteredQuery<"public", any, Promise<any>>;
|
|
16
|
-
export declare const update: RegisteredMutation<"public", any, Promise<any>>;
|
|
17
|
-
export declare const updateMany: RegisteredMutation<"public", any, Promise<any>>;
|
|
18
|
-
declare const deleteMutation: RegisteredMutation<"public", any, Promise<any>>;
|
|
19
|
-
export { deleteMutation as delete };
|
|
20
|
-
export declare const deleteMany: RegisteredMutation<"public", any, Promise<any>>;
|
|
21
|
-
//# 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,wFACJ,CAAC;AAE1C,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;;CAMhC,CAAC;AAEJ,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,73 +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
|
-
export const { createUser, deleteUser, updateUser, createSession, isAuthenticated, } = betterAuthComponent.createAuthFunctions({
|
|
14
|
-
onCreateUser: async (ctx, args) => {
|
|
15
|
-
// noop
|
|
16
|
-
// not required for the adapter test
|
|
17
|
-
},
|
|
18
|
-
});
|
|
19
|
-
export const deserialize = (data) => {
|
|
20
|
-
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)/;
|
|
21
|
-
return Object.fromEntries(Object.entries(data).map(([key, value]) => [
|
|
22
|
-
key,
|
|
23
|
-
dateStringRegex.test(value) ? new Date(value) : value,
|
|
24
|
-
]));
|
|
25
|
-
};
|
|
26
|
-
export const serialize = (data) => Object.fromEntries(Object.entries(data).map(([key, value]) => [
|
|
27
|
-
key,
|
|
28
|
-
value instanceof Date ? value.toISOString() : value,
|
|
29
|
-
]));
|
|
30
|
-
export const create = mutation(async (ctx, args) => {
|
|
31
|
-
const adapter = createAdapter(ctx);
|
|
32
|
-
const result = await adapter({}).create({
|
|
33
|
-
...args,
|
|
34
|
-
data: deserialize(args.data),
|
|
35
|
-
});
|
|
36
|
-
return serialize(result);
|
|
37
|
-
});
|
|
38
|
-
export const findOne = query(async (ctx, args) => {
|
|
39
|
-
const adapter = createAdapter(ctx);
|
|
40
|
-
const result = await adapter({}).findOne(args);
|
|
41
|
-
return serialize(result);
|
|
42
|
-
});
|
|
43
|
-
export const findMany = query(async (ctx, args) => {
|
|
44
|
-
const adapter = createAdapter(ctx);
|
|
45
|
-
const result = await adapter({}).findMany(args);
|
|
46
|
-
return result.map(serialize);
|
|
47
|
-
});
|
|
48
|
-
export const count = query(async (ctx, args) => {
|
|
49
|
-
const adapter = createAdapter(ctx);
|
|
50
|
-
return adapter({}).count(args);
|
|
51
|
-
});
|
|
52
|
-
export const update = mutation(async (ctx, args) => {
|
|
53
|
-
const adapter = createAdapter(ctx);
|
|
54
|
-
const result = await adapter({}).update({
|
|
55
|
-
...args,
|
|
56
|
-
update: deserialize(args.update),
|
|
57
|
-
});
|
|
58
|
-
return serialize(result);
|
|
59
|
-
});
|
|
60
|
-
export const updateMany = mutation(async (ctx, args) => {
|
|
61
|
-
const adapter = createAdapter(ctx);
|
|
62
|
-
return adapter({}).updateMany(args);
|
|
63
|
-
});
|
|
64
|
-
const deleteMutation = mutation(async (ctx, args) => {
|
|
65
|
-
const adapter = createAdapter(ctx);
|
|
66
|
-
return adapter({}).delete(args);
|
|
67
|
-
});
|
|
68
|
-
export { deleteMutation as delete };
|
|
69
|
-
export const deleteMany = mutation(async (ctx, args) => {
|
|
70
|
-
const adapter = createAdapter(ctx);
|
|
71
|
-
return adapter({}).deleteMany(args);
|
|
72
|
-
});
|
|
73
|
-
//# 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,CAAC,CAAC;AAE1C,MAAM,CAAC,MAAM,EACX,UAAU,EACV,UAAU,EACV,UAAU,EACV,aAAa,EACb,eAAe,GAChB,GAAG,mBAAmB,CAAC,mBAAmB,CAAC;IAC1C,YAAY,EAAE,KAAK,EAAE,GAAe,EAAE,IAAS,EAAE,EAAE;QACjD,OAAO;QACP,oCAAoC;IACtC,CAAC;CACF,CAAC,CAAC;AAEH,MAAM,CAAC,MAAM,WAAW,GAAG,CAAC,IAAS,EAAE,EAAE;IACvC,MAAM,eAAe,GACnB,0EAA0E,CAAC;IAC7E,OAAO,MAAM,CAAC,WAAW,CACvB,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,GAAG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E,GAA4B,EAAE,IAAS,EAAE,EAAE;IAC7D,MAAM,OAAO,GAAG,aAAa,CAAC,GAAG,CAAC,CAAC;IACnC,OAAO,OAAO,CAAC,EAAE,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;AAClC,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"}
|