@@ -83,6 +83,137 @@ export function authExtension() {
8383}
8484` ;
8585
86+ export const DEFAULT_MANAGED_AUTH_EXTENSION_TEMPLATE = `// This file is auto-generated. Do not edit this file manually.
87+ // To regenerate the schema, run:
88+ // \`npx kitcn add auth --yes\`
89+
90+ import {
91+ boolean,
92+ convexTable,
93+ defineSchemaExtension,
94+ index,
95+ text,
96+ timestamp,
97+ } from "kitcn/orm";
98+
99+ export const userTable = convexTable(
100+ "user",
101+ {
102+ name: text().notNull(),
103+ email: text().notNull().unique(),
104+ emailVerified: boolean().notNull(),
105+ image: text(),
106+ createdAt: timestamp().notNull(),
107+ updatedAt: timestamp().notNull(),
108+ userId: text(),
109+ },
110+ (userTable) => [
111+ index("email_name").on(userTable.email, userTable.name),
112+ index("name").on(userTable.name),
113+ ]
114+ );
115+
116+ export const sessionTable = convexTable(
117+ "session",
118+ {
119+ expiresAt: timestamp().notNull(),
120+ token: text().notNull().unique(),
121+ createdAt: timestamp().notNull(),
122+ updatedAt: timestamp().notNull(),
123+ ipAddress: text(),
124+ userAgent: text(),
125+ userId: text().notNull().references(() => userTable.id),
126+ },
127+ (sessionTable) => [
128+ index("expiresAt").on(sessionTable.expiresAt),
129+ index("expiresAt_userId").on(sessionTable.expiresAt, sessionTable.userId),
130+ index("userId").on(sessionTable.userId),
131+ ]
132+ );
133+
134+ export const accountTable = convexTable(
135+ "account",
136+ {
137+ accountId: text().notNull(),
138+ providerId: text().notNull(),
139+ userId: text().notNull().references(() => userTable.id),
140+ accessToken: text(),
141+ refreshToken: text(),
142+ idToken: text(),
143+ accessTokenExpiresAt: timestamp(),
144+ refreshTokenExpiresAt: timestamp(),
145+ scope: text(),
146+ password: text(),
147+ createdAt: timestamp().notNull(),
148+ updatedAt: timestamp().notNull(),
149+ },
150+ (accountTable) => [
151+ index("accountId").on(accountTable.accountId),
152+ index("accountId_providerId").on(accountTable.accountId, accountTable.providerId),
153+ index("providerId_userId").on(accountTable.providerId, accountTable.userId),
154+ index("userId").on(accountTable.userId),
155+ ]
156+ );
157+
158+ export const verificationTable = convexTable(
159+ "verification",
160+ {
161+ identifier: text().notNull(),
162+ value: text().notNull(),
163+ expiresAt: timestamp().notNull(),
164+ createdAt: timestamp().notNull(),
165+ updatedAt: timestamp().notNull(),
166+ },
167+ (verificationTable) => [
168+ index("expiresAt").on(verificationTable.expiresAt),
169+ index("identifier").on(verificationTable.identifier),
170+ ]
171+ );
172+
173+ export const jwksTable = convexTable(
174+ "jwks",
175+ {
176+ publicKey: text().notNull(),
177+ privateKey: text().notNull(),
178+ createdAt: timestamp().notNull(),
179+ expiresAt: timestamp(),
180+ }
181+ );
182+
183+ export function authExtension() {
184+ return defineSchemaExtension("auth", {
185+ user: userTable,
186+ session: sessionTable,
187+ account: accountTable,
188+ verification: verificationTable,
189+ jwks: jwksTable,
190+ }).relations((r) => ({
191+ user: {
192+ sessions: r.many.session({
193+ from: r.user.id,
194+ to: r.session.userId,
195+ }),
196+ accounts: r.many.account({
197+ from: r.user.id,
198+ to: r.account.userId,
199+ }),
200+ },
201+ session: {
202+ user: r.one.user({
203+ from: r.session.userId,
204+ to: r.user.id,
205+ }),
206+ },
207+ account: {
208+ user: r.one.user({
209+ from: r.account.userId,
210+ to: r.user.id,
211+ }),
212+ },
213+ }));
214+ }
215+ ` ;
216+
86217export const AUTH_CONVEX_SCHEMA_TEMPLATE = `import { defineTable } from 'convex/server';
87218import { v } from 'convex/values';
88219
0 commit comments