@convex-dev/better-auth 0.6.0
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/LICENSE +201 -0
- package/README.md +44 -0
- package/dist/commonjs/client/adapter.d.ts +4 -0
- package/dist/commonjs/client/adapter.d.ts.map +1 -0
- package/dist/commonjs/client/adapter.js +189 -0
- package/dist/commonjs/client/adapter.js.map +1 -0
- package/dist/commonjs/client/cors.d.ts +72 -0
- package/dist/commonjs/client/cors.d.ts.map +1 -0
- package/dist/commonjs/client/cors.js +281 -0
- package/dist/commonjs/client/cors.js.map +1 -0
- package/dist/commonjs/client/index.d.ts +302 -0
- package/dist/commonjs/client/index.d.ts.map +1 -0
- package/dist/commonjs/client/index.js +232 -0
- package/dist/commonjs/client/index.js.map +1 -0
- package/dist/commonjs/client/plugins/index.d.ts +3 -0
- package/dist/commonjs/client/plugins/index.d.ts.map +1 -0
- package/dist/commonjs/client/plugins/index.js +3 -0
- package/dist/commonjs/client/plugins/index.js.map +1 -0
- package/dist/commonjs/component/_generated/api.d.ts +12 -0
- package/dist/commonjs/component/_generated/api.d.ts.map +1 -0
- package/dist/commonjs/component/_generated/api.js +22 -0
- package/dist/commonjs/component/_generated/api.js.map +1 -0
- package/dist/commonjs/component/_generated/server.d.ts +64 -0
- package/dist/commonjs/component/_generated/server.d.ts.map +1 -0
- package/dist/commonjs/component/_generated/server.js +74 -0
- package/dist/commonjs/component/_generated/server.js.map +1 -0
- package/dist/commonjs/component/convex.config.d.ts +3 -0
- package/dist/commonjs/component/convex.config.d.ts.map +1 -0
- package/dist/commonjs/component/convex.config.js +4 -0
- package/dist/commonjs/component/convex.config.js.map +1 -0
- package/dist/commonjs/component/lib.d.ts +584 -0
- package/dist/commonjs/component/lib.d.ts.map +1 -0
- package/dist/commonjs/component/lib.js +323 -0
- package/dist/commonjs/component/lib.js.map +1 -0
- package/dist/commonjs/component/schema.d.ts +116 -0
- package/dist/commonjs/component/schema.d.ts.map +1 -0
- package/dist/commonjs/component/schema.js +68 -0
- package/dist/commonjs/component/schema.js.map +1 -0
- package/dist/commonjs/component/util.d.ts +394 -0
- package/dist/commonjs/component/util.d.ts.map +1 -0
- package/dist/commonjs/component/util.js +4 -0
- package/dist/commonjs/component/util.js.map +1 -0
- package/dist/commonjs/nextjs/index.d.ts +10 -0
- package/dist/commonjs/nextjs/index.d.ts.map +1 -0
- package/dist/commonjs/nextjs/index.js +23 -0
- package/dist/commonjs/nextjs/index.js.map +1 -0
- package/dist/commonjs/package.json +3 -0
- package/dist/commonjs/plugins/convex/client.d.ts +6 -0
- package/dist/commonjs/plugins/convex/client.d.ts.map +1 -0
- package/dist/commonjs/plugins/convex/client.js +7 -0
- package/dist/commonjs/plugins/convex/client.js.map +1 -0
- package/dist/commonjs/plugins/convex/index.d.ts +280 -0
- package/dist/commonjs/plugins/convex/index.d.ts.map +1 -0
- package/dist/commonjs/plugins/convex/index.js +253 -0
- package/dist/commonjs/plugins/convex/index.js.map +1 -0
- package/dist/commonjs/plugins/cross-domain/client.d.ts +123 -0
- package/dist/commonjs/plugins/cross-domain/client.d.ts.map +1 -0
- package/dist/commonjs/plugins/cross-domain/client.js +164 -0
- package/dist/commonjs/plugins/cross-domain/client.js.map +1 -0
- package/dist/commonjs/plugins/cross-domain/index.d.ts +81 -0
- package/dist/commonjs/plugins/cross-domain/index.d.ts.map +1 -0
- package/dist/commonjs/plugins/cross-domain/index.js +135 -0
- package/dist/commonjs/plugins/cross-domain/index.js.map +1 -0
- package/dist/commonjs/plugins/index.d.ts +3 -0
- package/dist/commonjs/plugins/index.d.ts.map +1 -0
- package/dist/commonjs/plugins/index.js +3 -0
- package/dist/commonjs/plugins/index.js.map +1 -0
- package/dist/commonjs/react/client.d.ts +31 -0
- package/dist/commonjs/react/client.d.ts.map +1 -0
- package/dist/commonjs/react/client.js +102 -0
- package/dist/commonjs/react/client.js.map +1 -0
- package/dist/commonjs/react/index.d.ts +9 -0
- package/dist/commonjs/react/index.d.ts.map +1 -0
- package/dist/commonjs/react/index.js +15 -0
- package/dist/commonjs/react/index.js.map +1 -0
- package/dist/commonjs/react-start/index.d.ts +10 -0
- package/dist/commonjs/react-start/index.d.ts.map +1 -0
- package/dist/commonjs/react-start/index.js +32 -0
- package/dist/commonjs/react-start/index.js.map +1 -0
- package/dist/esm/client/adapter.d.ts +4 -0
- package/dist/esm/client/adapter.d.ts.map +1 -0
- package/dist/esm/client/adapter.js +189 -0
- package/dist/esm/client/adapter.js.map +1 -0
- package/dist/esm/client/cors.d.ts +72 -0
- package/dist/esm/client/cors.d.ts.map +1 -0
- package/dist/esm/client/cors.js +281 -0
- package/dist/esm/client/cors.js.map +1 -0
- package/dist/esm/client/index.d.ts +302 -0
- package/dist/esm/client/index.d.ts.map +1 -0
- package/dist/esm/client/index.js +232 -0
- package/dist/esm/client/index.js.map +1 -0
- package/dist/esm/client/plugins/index.d.ts +3 -0
- package/dist/esm/client/plugins/index.d.ts.map +1 -0
- package/dist/esm/client/plugins/index.js +3 -0
- package/dist/esm/client/plugins/index.js.map +1 -0
- package/dist/esm/component/_generated/api.d.ts +12 -0
- package/dist/esm/component/_generated/api.d.ts.map +1 -0
- package/dist/esm/component/_generated/api.js +22 -0
- package/dist/esm/component/_generated/api.js.map +1 -0
- package/dist/esm/component/_generated/server.d.ts +64 -0
- package/dist/esm/component/_generated/server.d.ts.map +1 -0
- package/dist/esm/component/_generated/server.js +74 -0
- package/dist/esm/component/_generated/server.js.map +1 -0
- package/dist/esm/component/convex.config.d.ts +3 -0
- package/dist/esm/component/convex.config.d.ts.map +1 -0
- package/dist/esm/component/convex.config.js +4 -0
- package/dist/esm/component/convex.config.js.map +1 -0
- package/dist/esm/component/lib.d.ts +584 -0
- package/dist/esm/component/lib.d.ts.map +1 -0
- package/dist/esm/component/lib.js +323 -0
- package/dist/esm/component/lib.js.map +1 -0
- package/dist/esm/component/schema.d.ts +116 -0
- package/dist/esm/component/schema.d.ts.map +1 -0
- package/dist/esm/component/schema.js +68 -0
- package/dist/esm/component/schema.js.map +1 -0
- package/dist/esm/component/util.d.ts +394 -0
- package/dist/esm/component/util.d.ts.map +1 -0
- package/dist/esm/component/util.js +4 -0
- package/dist/esm/component/util.js.map +1 -0
- package/dist/esm/nextjs/index.d.ts +10 -0
- package/dist/esm/nextjs/index.d.ts.map +1 -0
- package/dist/esm/nextjs/index.js +23 -0
- package/dist/esm/nextjs/index.js.map +1 -0
- package/dist/esm/package.json +3 -0
- package/dist/esm/plugins/convex/client.d.ts +6 -0
- package/dist/esm/plugins/convex/client.d.ts.map +1 -0
- package/dist/esm/plugins/convex/client.js +7 -0
- package/dist/esm/plugins/convex/client.js.map +1 -0
- package/dist/esm/plugins/convex/index.d.ts +280 -0
- package/dist/esm/plugins/convex/index.d.ts.map +1 -0
- package/dist/esm/plugins/convex/index.js +253 -0
- package/dist/esm/plugins/convex/index.js.map +1 -0
- package/dist/esm/plugins/cross-domain/client.d.ts +123 -0
- package/dist/esm/plugins/cross-domain/client.d.ts.map +1 -0
- package/dist/esm/plugins/cross-domain/client.js +164 -0
- package/dist/esm/plugins/cross-domain/client.js.map +1 -0
- package/dist/esm/plugins/cross-domain/index.d.ts +81 -0
- package/dist/esm/plugins/cross-domain/index.d.ts.map +1 -0
- package/dist/esm/plugins/cross-domain/index.js +135 -0
- package/dist/esm/plugins/cross-domain/index.js.map +1 -0
- package/dist/esm/plugins/index.d.ts +3 -0
- package/dist/esm/plugins/index.d.ts.map +1 -0
- package/dist/esm/plugins/index.js +3 -0
- package/dist/esm/plugins/index.js.map +1 -0
- package/dist/esm/react/client.d.ts +31 -0
- package/dist/esm/react/client.d.ts.map +1 -0
- package/dist/esm/react/client.js +102 -0
- package/dist/esm/react/client.js.map +1 -0
- package/dist/esm/react/index.d.ts +9 -0
- package/dist/esm/react/index.d.ts.map +1 -0
- package/dist/esm/react/index.js +15 -0
- package/dist/esm/react/index.js.map +1 -0
- package/dist/esm/react-start/index.d.ts +10 -0
- package/dist/esm/react-start/index.d.ts.map +1 -0
- package/dist/esm/react-start/index.js +32 -0
- package/dist/esm/react-start/index.js.map +1 -0
- package/package.json +161 -0
- package/plugins/package.json +5 -0
- package/react/package.json +5 -0
- package/src/client/adapter.ts +236 -0
- package/src/client/cors.ts +403 -0
- package/src/client/index.ts +381 -0
- package/src/client/plugins/index.ts +2 -0
- package/src/component/_generated/api.d.ts +313 -0
- package/src/component/_generated/api.js +23 -0
- package/src/component/_generated/dataModel.d.ts +60 -0
- package/src/component/_generated/server.d.ts +149 -0
- package/src/component/_generated/server.js +90 -0
- package/src/component/convex.config.ts +5 -0
- package/src/component/lib.ts +391 -0
- package/src/component/schema.ts +74 -0
- package/src/component/util.ts +4 -0
- package/src/nextjs/index.ts +30 -0
- package/src/plugins/convex/client.ts +9 -0
- package/src/plugins/convex/index.ts +296 -0
- package/src/plugins/cross-domain/client.ts +209 -0
- package/src/plugins/cross-domain/index.ts +156 -0
- package/src/plugins/index.ts +2 -0
- package/src/react/client.tsx +184 -0
- package/src/react/index.tsx +38 -0
- package/src/react-start/index.ts +51 -0
|
@@ -0,0 +1,280 @@
|
|
|
1
|
+
import { getSession } from "better-auth/api";
|
|
2
|
+
export declare const convex: (opts?: {
|
|
3
|
+
jwtExpirationSeconds?: number;
|
|
4
|
+
}) => {
|
|
5
|
+
id: "convex";
|
|
6
|
+
hooks: {
|
|
7
|
+
before: {
|
|
8
|
+
matcher(context: import("better-auth").HookEndpointContext): boolean;
|
|
9
|
+
handler: (inputContext: import("better-call").MiddlewareInputContext<import("better-call").MiddlewareOptions>) => Promise<{
|
|
10
|
+
context: {
|
|
11
|
+
headers: Headers;
|
|
12
|
+
};
|
|
13
|
+
} | undefined>;
|
|
14
|
+
}[];
|
|
15
|
+
after: ({
|
|
16
|
+
matcher(): true;
|
|
17
|
+
handler: (inputContext: import("better-call").MiddlewareInputContext<import("better-call").MiddlewareOptions>) => Promise<Response | undefined>;
|
|
18
|
+
} | {
|
|
19
|
+
matcher: (ctx: import("better-auth").HookEndpointContext) => boolean;
|
|
20
|
+
handler: (inputContext: import("better-call").MiddlewareInputContext<import("better-call").MiddlewareOptions>) => Promise<void>;
|
|
21
|
+
})[];
|
|
22
|
+
};
|
|
23
|
+
endpoints: {
|
|
24
|
+
getSession: ReturnType<typeof getSession>;
|
|
25
|
+
getOpenIdConfig: {
|
|
26
|
+
<AsResponse extends boolean = false, ReturnHeaders extends boolean = false>(inputCtx_0?: ({
|
|
27
|
+
body?: undefined;
|
|
28
|
+
} & {
|
|
29
|
+
method?: "GET" | undefined;
|
|
30
|
+
} & {
|
|
31
|
+
query?: Record<string, any> | undefined;
|
|
32
|
+
} & {
|
|
33
|
+
params?: Record<string, any>;
|
|
34
|
+
} & {
|
|
35
|
+
request?: Request;
|
|
36
|
+
} & {
|
|
37
|
+
headers?: HeadersInit;
|
|
38
|
+
} & {
|
|
39
|
+
asResponse?: boolean;
|
|
40
|
+
returnHeaders?: boolean;
|
|
41
|
+
use?: import("better-call").Middleware[];
|
|
42
|
+
path?: string;
|
|
43
|
+
} & {
|
|
44
|
+
asResponse?: AsResponse | undefined;
|
|
45
|
+
returnHeaders?: ReturnHeaders | undefined;
|
|
46
|
+
}) | undefined): Promise<[AsResponse] extends [true] ? Response : [ReturnHeaders] extends [true] ? {
|
|
47
|
+
headers: Headers;
|
|
48
|
+
response: import("better-auth/plugins").OIDCMetadata;
|
|
49
|
+
} : import("better-auth/plugins").OIDCMetadata>;
|
|
50
|
+
options: {
|
|
51
|
+
method: "GET";
|
|
52
|
+
metadata: {
|
|
53
|
+
isAction: boolean;
|
|
54
|
+
};
|
|
55
|
+
} & {
|
|
56
|
+
use: any[];
|
|
57
|
+
};
|
|
58
|
+
path: "/convex/.well-known/openid-configuration";
|
|
59
|
+
};
|
|
60
|
+
getJwks: {
|
|
61
|
+
<AsResponse extends boolean = false, ReturnHeaders extends boolean = false>(inputCtx_0?: ({
|
|
62
|
+
body?: undefined;
|
|
63
|
+
} & {
|
|
64
|
+
method?: "GET" | undefined;
|
|
65
|
+
} & {
|
|
66
|
+
query?: Record<string, any> | undefined;
|
|
67
|
+
} & {
|
|
68
|
+
params?: Record<string, any>;
|
|
69
|
+
} & {
|
|
70
|
+
request?: Request;
|
|
71
|
+
} & {
|
|
72
|
+
headers?: HeadersInit;
|
|
73
|
+
} & {
|
|
74
|
+
asResponse?: boolean;
|
|
75
|
+
returnHeaders?: boolean;
|
|
76
|
+
use?: import("better-call").Middleware[];
|
|
77
|
+
path?: string;
|
|
78
|
+
} & {
|
|
79
|
+
asResponse?: AsResponse | undefined;
|
|
80
|
+
returnHeaders?: ReturnHeaders | undefined;
|
|
81
|
+
}) | undefined): Promise<[AsResponse] extends [true] ? Response : [ReturnHeaders] extends [true] ? {
|
|
82
|
+
headers: Headers;
|
|
83
|
+
response: {
|
|
84
|
+
keys: any[];
|
|
85
|
+
};
|
|
86
|
+
} : {
|
|
87
|
+
keys: any[];
|
|
88
|
+
}>;
|
|
89
|
+
options: {
|
|
90
|
+
method: "GET";
|
|
91
|
+
metadata: {
|
|
92
|
+
openapi: {
|
|
93
|
+
description: string;
|
|
94
|
+
responses: {
|
|
95
|
+
"200": {
|
|
96
|
+
description: string;
|
|
97
|
+
content: {
|
|
98
|
+
"application/json": {
|
|
99
|
+
schema: {
|
|
100
|
+
type: "object";
|
|
101
|
+
properties: {
|
|
102
|
+
keys: {
|
|
103
|
+
type: string;
|
|
104
|
+
description: string;
|
|
105
|
+
items: {
|
|
106
|
+
type: string;
|
|
107
|
+
properties: {
|
|
108
|
+
kid: {
|
|
109
|
+
type: string;
|
|
110
|
+
description: string;
|
|
111
|
+
};
|
|
112
|
+
kty: {
|
|
113
|
+
type: string;
|
|
114
|
+
description: string;
|
|
115
|
+
};
|
|
116
|
+
alg: {
|
|
117
|
+
type: string;
|
|
118
|
+
description: string;
|
|
119
|
+
};
|
|
120
|
+
use: {
|
|
121
|
+
type: string;
|
|
122
|
+
description: string;
|
|
123
|
+
enum: string[];
|
|
124
|
+
nullable: boolean;
|
|
125
|
+
};
|
|
126
|
+
n: {
|
|
127
|
+
type: string;
|
|
128
|
+
description: string;
|
|
129
|
+
nullable: boolean;
|
|
130
|
+
};
|
|
131
|
+
e: {
|
|
132
|
+
type: string;
|
|
133
|
+
description: string;
|
|
134
|
+
nullable: boolean;
|
|
135
|
+
};
|
|
136
|
+
crv: {
|
|
137
|
+
type: string;
|
|
138
|
+
description: string;
|
|
139
|
+
nullable: boolean;
|
|
140
|
+
};
|
|
141
|
+
x: {
|
|
142
|
+
type: string;
|
|
143
|
+
description: string;
|
|
144
|
+
nullable: boolean;
|
|
145
|
+
};
|
|
146
|
+
y: {
|
|
147
|
+
type: string;
|
|
148
|
+
description: string;
|
|
149
|
+
nullable: boolean;
|
|
150
|
+
};
|
|
151
|
+
};
|
|
152
|
+
required: string[];
|
|
153
|
+
};
|
|
154
|
+
};
|
|
155
|
+
};
|
|
156
|
+
required: string[];
|
|
157
|
+
};
|
|
158
|
+
};
|
|
159
|
+
};
|
|
160
|
+
};
|
|
161
|
+
};
|
|
162
|
+
};
|
|
163
|
+
};
|
|
164
|
+
} & {
|
|
165
|
+
use: any[];
|
|
166
|
+
};
|
|
167
|
+
path: "/convex/jwks";
|
|
168
|
+
};
|
|
169
|
+
getToken: {
|
|
170
|
+
<AsResponse extends boolean = false, ReturnHeaders extends boolean = false>(inputCtx_0: {
|
|
171
|
+
body?: undefined;
|
|
172
|
+
} & {
|
|
173
|
+
method?: "GET" | undefined;
|
|
174
|
+
} & {
|
|
175
|
+
query?: Record<string, any> | undefined;
|
|
176
|
+
} & {
|
|
177
|
+
params?: Record<string, any>;
|
|
178
|
+
} & {
|
|
179
|
+
request?: Request;
|
|
180
|
+
} & {
|
|
181
|
+
headers: HeadersInit;
|
|
182
|
+
} & {
|
|
183
|
+
asResponse?: boolean;
|
|
184
|
+
returnHeaders?: boolean;
|
|
185
|
+
use?: import("better-call").Middleware[];
|
|
186
|
+
path?: string;
|
|
187
|
+
} & {
|
|
188
|
+
asResponse?: AsResponse | undefined;
|
|
189
|
+
returnHeaders?: ReturnHeaders | undefined;
|
|
190
|
+
}): Promise<[AsResponse] extends [true] ? Response : [ReturnHeaders] extends [true] ? {
|
|
191
|
+
headers: Headers;
|
|
192
|
+
response: {
|
|
193
|
+
token: string;
|
|
194
|
+
};
|
|
195
|
+
} : {
|
|
196
|
+
token: string;
|
|
197
|
+
}>;
|
|
198
|
+
options: {
|
|
199
|
+
method: "GET";
|
|
200
|
+
requireHeaders: true;
|
|
201
|
+
use: ((inputContext: import("better-call").MiddlewareInputContext<import("better-call").MiddlewareOptions>) => Promise<{
|
|
202
|
+
session: {
|
|
203
|
+
session: Record<string, any> & {
|
|
204
|
+
id: string;
|
|
205
|
+
createdAt: Date;
|
|
206
|
+
updatedAt: Date;
|
|
207
|
+
userId: string;
|
|
208
|
+
expiresAt: Date;
|
|
209
|
+
token: string;
|
|
210
|
+
ipAddress?: string | null | undefined;
|
|
211
|
+
userAgent?: string | null | undefined;
|
|
212
|
+
};
|
|
213
|
+
user: Record<string, any> & {
|
|
214
|
+
id: string;
|
|
215
|
+
name: string;
|
|
216
|
+
email: string;
|
|
217
|
+
emailVerified: boolean;
|
|
218
|
+
createdAt: Date;
|
|
219
|
+
updatedAt: Date;
|
|
220
|
+
image?: string | null | undefined;
|
|
221
|
+
};
|
|
222
|
+
};
|
|
223
|
+
}>)[];
|
|
224
|
+
metadata: {
|
|
225
|
+
openapi: {
|
|
226
|
+
description: string;
|
|
227
|
+
responses: {
|
|
228
|
+
200: {
|
|
229
|
+
description: string;
|
|
230
|
+
content: {
|
|
231
|
+
"application/json": {
|
|
232
|
+
schema: {
|
|
233
|
+
type: "object";
|
|
234
|
+
properties: {
|
|
235
|
+
token: {
|
|
236
|
+
type: string;
|
|
237
|
+
};
|
|
238
|
+
};
|
|
239
|
+
};
|
|
240
|
+
};
|
|
241
|
+
};
|
|
242
|
+
};
|
|
243
|
+
};
|
|
244
|
+
};
|
|
245
|
+
};
|
|
246
|
+
} & {
|
|
247
|
+
use: any[];
|
|
248
|
+
};
|
|
249
|
+
path: "/convex/token";
|
|
250
|
+
};
|
|
251
|
+
};
|
|
252
|
+
schema: {
|
|
253
|
+
jwks: {
|
|
254
|
+
fields: {
|
|
255
|
+
publicKey: {
|
|
256
|
+
type: "string";
|
|
257
|
+
required: true;
|
|
258
|
+
};
|
|
259
|
+
privateKey: {
|
|
260
|
+
type: "string";
|
|
261
|
+
required: true;
|
|
262
|
+
};
|
|
263
|
+
createdAt: {
|
|
264
|
+
type: "date";
|
|
265
|
+
required: true;
|
|
266
|
+
};
|
|
267
|
+
};
|
|
268
|
+
};
|
|
269
|
+
user: {
|
|
270
|
+
readonly fields: {
|
|
271
|
+
readonly userId: {
|
|
272
|
+
readonly type: "string";
|
|
273
|
+
readonly required: false;
|
|
274
|
+
readonly input: false;
|
|
275
|
+
};
|
|
276
|
+
};
|
|
277
|
+
};
|
|
278
|
+
};
|
|
279
|
+
};
|
|
280
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/plugins/convex/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,UAAU,EAEX,MAAM,iBAAiB,CAAC;AAczB,eAAO,MAAM,MAAM,GAAI,OAAM;IAAE,oBAAoB,CAAC,EAAE,MAAM,CAAA;CAAO;;;;;;;;;;;;;;;;;;;;oBAyH7C,UAAU,CAAC,OAAO,UAAU,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;qCA6Js3kF,CAAC;qCAAkD,CAAC;;;;;;;;;iCAA0Q,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CADvulF,CAAC"}
|
|
@@ -0,0 +1,253 @@
|
|
|
1
|
+
import { createAuthMiddleware, sessionMiddleware, } from "better-auth/api";
|
|
2
|
+
import { createAuthEndpoint, customSession as customSessionPlugin, jwt as jwtPlugin, bearer as bearerPlugin, oidcProvider as oidcProviderPlugin, } from "better-auth/plugins";
|
|
3
|
+
import { omit } from "convex-helpers";
|
|
4
|
+
import { z } from "zod";
|
|
5
|
+
const JWT_COOKIE_NAME = "convex_jwt";
|
|
6
|
+
export const convex = (opts = {}) => {
|
|
7
|
+
const { jwtExpirationSeconds = 60 * 15 } = opts;
|
|
8
|
+
const customSession = customSessionPlugin(async ({ user, session }) => {
|
|
9
|
+
const { userId, ...userData } = omit(user, ["id"]);
|
|
10
|
+
return {
|
|
11
|
+
user: { ...userData, id: userId },
|
|
12
|
+
session: {
|
|
13
|
+
...session,
|
|
14
|
+
userId,
|
|
15
|
+
},
|
|
16
|
+
};
|
|
17
|
+
});
|
|
18
|
+
const oidcProvider = oidcProviderPlugin({
|
|
19
|
+
loginPage: "/not-used",
|
|
20
|
+
metadata: {
|
|
21
|
+
issuer: `${process.env.CONVEX_SITE_URL}`,
|
|
22
|
+
jwks_uri: `${process.env.CONVEX_SITE_URL}/api/auth/convex/jwks`,
|
|
23
|
+
},
|
|
24
|
+
});
|
|
25
|
+
const jwt = jwtPlugin({
|
|
26
|
+
jwt: {
|
|
27
|
+
issuer: `${process.env.CONVEX_SITE_URL}`,
|
|
28
|
+
audience: "convex",
|
|
29
|
+
expirationTime: `${jwtExpirationSeconds}s`,
|
|
30
|
+
getSubject: (session) => {
|
|
31
|
+
// Return the userId from the app user table
|
|
32
|
+
return session.user.userId;
|
|
33
|
+
},
|
|
34
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
35
|
+
definePayload: ({ user: { id, userId, ...user }, session }) => ({
|
|
36
|
+
...user,
|
|
37
|
+
sessionId: session.id,
|
|
38
|
+
}),
|
|
39
|
+
},
|
|
40
|
+
});
|
|
41
|
+
// Bearer plugin converts the session token to a cookie
|
|
42
|
+
// for cross domain social login after code verification, and is required for
|
|
43
|
+
// the headers() helper to work.
|
|
44
|
+
const bearer = bearerPlugin();
|
|
45
|
+
const schema = {
|
|
46
|
+
user: {
|
|
47
|
+
fields: { userId: { type: "string", required: false, input: false } },
|
|
48
|
+
},
|
|
49
|
+
...jwt.schema,
|
|
50
|
+
};
|
|
51
|
+
return {
|
|
52
|
+
id: "convex",
|
|
53
|
+
hooks: {
|
|
54
|
+
before: [...bearer.hooks.before],
|
|
55
|
+
after: [
|
|
56
|
+
...oidcProvider.hooks.after,
|
|
57
|
+
{
|
|
58
|
+
matcher: (ctx) => {
|
|
59
|
+
return ctx.path?.startsWith("/sign-out");
|
|
60
|
+
},
|
|
61
|
+
handler: createAuthMiddleware(async (ctx) => {
|
|
62
|
+
const jwtCookie = ctx.context.createAuthCookie(JWT_COOKIE_NAME, {
|
|
63
|
+
maxAge: 0,
|
|
64
|
+
});
|
|
65
|
+
ctx.setCookie(jwtCookie.name, "", jwtCookie.attributes);
|
|
66
|
+
}),
|
|
67
|
+
},
|
|
68
|
+
],
|
|
69
|
+
},
|
|
70
|
+
endpoints: {
|
|
71
|
+
getSession: createAuthEndpoint("/get-session", {
|
|
72
|
+
method: "GET",
|
|
73
|
+
query: z.optional(z.object({
|
|
74
|
+
// If cookie cache is enabled, it will disable the cache
|
|
75
|
+
// and fetch the session from the database
|
|
76
|
+
disableCookieCache: z
|
|
77
|
+
.boolean({
|
|
78
|
+
description: "Disable cookie cache and fetch session from database",
|
|
79
|
+
})
|
|
80
|
+
.or(z.string().transform((v) => v === "true"))
|
|
81
|
+
.optional(),
|
|
82
|
+
disableRefresh: z
|
|
83
|
+
.boolean({
|
|
84
|
+
description: "Disable session refresh. Useful for checking session status, without updating the session",
|
|
85
|
+
})
|
|
86
|
+
.optional(),
|
|
87
|
+
})),
|
|
88
|
+
metadata: {
|
|
89
|
+
CUSTOM_SESSION: true,
|
|
90
|
+
openapi: {
|
|
91
|
+
description: "Get custom session data",
|
|
92
|
+
responses: {
|
|
93
|
+
"200": {
|
|
94
|
+
description: "Success",
|
|
95
|
+
content: {
|
|
96
|
+
"application/json": {
|
|
97
|
+
schema: {
|
|
98
|
+
type: "array",
|
|
99
|
+
nullable: true,
|
|
100
|
+
items: {
|
|
101
|
+
$ref: "#/components/schemas/Session",
|
|
102
|
+
},
|
|
103
|
+
},
|
|
104
|
+
},
|
|
105
|
+
},
|
|
106
|
+
},
|
|
107
|
+
},
|
|
108
|
+
},
|
|
109
|
+
},
|
|
110
|
+
requireHeaders: true,
|
|
111
|
+
}, async (ctx) => {
|
|
112
|
+
const response = await customSession.endpoints.getSession({
|
|
113
|
+
...ctx,
|
|
114
|
+
returnHeaders: false,
|
|
115
|
+
});
|
|
116
|
+
return response;
|
|
117
|
+
}),
|
|
118
|
+
getOpenIdConfig: createAuthEndpoint("/convex/.well-known/openid-configuration", {
|
|
119
|
+
method: "GET",
|
|
120
|
+
metadata: {
|
|
121
|
+
isAction: false,
|
|
122
|
+
},
|
|
123
|
+
}, async (ctx) => {
|
|
124
|
+
const response = await oidcProvider.endpoints.getOpenIdConfig({
|
|
125
|
+
...ctx,
|
|
126
|
+
returnHeaders: false,
|
|
127
|
+
});
|
|
128
|
+
return response;
|
|
129
|
+
}),
|
|
130
|
+
getJwks: createAuthEndpoint("/convex/jwks", {
|
|
131
|
+
method: "GET",
|
|
132
|
+
metadata: {
|
|
133
|
+
openapi: {
|
|
134
|
+
description: "Get the JSON Web Key Set",
|
|
135
|
+
responses: {
|
|
136
|
+
"200": {
|
|
137
|
+
description: "JSON Web Key Set retrieved successfully",
|
|
138
|
+
content: {
|
|
139
|
+
"application/json": {
|
|
140
|
+
schema: {
|
|
141
|
+
type: "object",
|
|
142
|
+
properties: {
|
|
143
|
+
keys: {
|
|
144
|
+
type: "array",
|
|
145
|
+
description: "Array of public JSON Web Keys",
|
|
146
|
+
items: {
|
|
147
|
+
type: "object",
|
|
148
|
+
properties: {
|
|
149
|
+
kid: {
|
|
150
|
+
type: "string",
|
|
151
|
+
description: "Key ID uniquely identifying the key, corresponds to the 'id' from the stored Jwk",
|
|
152
|
+
},
|
|
153
|
+
kty: {
|
|
154
|
+
type: "string",
|
|
155
|
+
description: "Key type (e.g., 'RSA', 'EC', 'OKP')",
|
|
156
|
+
},
|
|
157
|
+
alg: {
|
|
158
|
+
type: "string",
|
|
159
|
+
description: "Algorithm intended for use with the key (e.g., 'EdDSA', 'RS256')",
|
|
160
|
+
},
|
|
161
|
+
use: {
|
|
162
|
+
type: "string",
|
|
163
|
+
description: "Intended use of the public key (e.g., 'sig' for signature)",
|
|
164
|
+
enum: ["sig"],
|
|
165
|
+
nullable: true,
|
|
166
|
+
},
|
|
167
|
+
n: {
|
|
168
|
+
type: "string",
|
|
169
|
+
description: "Modulus for RSA keys (base64url-encoded)",
|
|
170
|
+
nullable: true,
|
|
171
|
+
},
|
|
172
|
+
e: {
|
|
173
|
+
type: "string",
|
|
174
|
+
description: "Exponent for RSA keys (base64url-encoded)",
|
|
175
|
+
nullable: true,
|
|
176
|
+
},
|
|
177
|
+
crv: {
|
|
178
|
+
type: "string",
|
|
179
|
+
description: "Curve name for elliptic curve keys (e.g., 'Ed25519', 'P-256')",
|
|
180
|
+
nullable: true,
|
|
181
|
+
},
|
|
182
|
+
x: {
|
|
183
|
+
type: "string",
|
|
184
|
+
description: "X coordinate for elliptic curve keys (base64url-encoded)",
|
|
185
|
+
nullable: true,
|
|
186
|
+
},
|
|
187
|
+
y: {
|
|
188
|
+
type: "string",
|
|
189
|
+
description: "Y coordinate for elliptic curve keys (base64url-encoded)",
|
|
190
|
+
nullable: true,
|
|
191
|
+
},
|
|
192
|
+
},
|
|
193
|
+
required: ["kid", "kty", "alg"],
|
|
194
|
+
},
|
|
195
|
+
},
|
|
196
|
+
},
|
|
197
|
+
required: ["keys"],
|
|
198
|
+
},
|
|
199
|
+
},
|
|
200
|
+
},
|
|
201
|
+
},
|
|
202
|
+
},
|
|
203
|
+
},
|
|
204
|
+
},
|
|
205
|
+
}, async (ctx) => {
|
|
206
|
+
const response = await jwt.endpoints.getJwks({
|
|
207
|
+
...ctx,
|
|
208
|
+
returnHeaders: false,
|
|
209
|
+
});
|
|
210
|
+
return response;
|
|
211
|
+
}),
|
|
212
|
+
getToken: createAuthEndpoint("/convex/token", {
|
|
213
|
+
method: "GET",
|
|
214
|
+
requireHeaders: true,
|
|
215
|
+
use: [sessionMiddleware],
|
|
216
|
+
metadata: {
|
|
217
|
+
openapi: {
|
|
218
|
+
description: "Get a JWT token",
|
|
219
|
+
responses: {
|
|
220
|
+
200: {
|
|
221
|
+
description: "Success",
|
|
222
|
+
content: {
|
|
223
|
+
"application/json": {
|
|
224
|
+
schema: {
|
|
225
|
+
type: "object",
|
|
226
|
+
properties: {
|
|
227
|
+
token: {
|
|
228
|
+
type: "string",
|
|
229
|
+
},
|
|
230
|
+
},
|
|
231
|
+
},
|
|
232
|
+
},
|
|
233
|
+
},
|
|
234
|
+
},
|
|
235
|
+
},
|
|
236
|
+
},
|
|
237
|
+
},
|
|
238
|
+
}, async (ctx) => {
|
|
239
|
+
const response = await jwt.endpoints.getToken({
|
|
240
|
+
...ctx,
|
|
241
|
+
returnHeaders: false,
|
|
242
|
+
});
|
|
243
|
+
const jwtCookie = ctx.context.createAuthCookie(JWT_COOKIE_NAME, {
|
|
244
|
+
maxAge: jwtExpirationSeconds,
|
|
245
|
+
});
|
|
246
|
+
ctx.setCookie(jwtCookie.name, response.token, jwtCookie.attributes);
|
|
247
|
+
return response;
|
|
248
|
+
}),
|
|
249
|
+
},
|
|
250
|
+
schema,
|
|
251
|
+
};
|
|
252
|
+
};
|
|
253
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/plugins/convex/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,oBAAoB,EAEpB,iBAAiB,GAClB,MA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M,QAAQ,GAAG,MAAM,GAAG,CAAC,SAAS,CAAC,QAAQ,CAAC;oBAC5C,GAAG,GAAG;oBACN,aAAa,EAAE,KAAK;iBACrB,CAAC,CAAC;gBACH,MAAM,SAAS,GAAG,GAAG,CAAC,OAAO,CAAC,gBAAgB,CAAC,eAAe,EAAE;oBAC9D,MAAM,EAAE,oBAAoB;iBAC7B,CAAC,CAAC;gBACH,GAAG,CAAC,SAAS,CAAC,SAAS,CAAC,IAAI,EAAE,QAAQ,CAAC,KAAK,EAAE,SAAS,CAAC,UAAU,CAAC,CAAC;gBACpE,OAAO,QAAQ,CAAC;YAClB,CAAC,CACF;SACF;QACD,MAAM;KACoB,CAAC;AAC/B,CAAC,CAAC"}
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
import type { Store } from "better-auth";
|
|
2
|
+
import { BetterFetchOption } from "@better-fetch/fetch";
|
|
3
|
+
import { crossDomain } from "./index.js";
|
|
4
|
+
interface CookieAttributes {
|
|
5
|
+
value: string;
|
|
6
|
+
expires?: Date;
|
|
7
|
+
"max-age"?: number;
|
|
8
|
+
domain?: string;
|
|
9
|
+
path?: string;
|
|
10
|
+
secure?: boolean;
|
|
11
|
+
httpOnly?: boolean;
|
|
12
|
+
sameSite?: "Strict" | "Lax" | "None";
|
|
13
|
+
}
|
|
14
|
+
export declare function parseSetCookieHeader(header: string): Map<string, CookieAttributes>;
|
|
15
|
+
export declare function getSetCookie(header: string, prevCookie?: string): string;
|
|
16
|
+
export declare function getCookie(cookie: string): string;
|
|
17
|
+
export declare const crossDomainClient: (opts?: {
|
|
18
|
+
storage?: {
|
|
19
|
+
setItem: (key: string, value: string) => any;
|
|
20
|
+
getItem: (key: string) => string | null;
|
|
21
|
+
};
|
|
22
|
+
storagePrefix?: string;
|
|
23
|
+
disableCache?: boolean;
|
|
24
|
+
}) => {
|
|
25
|
+
id: "cross-domain";
|
|
26
|
+
$InferServerPlugin: ReturnType<typeof crossDomain>;
|
|
27
|
+
getActions(_: import("@better-fetch/fetch").BetterFetch, $store: Store): {
|
|
28
|
+
/**
|
|
29
|
+
* Get the stored cookie.
|
|
30
|
+
*
|
|
31
|
+
* You can use this to get the cookie stored in the device and use it in your fetch
|
|
32
|
+
* requests.
|
|
33
|
+
*
|
|
34
|
+
* @example
|
|
35
|
+
* ```ts
|
|
36
|
+
* const cookie = client.getCookie();
|
|
37
|
+
* fetch("https://api.example.com", {
|
|
38
|
+
* headers: {
|
|
39
|
+
* cookie,
|
|
40
|
+
* },
|
|
41
|
+
* });
|
|
42
|
+
*/
|
|
43
|
+
getCookie: () => string;
|
|
44
|
+
/**
|
|
45
|
+
* Notify the session signal.
|
|
46
|
+
*
|
|
47
|
+
* This is used to trigger an update in useSession, generally when a new session
|
|
48
|
+
* token is set.
|
|
49
|
+
*
|
|
50
|
+
* @example
|
|
51
|
+
* ```ts
|
|
52
|
+
* client.notifySessionSignal();
|
|
53
|
+
* ```
|
|
54
|
+
*/
|
|
55
|
+
updateSession: () => void;
|
|
56
|
+
};
|
|
57
|
+
fetchPlugins: {
|
|
58
|
+
id: string;
|
|
59
|
+
name: string;
|
|
60
|
+
hooks: {
|
|
61
|
+
onSuccess(context: import("@better-fetch/fetch").SuccessContext<any>): Promise<void>;
|
|
62
|
+
};
|
|
63
|
+
init(url: string, options: {
|
|
64
|
+
headers?: (HeadersInit & (HeadersInit | {
|
|
65
|
+
accept: "application/json" | "text/plain" | "application/octet-stream";
|
|
66
|
+
"content-type": "application/json" | "text/plain" | "application/x-www-form-urlencoded" | "multipart/form-data" | "application/octet-stream";
|
|
67
|
+
authorization: "Bearer" | "Basic";
|
|
68
|
+
})) | undefined;
|
|
69
|
+
method?: string | undefined;
|
|
70
|
+
cache?: RequestCache | undefined;
|
|
71
|
+
credentials?: RequestCredentials | undefined;
|
|
72
|
+
integrity?: string | undefined;
|
|
73
|
+
keepalive?: boolean | undefined;
|
|
74
|
+
mode?: RequestMode | undefined;
|
|
75
|
+
priority?: RequestPriority | undefined;
|
|
76
|
+
redirect?: RequestRedirect | undefined;
|
|
77
|
+
referrer?: string | undefined;
|
|
78
|
+
referrerPolicy?: ReferrerPolicy | undefined;
|
|
79
|
+
signal?: (AbortSignal | null) | undefined;
|
|
80
|
+
window?: null | undefined;
|
|
81
|
+
onRequest?: (<T extends Record<string, any>>(context: import("@better-fetch/fetch").RequestContext<T>) => Promise<import("@better-fetch/fetch").RequestContext | void> | import("@better-fetch/fetch").RequestContext | void) | undefined;
|
|
82
|
+
onResponse?: ((context: import("@better-fetch/fetch").ResponseContext) => Promise<Response | void | import("@better-fetch/fetch").ResponseContext> | Response | import("@better-fetch/fetch").ResponseContext | void) | undefined;
|
|
83
|
+
onSuccess?: ((context: import("@better-fetch/fetch").SuccessContext<any>) => Promise<void> | void) | undefined;
|
|
84
|
+
onError?: ((context: import("@better-fetch/fetch").ErrorContext) => Promise<void> | void) | undefined;
|
|
85
|
+
onRetry?: ((response: import("@better-fetch/fetch").ResponseContext) => Promise<void> | void) | undefined;
|
|
86
|
+
hookOptions?: {
|
|
87
|
+
cloneResponse?: boolean;
|
|
88
|
+
} | undefined;
|
|
89
|
+
timeout?: number | undefined;
|
|
90
|
+
customFetchImpl?: import("@better-fetch/fetch").FetchEsque | undefined;
|
|
91
|
+
plugins?: import("@better-fetch/fetch").BetterFetchPlugin[] | undefined;
|
|
92
|
+
baseURL?: string | undefined;
|
|
93
|
+
throw?: boolean | undefined;
|
|
94
|
+
auth?: ({
|
|
95
|
+
type: "Bearer";
|
|
96
|
+
token: string | Promise<string | undefined> | (() => string | Promise<string | undefined> | undefined) | undefined;
|
|
97
|
+
} | {
|
|
98
|
+
type: "Basic";
|
|
99
|
+
username: string | (() => string | undefined) | undefined;
|
|
100
|
+
password: string | (() => string | undefined) | undefined;
|
|
101
|
+
} | {
|
|
102
|
+
type: "Custom";
|
|
103
|
+
prefix: string | (() => string | undefined) | undefined;
|
|
104
|
+
value: string | (() => string | undefined) | undefined;
|
|
105
|
+
}) | undefined;
|
|
106
|
+
body?: any;
|
|
107
|
+
query?: any;
|
|
108
|
+
params?: any;
|
|
109
|
+
duplex?: "full" | "half" | undefined;
|
|
110
|
+
jsonParser?: ((text: string) => Promise<any> | any) | undefined;
|
|
111
|
+
retry?: import("@better-fetch/fetch").RetryOptions | undefined;
|
|
112
|
+
retryAttempt?: number | undefined;
|
|
113
|
+
output?: (import("@better-fetch/fetch").StandardSchemaV1 | typeof Blob | typeof File) | undefined;
|
|
114
|
+
errorSchema?: import("@better-fetch/fetch").StandardSchemaV1 | undefined;
|
|
115
|
+
disableValidation?: boolean | undefined;
|
|
116
|
+
} | undefined): Promise<{
|
|
117
|
+
url: string;
|
|
118
|
+
options: BetterFetchOption;
|
|
119
|
+
}>;
|
|
120
|
+
}[];
|
|
121
|
+
};
|
|
122
|
+
export {};
|
|
123
|
+
//# sourceMappingURL=client.d.ts.map
|