Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2,100 changes: 2,100 additions & 0 deletions convex/_generated/api.d.ts

Large diffs are not rendered by default.

34 changes: 18 additions & 16 deletions convex/_generated/dataModel.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,29 +8,29 @@
* @module
*/

import { AnyDataModel } from "convex/server";
import type {
DataModelFromSchemaDefinition,
DocumentByName,
TableNamesInDataModel,
SystemTableNames,
} from "convex/server";
import type { GenericId } from "convex/values";

/**
* No `schema.ts` file found!
*
* This generated code has permissive types like `Doc = any` because
* Convex doesn't know your schema. If you'd like more type safety, see
* https://docs.convex.dev/using/schemas for instructions on how to add a
* schema file.
*
* After you change a schema, rerun codegen with `npx convex dev`.
*/
import schema from "../schema.js";

/**
* The names of all of your Convex tables.
*/
export type TableNames = string;
export type TableNames = TableNamesInDataModel<DataModel>;

/**
* The type of a document stored in Convex.
*
* @typeParam TableName - A string literal type of the table name (like "users").
*/
export type Doc = any;
export type Doc<TableName extends TableNames> = DocumentByName<
DataModel,
TableName
>;

/**
* An identifier for a document in Convex.
Expand All @@ -42,8 +42,10 @@ export type Doc = any;
*
* IDs are just strings at runtime, but this type can be used to distinguish them from other
* strings when type checking.
*
* @typeParam TableName - A string literal type of the table name (like "users").
*/
export type Id<TableName extends TableNames = TableNames> =
export type Id<TableName extends TableNames | SystemTableNames> =
GenericId<TableName>;

/**
Expand All @@ -55,4 +57,4 @@ export type Id<TableName extends TableNames = TableNames> =
* This type is used to parameterize methods like `queryGeneric` and
* `mutationGeneric` to make them type-safe.
*/
export type DataModel = AnyDataModel;
export type DataModel = DataModelFromSchemaDefinition<typeof schema>;
8 changes: 8 additions & 0 deletions convex/auth.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
export default {
providers: [
{
domain: process.env.CONVEX_SITE_URL,
applicationID: "convex",
},
],
};
63 changes: 63 additions & 0 deletions convex/auth.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import {
BetterAuth,
type AuthFunctions,
type PublicAuthFunctions,
} from "@convex-dev/better-auth";
import { api, components, internal } from "./_generated/api";
import { query } from "./_generated/server";
import type { Id, DataModel } from "./_generated/dataModel";

// Typesafe way to pass Convex functions defined in this file
const authFunctions: AuthFunctions = internal.auth
const publicAuthFunctions: PublicAuthFunctions = api.auth;

// Initialize the component
export const betterAuthComponent = new BetterAuth(
components.betterAuth,
{
authFunctions,
publicAuthFunctions,
}
);

// These are required named exports
export const {
createUser,
updateUser,
deleteUser,
createSession,
isAuthenticated,
} =
betterAuthComponent.createAuthFunctions<DataModel>({
// Must create a user and return the user id
onCreateUser: async (ctx, user) => {
return ctx.db.insert("users", {
capabilities: [],
});
},

// Delete the user when they are deleted from Better Auth
onDeleteUser: async (ctx, userId) => {
await ctx.db.delete(userId as Id<"users">);
},
});

// Example function for getting the current user
// Feel free to edit, omit, etc.
export const getCurrentUser = query({
args: {},
handler: async (ctx) => {
// Get user data from Better Auth - email, name, image, etc.
const userMetadata = await betterAuthComponent.getAuthUser(ctx);
if (!userMetadata) {
return null;
}
// Get user data from your application's database
// (skip this if you have no fields in your users table schema)
const user = await ctx.db.get(userMetadata.userId as Id<"users">);
return {
...user,
...userMetadata,
};
},
});
2 changes: 2 additions & 0 deletions convex/convex.config.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import { defineApp } from 'convex/server'
import ossStats from '@erquhart/convex-oss-stats/convex.config'
import betterAuth from '@convex-dev/better-auth/convex.config'

const app = defineApp()
app.use(ossStats)
app.use(betterAuth)

export default app
4 changes: 4 additions & 0 deletions convex/http.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
import { ossStats } from './stats'
import { httpRouter } from 'convex/server'

import { betterAuthComponent } from './auth'
import { createAuth } from '../src/libraries/auth'

const http = httpRouter()

ossStats.registerRoutes(http)
betterAuthComponent.registerRoutes(http, createAuth)

export default http
12 changes: 12 additions & 0 deletions convex/schema.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { defineSchema, defineTable } from "convex/server";
import { authTables } from "@convex-dev/auth/server";
import { v } from "convex/values";

const schema = defineSchema({
...authTables,
users: defineTable({
capabilities: v.array(v.string()),
})
});

export default schema
9 changes: 6 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@
"linkAll": "node scripts/link.js"
},
"dependencies": {
"@clerk/tanstack-react-start": "^0.21.7",
"@auth/core": "0.37.0",
"@convex-dev/auth": "^0.0.88",
"@convex-dev/better-auth": "^0.7.14",
"@convex-dev/react-query": "0.0.0-alpha.8",
"@erquhart/convex-oss-stats": "^0.5.5",
"@floating-ui/react": "^0.27.8",
Expand Down Expand Up @@ -50,8 +52,9 @@
"airtable": "^0.12.2",
"algoliasearch": "^5.23.4",
"axios": "^1.6.7",
"better-auth": "^1.3.7",
"cmdk": "^1.1.1",
"convex": "^1.17.2",
"convex": "^1.25.4",
"d3": "^7.9.0",
"date-fns": "^2.30.0",
"downshift": "^9.0.9",
Expand All @@ -76,7 +79,7 @@
"tailwind-merge": "^1.14.0",
"tiny-invariant": "^1.3.3",
"vite-tsconfig-paths": "^5.0.1",
"zod": "^3.23.8",
"zod": "^4.0.17",
"zustand": "^4.5.2"
},
"devDependencies": {
Expand Down
Loading