@neutralauth/internal-auth 0.10.11
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 +39 -0
- package/dist/auth-config.d.ts +43 -0
- package/dist/auth-config.d.ts.map +1 -0
- package/dist/auth-config.js +43 -0
- package/dist/auth-config.js.map +1 -0
- package/dist/auth-options.d.ts +3 -0
- package/dist/auth-options.d.ts.map +1 -0
- package/dist/auth-options.js +40 -0
- package/dist/auth-options.js.map +1 -0
- package/dist/auth.d.ts +2 -0
- package/dist/auth.d.ts.map +1 -0
- package/dist/auth.js +4 -0
- package/dist/auth.js.map +1 -0
- package/dist/client/adapter-utils.d.ts +66 -0
- package/dist/client/adapter-utils.d.ts.map +1 -0
- package/dist/client/adapter-utils.js +437 -0
- package/dist/client/adapter-utils.js.map +1 -0
- package/dist/client/adapter.d.ts +14 -0
- package/dist/client/adapter.d.ts.map +1 -0
- package/dist/client/adapter.js +274 -0
- package/dist/client/adapter.js.map +1 -0
- package/dist/client/create-api.d.ts +141 -0
- package/dist/client/create-api.d.ts.map +1 -0
- package/dist/client/create-api.js +205 -0
- package/dist/client/create-api.js.map +1 -0
- package/dist/client/create-client.d.ts +183 -0
- package/dist/client/create-client.d.ts.map +1 -0
- package/dist/client/create-client.js +311 -0
- package/dist/client/create-client.js.map +1 -0
- package/dist/client/create-schema.d.ts +19 -0
- package/dist/client/create-schema.d.ts.map +1 -0
- package/dist/client/create-schema.js +114 -0
- package/dist/client/create-schema.js.map +1 -0
- package/dist/client/index.d.ts +7 -0
- package/dist/client/index.d.ts.map +1 -0
- package/dist/client/index.js +10 -0
- package/dist/client/index.js.map +1 -0
- package/dist/client/plugins/index.d.ts +3 -0
- package/dist/client/plugins/index.d.ts.map +1 -0
- package/dist/client/plugins/index.js +3 -0
- package/dist/client/plugins/index.js.map +1 -0
- package/dist/component/_generated/api.d.ts +36 -0
- package/dist/component/_generated/api.d.ts.map +1 -0
- package/dist/component/_generated/api.js +31 -0
- package/dist/component/_generated/api.js.map +1 -0
- package/dist/component/_generated/component.d.ts +787 -0
- package/dist/component/_generated/component.d.ts.map +1 -0
- package/dist/component/_generated/component.js +11 -0
- package/dist/component/_generated/component.js.map +1 -0
- package/dist/component/_generated/dataModel.d.ts +46 -0
- package/dist/component/_generated/dataModel.d.ts.map +1 -0
- package/dist/component/_generated/dataModel.js +11 -0
- package/dist/component/_generated/dataModel.js.map +1 -0
- package/dist/component/_generated/server.d.ts +121 -0
- package/dist/component/_generated/server.d.ts.map +1 -0
- package/dist/component/_generated/server.js +78 -0
- package/dist/component/_generated/server.js.map +1 -0
- package/dist/component/adapter.d.ts +130 -0
- package/dist/component/adapter.d.ts.map +1 -0
- package/dist/component/adapter.js +5 -0
- package/dist/component/adapter.js.map +1 -0
- package/dist/component/adapterTest.d.ts +10 -0
- package/dist/component/adapterTest.d.ts.map +1 -0
- package/dist/component/adapterTest.js +409 -0
- package/dist/component/adapterTest.js.map +1 -0
- package/dist/component/convex.config.d.ts +3 -0
- package/dist/component/convex.config.d.ts.map +1 -0
- package/dist/component/convex.config.js +4 -0
- package/dist/component/convex.config.js.map +1 -0
- package/dist/component/schema.d.ts +474 -0
- package/dist/component/schema.d.ts.map +1 -0
- package/dist/component/schema.js +139 -0
- package/dist/component/schema.js.map +1 -0
- package/dist/nextjs/client.d.ts +4 -0
- package/dist/nextjs/client.d.ts.map +1 -0
- package/dist/nextjs/client.js +37 -0
- package/dist/nextjs/client.js.map +1 -0
- package/dist/nextjs/index.d.ts +22 -0
- package/dist/nextjs/index.d.ts.map +1 -0
- package/dist/nextjs/index.js +98 -0
- package/dist/nextjs/index.js.map +1 -0
- package/dist/plugins/convex/client.d.ts +6 -0
- package/dist/plugins/convex/client.d.ts.map +1 -0
- package/dist/plugins/convex/client.js +7 -0
- package/dist/plugins/convex/client.js.map +1 -0
- package/dist/plugins/convex/index.d.ts +322 -0
- package/dist/plugins/convex/index.d.ts.map +1 -0
- package/dist/plugins/convex/index.js +422 -0
- package/dist/plugins/convex/index.js.map +1 -0
- package/dist/plugins/cross-domain/client.d.ts +132 -0
- package/dist/plugins/cross-domain/client.d.ts.map +1 -0
- package/dist/plugins/cross-domain/client.js +192 -0
- package/dist/plugins/cross-domain/client.js.map +1 -0
- package/dist/plugins/cross-domain/index.d.ts +51 -0
- package/dist/plugins/cross-domain/index.d.ts.map +1 -0
- package/dist/plugins/cross-domain/index.js +173 -0
- package/dist/plugins/cross-domain/index.js.map +1 -0
- package/dist/plugins/index.d.ts +3 -0
- package/dist/plugins/index.d.ts.map +1 -0
- package/dist/plugins/index.js +3 -0
- package/dist/plugins/index.js.map +1 -0
- package/dist/react/index.d.ts +80 -0
- package/dist/react/index.d.ts.map +1 -0
- package/dist/react/index.js +190 -0
- package/dist/react/index.js.map +1 -0
- package/dist/react-start/index.d.ts +13 -0
- package/dist/react-start/index.d.ts.map +1 -0
- package/dist/react-start/index.js +101 -0
- package/dist/react-start/index.js.map +1 -0
- package/dist/utils/index.d.ts +33 -0
- package/dist/utils/index.d.ts.map +1 -0
- package/dist/utils/index.js +91 -0
- package/dist/utils/index.js.map +1 -0
- package/package.json +208 -0
- package/src/auth-config.ts +80 -0
- package/src/auth-options.ts +54 -0
- package/src/auth.ts +4 -0
- package/src/client/adapter-utils.ts +639 -0
- package/src/client/adapter.test.ts +83 -0
- package/src/client/adapter.ts +363 -0
- package/src/client/create-api.ts +339 -0
- package/src/client/create-client.ts +452 -0
- package/src/client/create-schema.ts +166 -0
- package/src/client/index.ts +22 -0
- package/src/client/plugins/index.ts +2 -0
- package/src/component/_generated/api.ts +52 -0
- package/src/component/_generated/component.ts +2008 -0
- package/src/component/_generated/dataModel.ts +60 -0
- package/src/component/_generated/server.ts +161 -0
- package/src/component/adapter.ts +13 -0
- package/src/component/adapterTest.ts +505 -0
- package/src/component/convex.config.ts +5 -0
- package/src/component/schema.ts +142 -0
- package/src/nextjs/client.tsx +54 -0
- package/src/nextjs/index.ts +152 -0
- package/src/plugins/convex/client.ts +9 -0
- package/src/plugins/convex/index.ts +596 -0
- package/src/plugins/cross-domain/client.test.ts +217 -0
- package/src/plugins/cross-domain/client.ts +234 -0
- package/src/plugins/cross-domain/index.ts +199 -0
- package/src/plugins/index.ts +2 -0
- package/src/react/index.tsx +304 -0
- package/src/react-start/index.ts +153 -0
- package/src/react-start/vite-env.d.ts +2 -0
- package/src/test.ts +18 -0
- package/src/utils/index.ts +171 -0
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
import type { DataModelFromSchemaDefinition, FunctionReference, GenericDataModel, GenericMutationCtx, GenericSchema, HttpRouter, SchemaDefinition } from "convex/server";
|
|
2
|
+
import type { Infer } from "convex/values";
|
|
3
|
+
import type defaultSchema from "../component/schema.js";
|
|
4
|
+
import type { ComponentApi } from "../component/_generated/component.js";
|
|
5
|
+
import type { CreateAuth, GenericCtx } from "./index.js";
|
|
6
|
+
export type AuthFunctions = {
|
|
7
|
+
onCreate?: FunctionReference<"mutation", "internal", {
|
|
8
|
+
[key: string]: any;
|
|
9
|
+
}>;
|
|
10
|
+
onUpdate?: FunctionReference<"mutation", "internal", {
|
|
11
|
+
[key: string]: any;
|
|
12
|
+
}>;
|
|
13
|
+
onDelete?: FunctionReference<"mutation", "internal", {
|
|
14
|
+
[key: string]: any;
|
|
15
|
+
}>;
|
|
16
|
+
};
|
|
17
|
+
export type Triggers<DataModel extends GenericDataModel, Schema extends SchemaDefinition<any, any>> = {
|
|
18
|
+
[K in keyof Schema["tables"]]?: {
|
|
19
|
+
onCreate?: <Ctx extends GenericMutationCtx<DataModel>>(ctx: Ctx, doc: Infer<Schema["tables"][K]["validator"]> & {
|
|
20
|
+
_id: string;
|
|
21
|
+
_creationTime: number;
|
|
22
|
+
}) => Promise<void>;
|
|
23
|
+
onUpdate?: <Ctx extends GenericMutationCtx<DataModel>>(ctx: Ctx, newDoc: Infer<Schema["tables"][K]["validator"]> & {
|
|
24
|
+
_id: string;
|
|
25
|
+
_creationTime: number;
|
|
26
|
+
}, oldDoc: Infer<Schema["tables"][K]["validator"]> & {
|
|
27
|
+
_id: string;
|
|
28
|
+
_creationTime: number;
|
|
29
|
+
}) => Promise<void>;
|
|
30
|
+
onDelete?: <Ctx extends GenericMutationCtx<DataModel>>(ctx: Ctx, doc: Infer<Schema["tables"][K]["validator"]> & {
|
|
31
|
+
_id: string;
|
|
32
|
+
_creationTime: number;
|
|
33
|
+
}) => Promise<void>;
|
|
34
|
+
};
|
|
35
|
+
};
|
|
36
|
+
type SlimComponentApi = {
|
|
37
|
+
adapter: {
|
|
38
|
+
create: FunctionReference<"mutation", "internal">;
|
|
39
|
+
findOne: FunctionReference<"query", "internal">;
|
|
40
|
+
findMany: FunctionReference<"query", "internal">;
|
|
41
|
+
updateOne: FunctionReference<"mutation", "internal">;
|
|
42
|
+
updateMany: FunctionReference<"mutation", "internal">;
|
|
43
|
+
deleteOne: FunctionReference<"mutation", "internal">;
|
|
44
|
+
deleteMany: FunctionReference<"mutation", "internal">;
|
|
45
|
+
};
|
|
46
|
+
adapterTest?: ComponentApi["adapterTest"];
|
|
47
|
+
};
|
|
48
|
+
/**
|
|
49
|
+
* Backend API for the Better Auth component.
|
|
50
|
+
* Responsible for exposing the `client` and `triggers` APIs to the client, http
|
|
51
|
+
* route registration, and having convenience methods for interacting with the
|
|
52
|
+
* component from the backend.
|
|
53
|
+
*
|
|
54
|
+
* @param component - Generally `components.betterAuth` from
|
|
55
|
+
* `./_generated/api` once you've configured it in `convex.config.ts`.
|
|
56
|
+
* @param config - Configuration options for the component.
|
|
57
|
+
* @param config.local - Local schema configuration.
|
|
58
|
+
* @param config.verbose - Whether to enable verbose logging.
|
|
59
|
+
* @param config.triggers - Triggers configuration.
|
|
60
|
+
* @param config.authFunctions - Authentication functions configuration.
|
|
61
|
+
*/
|
|
62
|
+
export declare const createClient: <DataModel extends GenericDataModel, Schema extends SchemaDefinition<GenericSchema, true> = typeof defaultSchema, Api extends SlimComponentApi = SlimComponentApi>(component: Api, config?: {
|
|
63
|
+
local?: {
|
|
64
|
+
schema?: Schema;
|
|
65
|
+
};
|
|
66
|
+
verbose?: boolean;
|
|
67
|
+
} & ({
|
|
68
|
+
triggers: Triggers<DataModel, Schema>;
|
|
69
|
+
authFunctions: AuthFunctions;
|
|
70
|
+
} | {
|
|
71
|
+
triggers?: undefined;
|
|
72
|
+
})) => {
|
|
73
|
+
/**
|
|
74
|
+
* Returns the Convex database adapter for use in Better Auth options.
|
|
75
|
+
* @param ctx - The Convex context
|
|
76
|
+
* @returns The Convex database adapter
|
|
77
|
+
*/
|
|
78
|
+
adapter: (ctx: GenericCtx<DataModel>) => import("better-auth/adapters").AdapterFactory;
|
|
79
|
+
/**
|
|
80
|
+
* Returns the Better Auth auth object and headers for using Better Auth API
|
|
81
|
+
* methods directly in a Convex mutation or query. Convex functions don't
|
|
82
|
+
* have access to request headers, so the headers object is created at
|
|
83
|
+
* runtime with the token for the current session as a Bearer token.
|
|
84
|
+
*
|
|
85
|
+
* @param createAuth - The createAuth function
|
|
86
|
+
* @param ctx - The Convex context
|
|
87
|
+
* @returns A promise that resolves to the Better Auth `auth` API object and
|
|
88
|
+
* headers.
|
|
89
|
+
*/
|
|
90
|
+
getAuth: <T extends CreateAuth<DataModel>>(createAuth: T, ctx: GenericCtx<DataModel>) => Promise<{
|
|
91
|
+
auth: ReturnType<T>;
|
|
92
|
+
headers: Headers;
|
|
93
|
+
}>;
|
|
94
|
+
/**
|
|
95
|
+
* Returns a Headers object for the current session using the session id
|
|
96
|
+
* from the current user identity via `ctx.auth.getUserIdentity()`. This is
|
|
97
|
+
* used to pass the headers to the Better Auth API methods when using the
|
|
98
|
+
* `getAuth` method.
|
|
99
|
+
*
|
|
100
|
+
* @param ctx - The Convex context
|
|
101
|
+
* @returns The headers
|
|
102
|
+
*/
|
|
103
|
+
getHeaders: (ctx: GenericCtx<DataModel>) => Promise<Headers>;
|
|
104
|
+
/**
|
|
105
|
+
* Returns the current user or null if the user is not found
|
|
106
|
+
* @param ctx - The Convex context
|
|
107
|
+
* @returns The user or null if the user is not found
|
|
108
|
+
*/
|
|
109
|
+
safeGetAuthUser: (ctx: GenericCtx<DataModel>) => Promise<DataModelFromSchemaDefinition<Schema>["user"]["document"] | undefined>;
|
|
110
|
+
/**
|
|
111
|
+
* Returns the current user or throws an error if the user is not found
|
|
112
|
+
*
|
|
113
|
+
* @param ctx - The Convex context
|
|
114
|
+
* @returns The user or throws an error if the user is not found
|
|
115
|
+
*/
|
|
116
|
+
getAuthUser: (ctx: GenericCtx<DataModel>) => Promise<DataModelFromSchemaDefinition<Schema>["user"]["document"]>;
|
|
117
|
+
/**
|
|
118
|
+
* Returns a user by their Better Auth user id.
|
|
119
|
+
* @param ctx - The Convex context
|
|
120
|
+
* @param id - The Better Auth user id
|
|
121
|
+
* @returns The user or null if the user is not found
|
|
122
|
+
*/
|
|
123
|
+
getAnyUserById: (ctx: GenericCtx<DataModel>, id: string) => Promise<DataModelFromSchemaDefinition<Schema>["user"]["document"] | null>;
|
|
124
|
+
/**
|
|
125
|
+
* Replaces 0.7 behavior of returning a new user id from
|
|
126
|
+
* onCreateUser
|
|
127
|
+
* @param ctx - The Convex context
|
|
128
|
+
* @param authId - The Better Auth user id
|
|
129
|
+
* @param userId - The app user id
|
|
130
|
+
* @deprecated in 0.9
|
|
131
|
+
*/
|
|
132
|
+
setUserId: (ctx: GenericMutationCtx<DataModel>, authId: string, userId: string) => Promise<void>;
|
|
133
|
+
/**
|
|
134
|
+
* Exposes functions for use with the ClientAuthBoundary component. Currently
|
|
135
|
+
* only contains getAuthUser.
|
|
136
|
+
* @returns Functions to pass to the ClientAuthBoundary component.
|
|
137
|
+
*/
|
|
138
|
+
clientApi: () => {
|
|
139
|
+
/**
|
|
140
|
+
* Convex query to get the current user. For use with the ClientAuthBoundary component.
|
|
141
|
+
*
|
|
142
|
+
* ```ts title="convex/auth.ts"
|
|
143
|
+
* export const { getAuthUser } = authComponent.clientApi();
|
|
144
|
+
* ```
|
|
145
|
+
*
|
|
146
|
+
* @returns The user or throws an error if the user is not found
|
|
147
|
+
*/
|
|
148
|
+
getAuthUser: import("convex/server").RegisteredQuery<"public", {}, Promise<DataModelFromSchemaDefinition<Schema>["user"]["document"]>>;
|
|
149
|
+
};
|
|
150
|
+
/**
|
|
151
|
+
* Exposes functions for executing trigger callbacks in the app context.
|
|
152
|
+
*
|
|
153
|
+
* Callbacks are defined in the `triggers` option to the component client config.
|
|
154
|
+
*
|
|
155
|
+
* See {@link createClient} for more information.
|
|
156
|
+
*
|
|
157
|
+
* @returns Functions to execute trigger callbacks in the app context.
|
|
158
|
+
*/
|
|
159
|
+
triggersApi: () => {
|
|
160
|
+
onCreate: import("convex/server").RegisteredMutation<"internal", {
|
|
161
|
+
model: string;
|
|
162
|
+
doc: any;
|
|
163
|
+
}, Promise<void>>;
|
|
164
|
+
onUpdate: import("convex/server").RegisteredMutation<"internal", {
|
|
165
|
+
model: string;
|
|
166
|
+
oldDoc: any;
|
|
167
|
+
newDoc: any;
|
|
168
|
+
}, Promise<void>>;
|
|
169
|
+
onDelete: import("convex/server").RegisteredMutation<"internal", {
|
|
170
|
+
model: string;
|
|
171
|
+
doc: any;
|
|
172
|
+
}, Promise<void>>;
|
|
173
|
+
};
|
|
174
|
+
registerRoutes: (http: HttpRouter, createAuth: CreateAuth<DataModel>, opts?: {
|
|
175
|
+
cors?: boolean | {
|
|
176
|
+
allowedOrigins?: string[];
|
|
177
|
+
allowedHeaders?: string[];
|
|
178
|
+
exposedHeaders?: string[];
|
|
179
|
+
};
|
|
180
|
+
}) => void;
|
|
181
|
+
};
|
|
182
|
+
export {};
|
|
183
|
+
//# sourceMappingURL=create-client.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"create-client.d.ts","sourceRoot":"","sources":["../../src/client/create-client.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EACV,6BAA6B,EAC7B,iBAAiB,EACjB,gBAAgB,EAChB,kBAAkB,EAClB,aAAa,EACb,UAAU,E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,CAAC;YAC1B,cAAc,CAAC,EAAE,MAAM,EAAE,CAAC;YAC1B,cAAc,CAAC,EAAE,MAAM,EAAE,CAAC;SAC3B,CAAC;KACP;CAqGN,CAAC"}
|
|
@@ -0,0 +1,311 @@
|
|
|
1
|
+
import { httpActionGeneric, internalMutationGeneric, queryGeneric, } from "convex/server";
|
|
2
|
+
import { ConvexError, v } from "convex/values";
|
|
3
|
+
import { convexAdapter } from "./adapter.js";
|
|
4
|
+
import { corsRouter } from "convex-helpers/server/cors";
|
|
5
|
+
/**
|
|
6
|
+
* Backend API for the Better Auth component.
|
|
7
|
+
* Responsible for exposing the `client` and `triggers` APIs to the client, http
|
|
8
|
+
* route registration, and having convenience methods for interacting with the
|
|
9
|
+
* component from the backend.
|
|
10
|
+
*
|
|
11
|
+
* @param component - Generally `components.betterAuth` from
|
|
12
|
+
* `./_generated/api` once you've configured it in `convex.config.ts`.
|
|
13
|
+
* @param config - Configuration options for the component.
|
|
14
|
+
* @param config.local - Local schema configuration.
|
|
15
|
+
* @param config.verbose - Whether to enable verbose logging.
|
|
16
|
+
* @param config.triggers - Triggers configuration.
|
|
17
|
+
* @param config.authFunctions - Authentication functions configuration.
|
|
18
|
+
*/
|
|
19
|
+
export const createClient = (component, config) => {
|
|
20
|
+
const safeGetAuthUser = async (ctx) => {
|
|
21
|
+
const identity = await ctx.auth.getUserIdentity();
|
|
22
|
+
if (!identity) {
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
const session = (await ctx.runQuery(component.adapter.findOne, {
|
|
26
|
+
model: "session",
|
|
27
|
+
where: [
|
|
28
|
+
{
|
|
29
|
+
field: "_id",
|
|
30
|
+
value: identity.sessionId,
|
|
31
|
+
},
|
|
32
|
+
{
|
|
33
|
+
field: "expiresAt",
|
|
34
|
+
operator: "gt",
|
|
35
|
+
value: new Date().getTime(),
|
|
36
|
+
},
|
|
37
|
+
],
|
|
38
|
+
}));
|
|
39
|
+
if (!session) {
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
const doc = (await ctx.runQuery(component.adapter.findOne, {
|
|
43
|
+
model: "user",
|
|
44
|
+
where: [
|
|
45
|
+
{
|
|
46
|
+
field: "_id",
|
|
47
|
+
value: identity.subject,
|
|
48
|
+
},
|
|
49
|
+
],
|
|
50
|
+
}));
|
|
51
|
+
if (!doc) {
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
return doc;
|
|
55
|
+
};
|
|
56
|
+
const getAuthUser = async (ctx) => {
|
|
57
|
+
const user = await safeGetAuthUser(ctx);
|
|
58
|
+
if (!user) {
|
|
59
|
+
throw new ConvexError("Unauthenticated");
|
|
60
|
+
}
|
|
61
|
+
return user;
|
|
62
|
+
};
|
|
63
|
+
const getHeaders = async (ctx) => {
|
|
64
|
+
const identity = await ctx.auth.getUserIdentity();
|
|
65
|
+
if (!identity) {
|
|
66
|
+
return new Headers();
|
|
67
|
+
}
|
|
68
|
+
// Don't validate the session here, let Better Auth handle that
|
|
69
|
+
const session = await ctx.runQuery(component.adapter.findOne, {
|
|
70
|
+
model: "session",
|
|
71
|
+
where: [
|
|
72
|
+
{
|
|
73
|
+
field: "_id",
|
|
74
|
+
value: identity.sessionId,
|
|
75
|
+
},
|
|
76
|
+
],
|
|
77
|
+
});
|
|
78
|
+
return new Headers({
|
|
79
|
+
...(session?.token ? { authorization: `Bearer ${session.token}` } : {}),
|
|
80
|
+
...(session?.ipAddress
|
|
81
|
+
? { "x-forwarded-for": session.ipAddress }
|
|
82
|
+
: {}),
|
|
83
|
+
});
|
|
84
|
+
};
|
|
85
|
+
return {
|
|
86
|
+
/**
|
|
87
|
+
* Returns the Convex database adapter for use in Better Auth options.
|
|
88
|
+
* @param ctx - The Convex context
|
|
89
|
+
* @returns The Convex database adapter
|
|
90
|
+
*/
|
|
91
|
+
adapter: (ctx) => convexAdapter(ctx, component, {
|
|
92
|
+
...config,
|
|
93
|
+
debugLogs: config?.verbose,
|
|
94
|
+
}),
|
|
95
|
+
/**
|
|
96
|
+
* Returns the Better Auth auth object and headers for using Better Auth API
|
|
97
|
+
* methods directly in a Convex mutation or query. Convex functions don't
|
|
98
|
+
* have access to request headers, so the headers object is created at
|
|
99
|
+
* runtime with the token for the current session as a Bearer token.
|
|
100
|
+
*
|
|
101
|
+
* @param createAuth - The createAuth function
|
|
102
|
+
* @param ctx - The Convex context
|
|
103
|
+
* @returns A promise that resolves to the Better Auth `auth` API object and
|
|
104
|
+
* headers.
|
|
105
|
+
*/
|
|
106
|
+
getAuth: async (createAuth, ctx) => ({
|
|
107
|
+
auth: createAuth(ctx),
|
|
108
|
+
headers: await getHeaders(ctx),
|
|
109
|
+
}),
|
|
110
|
+
/**
|
|
111
|
+
* Returns a Headers object for the current session using the session id
|
|
112
|
+
* from the current user identity via `ctx.auth.getUserIdentity()`. This is
|
|
113
|
+
* used to pass the headers to the Better Auth API methods when using the
|
|
114
|
+
* `getAuth` method.
|
|
115
|
+
*
|
|
116
|
+
* @param ctx - The Convex context
|
|
117
|
+
* @returns The headers
|
|
118
|
+
*/
|
|
119
|
+
getHeaders,
|
|
120
|
+
/**
|
|
121
|
+
* Returns the current user or null if the user is not found
|
|
122
|
+
* @param ctx - The Convex context
|
|
123
|
+
* @returns The user or null if the user is not found
|
|
124
|
+
*/
|
|
125
|
+
safeGetAuthUser,
|
|
126
|
+
/**
|
|
127
|
+
* Returns the current user or throws an error if the user is not found
|
|
128
|
+
*
|
|
129
|
+
* @param ctx - The Convex context
|
|
130
|
+
* @returns The user or throws an error if the user is not found
|
|
131
|
+
*/
|
|
132
|
+
getAuthUser,
|
|
133
|
+
/**
|
|
134
|
+
* Returns a user by their Better Auth user id.
|
|
135
|
+
* @param ctx - The Convex context
|
|
136
|
+
* @param id - The Better Auth user id
|
|
137
|
+
* @returns The user or null if the user is not found
|
|
138
|
+
*/
|
|
139
|
+
getAnyUserById: async (ctx, id) => {
|
|
140
|
+
return (await ctx.runQuery(component.adapter.findOne, {
|
|
141
|
+
model: "user",
|
|
142
|
+
where: [{ field: "_id", value: id }],
|
|
143
|
+
}));
|
|
144
|
+
},
|
|
145
|
+
/**
|
|
146
|
+
* Replaces 0.7 behavior of returning a new user id from
|
|
147
|
+
* onCreateUser
|
|
148
|
+
* @param ctx - The Convex context
|
|
149
|
+
* @param authId - The Better Auth user id
|
|
150
|
+
* @param userId - The app user id
|
|
151
|
+
* @deprecated in 0.9
|
|
152
|
+
*/
|
|
153
|
+
setUserId: async (ctx, authId, userId) => {
|
|
154
|
+
await ctx.runMutation(component.adapter.updateOne, {
|
|
155
|
+
input: {
|
|
156
|
+
model: "user",
|
|
157
|
+
where: [{ field: "_id", value: authId }],
|
|
158
|
+
update: { userId },
|
|
159
|
+
},
|
|
160
|
+
});
|
|
161
|
+
},
|
|
162
|
+
/**
|
|
163
|
+
* Exposes functions for use with the ClientAuthBoundary component. Currently
|
|
164
|
+
* only contains getAuthUser.
|
|
165
|
+
* @returns Functions to pass to the ClientAuthBoundary component.
|
|
166
|
+
*/
|
|
167
|
+
clientApi: () => ({
|
|
168
|
+
/**
|
|
169
|
+
* Convex query to get the current user. For use with the ClientAuthBoundary component.
|
|
170
|
+
*
|
|
171
|
+
* ```ts title="convex/auth.ts"
|
|
172
|
+
* export const { getAuthUser } = authComponent.clientApi();
|
|
173
|
+
* ```
|
|
174
|
+
*
|
|
175
|
+
* @returns The user or throws an error if the user is not found
|
|
176
|
+
*/
|
|
177
|
+
getAuthUser: queryGeneric({
|
|
178
|
+
args: {},
|
|
179
|
+
handler: async (ctx) => {
|
|
180
|
+
return await getAuthUser(ctx);
|
|
181
|
+
},
|
|
182
|
+
}),
|
|
183
|
+
}),
|
|
184
|
+
/**
|
|
185
|
+
* Exposes functions for executing trigger callbacks in the app context.
|
|
186
|
+
*
|
|
187
|
+
* Callbacks are defined in the `triggers` option to the component client config.
|
|
188
|
+
*
|
|
189
|
+
* See {@link createClient} for more information.
|
|
190
|
+
*
|
|
191
|
+
* @returns Functions to execute trigger callbacks in the app context.
|
|
192
|
+
*/
|
|
193
|
+
triggersApi: () => ({
|
|
194
|
+
onCreate: internalMutationGeneric({
|
|
195
|
+
args: {
|
|
196
|
+
doc: v.any(),
|
|
197
|
+
model: v.string(),
|
|
198
|
+
},
|
|
199
|
+
handler: async (ctx, args) => {
|
|
200
|
+
await config?.triggers?.[args.model]?.onCreate?.(ctx, args.doc);
|
|
201
|
+
},
|
|
202
|
+
}),
|
|
203
|
+
onUpdate: internalMutationGeneric({
|
|
204
|
+
args: {
|
|
205
|
+
oldDoc: v.any(),
|
|
206
|
+
newDoc: v.any(),
|
|
207
|
+
model: v.string(),
|
|
208
|
+
},
|
|
209
|
+
handler: async (ctx, args) => {
|
|
210
|
+
await config?.triggers?.[args.model]?.onUpdate?.(ctx, args.newDoc, args.oldDoc);
|
|
211
|
+
},
|
|
212
|
+
}),
|
|
213
|
+
onDelete: internalMutationGeneric({
|
|
214
|
+
args: {
|
|
215
|
+
doc: v.any(),
|
|
216
|
+
model: v.string(),
|
|
217
|
+
},
|
|
218
|
+
handler: async (ctx, args) => {
|
|
219
|
+
await config?.triggers?.[args.model]?.onDelete?.(ctx, args.doc);
|
|
220
|
+
},
|
|
221
|
+
}),
|
|
222
|
+
}),
|
|
223
|
+
registerRoutes: (http, createAuth, opts = {}) => {
|
|
224
|
+
const staticAuth = createAuth({});
|
|
225
|
+
const path = staticAuth.options.basePath ?? "/api/auth";
|
|
226
|
+
const authRequestHandler = httpActionGeneric(async (ctx, request) => {
|
|
227
|
+
if (config?.verbose) {
|
|
228
|
+
// eslint-disable-next-line no-console
|
|
229
|
+
console.log("options.baseURL", staticAuth.options.baseURL);
|
|
230
|
+
// eslint-disable-next-line no-console
|
|
231
|
+
console.log("request headers", request.headers);
|
|
232
|
+
}
|
|
233
|
+
const auth = createAuth(ctx);
|
|
234
|
+
const response = await auth.handler(request);
|
|
235
|
+
if (config?.verbose) {
|
|
236
|
+
// eslint-disable-next-line no-console
|
|
237
|
+
console.log("response headers", response.headers);
|
|
238
|
+
}
|
|
239
|
+
return response;
|
|
240
|
+
});
|
|
241
|
+
const wellKnown = http.lookup("/.well-known/openid-configuration", "GET");
|
|
242
|
+
// If registerRoutes is used multiple times, this may already be defined
|
|
243
|
+
if (!wellKnown) {
|
|
244
|
+
// Redirect root well-known to api well-known
|
|
245
|
+
http.route({
|
|
246
|
+
path: "/.well-known/openid-configuration",
|
|
247
|
+
method: "GET",
|
|
248
|
+
handler: httpActionGeneric(async () => {
|
|
249
|
+
const url = `${process.env.CONVEX_SITE_URL}${path}/convex/.well-known/openid-configuration`;
|
|
250
|
+
return Response.redirect(url);
|
|
251
|
+
}),
|
|
252
|
+
});
|
|
253
|
+
}
|
|
254
|
+
if (!opts.cors) {
|
|
255
|
+
http.route({
|
|
256
|
+
pathPrefix: `${path}/`,
|
|
257
|
+
method: "GET",
|
|
258
|
+
handler: authRequestHandler,
|
|
259
|
+
});
|
|
260
|
+
http.route({
|
|
261
|
+
pathPrefix: `${path}/`,
|
|
262
|
+
method: "POST",
|
|
263
|
+
handler: authRequestHandler,
|
|
264
|
+
});
|
|
265
|
+
return;
|
|
266
|
+
}
|
|
267
|
+
const corsOpts = typeof opts.cors === "boolean"
|
|
268
|
+
? { allowedOrigins: [], allowedHeaders: [], exposedHeaders: [] }
|
|
269
|
+
: opts.cors;
|
|
270
|
+
let trustedOriginsOption;
|
|
271
|
+
const cors = corsRouter(http, {
|
|
272
|
+
allowedOrigins: async (request) => {
|
|
273
|
+
trustedOriginsOption =
|
|
274
|
+
trustedOriginsOption ??
|
|
275
|
+
(await staticAuth.$context).options.trustedOrigins ??
|
|
276
|
+
[];
|
|
277
|
+
const trustedOrigins = Array.isArray(trustedOriginsOption)
|
|
278
|
+
? trustedOriginsOption
|
|
279
|
+
: await trustedOriginsOption(request);
|
|
280
|
+
return trustedOrigins
|
|
281
|
+
.map((origin) =>
|
|
282
|
+
// Strip trailing wildcards, unsupported for allowedOrigins
|
|
283
|
+
origin.endsWith("*") && origin.length > 1
|
|
284
|
+
? origin.slice(0, -1)
|
|
285
|
+
: origin)
|
|
286
|
+
.concat(corsOpts.allowedOrigins ?? []);
|
|
287
|
+
},
|
|
288
|
+
allowCredentials: true,
|
|
289
|
+
allowedHeaders: [
|
|
290
|
+
"Content-Type",
|
|
291
|
+
"Better-Auth-Cookie",
|
|
292
|
+
"Authorization",
|
|
293
|
+
].concat(corsOpts.allowedHeaders ?? []),
|
|
294
|
+
exposedHeaders: ["Set-Better-Auth-Cookie"].concat(corsOpts.exposedHeaders ?? []),
|
|
295
|
+
debug: config?.verbose,
|
|
296
|
+
enforceAllowOrigins: false,
|
|
297
|
+
});
|
|
298
|
+
cors.route({
|
|
299
|
+
pathPrefix: `${path}/`,
|
|
300
|
+
method: "GET",
|
|
301
|
+
handler: authRequestHandler,
|
|
302
|
+
});
|
|
303
|
+
cors.route({
|
|
304
|
+
pathPrefix: `${path}/`,
|
|
305
|
+
method: "POST",
|
|
306
|
+
handler: authRequestHandler,
|
|
307
|
+
});
|
|
308
|
+
},
|
|
309
|
+
};
|
|
310
|
+
};
|
|
311
|
+
//# sourceMappingURL=create-client.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"create-client.js","sourceRoot":"","sources":["../../src/client/create-client.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,iBAAiB,EACjB,uBAAuB,EACvB,YAAY,GACb,MAAM,eAAe,CAAC;AAUvB,OAAO,EAAE,WAAW,EAAE,CAAC,EAAE,MAAM,eAAe,CAAC;AAE/C,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAC7C,OAAO,EAAE,UAAU,EAAE,MAAM,4BAA4B,CAAC;AAyDxD;;;;;;;;;;;;;GAaG;AACH,MAAM,CAAC,MAAM,YAAY,GAAG,CAK1B,SAAc,EACd,MAWC,EACD,EAAE;IAGF,MAAM,eAAe,GAAG,KAAK,EAAE,GAA0B,EAAE,EAAE;QAC3D,MAAM,QAAQ,GAAG,MAAM,GAAG,CAAC,IAAI,CAAC,eAAe,EAAE,CAAC;QA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E,OAAO;gBACtB,mBAAmB,EAAE,KAAK;aAC3B,CAAC,CAAC;YAEH,IAAI,CAAC,KAAK,CAAC;gBACT,UAAU,EAAE,GAAG,IAAI,GAAG;gBACtB,MAAM,EAAE,KAAK;gBACb,OAAO,EAAE,kBAAkB;aAC5B,CAAC,CAAC;YAEH,IAAI,CAAC,KAAK,CAAC;gBACT,UAAU,EAAE,GAAG,IAAI,GAAG;gBACtB,MAAM,EAAE,MAAM;gBACd,OAAO,EAAE,kBAAkB;aAC5B,CAAC,CAAC;QACL,CAAC;KACF,CAAC;AACJ,CAAC,CAAC"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { BetterAuthDBSchema } from "better-auth/db";
|
|
2
|
+
export declare const indexFields: {
|
|
3
|
+
account: (string | string[])[];
|
|
4
|
+
rateLimit: string[];
|
|
5
|
+
session: (string | string[])[];
|
|
6
|
+
verification: string[];
|
|
7
|
+
user: (string | string[])[];
|
|
8
|
+
passkey: string[];
|
|
9
|
+
oauthConsent: string[][];
|
|
10
|
+
};
|
|
11
|
+
export declare const createSchema: ({ file, tables, }: {
|
|
12
|
+
tables: BetterAuthDBSchema;
|
|
13
|
+
file?: string;
|
|
14
|
+
}) => Promise<{
|
|
15
|
+
code: string;
|
|
16
|
+
path: string;
|
|
17
|
+
overwrite: boolean;
|
|
18
|
+
}>;
|
|
19
|
+
//# sourceMappingURL=create-schema.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"create-schema.d.ts","sourceRoot":"","sources":["../../src/client/create-schema.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAoB,MAAM,gBAAgB,CAAC;AAI3E,eAAO,MAAM,WAAW;;;;;;;;CAQvB,CAAC;AAkDF,eAAO,MAAM,YAAY,GAAU,mBAGhC;IACD,MAAM,EAAE,kBAAkB,CAAC;IAC3B,IAAI,CAAC,EAAE,MAAM,CAAC;CACf;;;;EAiGA,CAAC"}
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
// Manually add fields to index on for schema generation,
|
|
2
|
+
// all fields in the schema specialFields are automatically indexed
|
|
3
|
+
export const indexFields = {
|
|
4
|
+
account: ["accountId", ["accountId", "providerId"], ["providerId", "userId"]],
|
|
5
|
+
rateLimit: ["key"],
|
|
6
|
+
session: ["expiresAt", ["expiresAt", "userId"]],
|
|
7
|
+
verification: ["expiresAt", "identifier"],
|
|
8
|
+
user: [["email", "name"], "name", "userId"],
|
|
9
|
+
passkey: ["credentialID"],
|
|
10
|
+
oauthConsent: [["clientId", "userId"]],
|
|
11
|
+
};
|
|
12
|
+
// Return map of unique, sortable, and reference fields
|
|
13
|
+
const specialFields = (tables) => Object.fromEntries(Object.entries(tables)
|
|
14
|
+
.map(([key, table]) => {
|
|
15
|
+
const fields = Object.fromEntries(Object.entries(table.fields)
|
|
16
|
+
.map(([fieldKey, field]) => [
|
|
17
|
+
field.fieldName ?? fieldKey,
|
|
18
|
+
{
|
|
19
|
+
...(field.sortable ? { sortable: true } : {}),
|
|
20
|
+
...(field.unique ? { unique: true } : {}),
|
|
21
|
+
...(field.references ? { references: field.references } : {}),
|
|
22
|
+
},
|
|
23
|
+
])
|
|
24
|
+
.filter(([_key, value]) => typeof value === "object" ? Object.keys(value).length > 0 : true));
|
|
25
|
+
return [key, fields];
|
|
26
|
+
})
|
|
27
|
+
.filter(([_key, value]) => typeof value === "object" ? Object.keys(value).length > 0 : true));
|
|
28
|
+
const mergedIndexFields = (tables) => Object.fromEntries(Object.entries(tables).map(([key, table]) => {
|
|
29
|
+
const manualIndexes = indexFields[key]?.map((index) => {
|
|
30
|
+
return typeof index === "string"
|
|
31
|
+
? (table.fields[index]?.fieldName ?? index)
|
|
32
|
+
: index.map((i) => table.fields[i]?.fieldName ?? i);
|
|
33
|
+
}) || [];
|
|
34
|
+
const specialFieldIndexes = Object.keys(specialFields(tables)[key] ||
|
|
35
|
+
{}).filter((index) => !manualIndexes.some((m) => Array.isArray(m) ? m[0] === index : m === index));
|
|
36
|
+
return [key, manualIndexes.concat(specialFieldIndexes)];
|
|
37
|
+
}));
|
|
38
|
+
export const createSchema = async ({ file, tables, }) => {
|
|
39
|
+
// stop convex esbuild from throwing over this import, only runs
|
|
40
|
+
// in the better auth cli
|
|
41
|
+
const pathImport = "path";
|
|
42
|
+
const path = await import(pathImport);
|
|
43
|
+
const baseName = path.basename(path.resolve(process.cwd(), file ?? ""));
|
|
44
|
+
// if the target directory is named "convex", they're almost definitely
|
|
45
|
+
// generating the schema in the wrong directory, likely would replace the
|
|
46
|
+
// app schema
|
|
47
|
+
if (baseName === "convex") {
|
|
48
|
+
throw new Error("Better Auth schema must be generated in the Better Auth component directory.");
|
|
49
|
+
}
|
|
50
|
+
let code = `/**
|
|
51
|
+
* This file is auto-generated. Do not edit this file manually.
|
|
52
|
+
* To regenerate the schema, run:
|
|
53
|
+
* \`npx @better-auth/cli generate --output ${file} -y\`
|
|
54
|
+
*
|
|
55
|
+
* To customize the schema, generate to an alternate file and import
|
|
56
|
+
* the table definitions to your schema file. See
|
|
57
|
+
* https://labs.convex.dev/better-auth/features/local-install#adding-custom-indexes.
|
|
58
|
+
*/
|
|
59
|
+
|
|
60
|
+
import { defineSchema, defineTable } from "convex/server";
|
|
61
|
+
import { v } from "convex/values";
|
|
62
|
+
|
|
63
|
+
export const tables = {
|
|
64
|
+
`;
|
|
65
|
+
for (const tableKey in tables) {
|
|
66
|
+
const table = tables[tableKey];
|
|
67
|
+
const modelName = table.modelName;
|
|
68
|
+
// No id fields in Convex schema
|
|
69
|
+
const fields = Object.fromEntries(Object.entries(table.fields).filter(([key]) => key !== "id"));
|
|
70
|
+
function getType(name, field) {
|
|
71
|
+
const type = field.type;
|
|
72
|
+
const typeMap = {
|
|
73
|
+
string: `v.string()`,
|
|
74
|
+
boolean: `v.boolean()`,
|
|
75
|
+
number: `v.number()`,
|
|
76
|
+
date: `v.number()`,
|
|
77
|
+
json: `v.string()`,
|
|
78
|
+
"number[]": `v.array(v.number())`,
|
|
79
|
+
"string[]": `v.array(v.string())`,
|
|
80
|
+
};
|
|
81
|
+
return typeMap[type];
|
|
82
|
+
}
|
|
83
|
+
const indexes = mergedIndexFields(tables)[tableKey]?.map((index) => {
|
|
84
|
+
const indexArray = Array.isArray(index) ? index.sort() : [index];
|
|
85
|
+
const indexName = indexArray.join("_");
|
|
86
|
+
return `.index("${indexName}", ${JSON.stringify(indexArray)})`;
|
|
87
|
+
}) || [];
|
|
88
|
+
const schema = `${modelName}: defineTable({
|
|
89
|
+
${Object.keys(fields)
|
|
90
|
+
.map((field) => {
|
|
91
|
+
const attr = fields[field];
|
|
92
|
+
const type = getType(field, attr);
|
|
93
|
+
const optional = (fieldSchema) => attr.required
|
|
94
|
+
? fieldSchema
|
|
95
|
+
: `v.optional(v.union(v.null(), ${fieldSchema}))`;
|
|
96
|
+
return ` ${attr.fieldName ?? field}: ${optional(type)},`;
|
|
97
|
+
})
|
|
98
|
+
.join("\n")}
|
|
99
|
+
})${indexes.length > 0 ? `\n ${indexes.join("\n ")}` : ""},\n`;
|
|
100
|
+
code += ` ${schema}`;
|
|
101
|
+
}
|
|
102
|
+
code += `};
|
|
103
|
+
|
|
104
|
+
const schema = defineSchema(tables);
|
|
105
|
+
|
|
106
|
+
export default schema;
|
|
107
|
+
`;
|
|
108
|
+
return {
|
|
109
|
+
code,
|
|
110
|
+
path: file ?? "./schema.ts",
|
|
111
|
+
overwrite: true,
|
|
112
|
+
};
|
|
113
|
+
};
|
|
114
|
+
//# sourceMappingURL=create-schema.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"create-schema.js","sourceRoot":"","sources":["../../src/client/create-schema.ts"],"names":[],"mappings":"AAEA,yDAAyD;AACzD,mEAAmE;AACnE,MAAM,CAAC,MAAM,WAAW,GAAG;IACzB,OAAO,EAAE,CAAC,WAAW,EAAE,CAAC,WAAW,EAAE,YAAY,CAAC,EAAE,CAAC,YAAY,EAAE,QAAQ,CAAC,CAAC;IAC7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