Skip to content
Open
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
4 changes: 2 additions & 2 deletions .cursor/rules/convex_rules.mdc
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ globs: **/*.{ts,tsx,js,jsx}
- Index fields must be queried in the same order they are defined. If you want to be able to query by "field1" then "field2" and by "field2" then "field1", you must create separate indexes.

## Typescript guidelines
- You can use the helper typescript type `Id` imported from './_generated/dataModel' to get the type of the id for a given table. For example if there is a table called 'users' you can use `Id<'users'>` to get the type of the id for that table.
- You can use the helper typescript type `Id` imported from './_generated/dataModel' to get the type of the ID for a given table. For example if there is a table called 'users' you can use `Id<'users'>` to get the type of the ID for that table.
- If you need to define a `Record` make sure that you correctly provide the type of the key and value in the type. For example a validator `v.record(v.id('users'), v.string())` would have the type `Record<Id<'users'>, string>`. Below is an example of using `Record` with an `Id` type in a query:
```ts
import { query } from "./_generated/server";
Expand All @@ -192,7 +192,7 @@ globs: **/*.{ts,tsx,js,jsx}
},
});
```
- Be strict with types, particularly around id's of documents. For example, if a function takes in an id for a document in the 'users' table, take in `Id<'users'>` rather than `string`.
- Be strict with types, particularly around IDs of documents. For example, if a function takes in an ID for a document in the 'users' table, take in `Id<'users'>` rather than `string`.
- Always use `as const` for string literals in discriminated union types.
- When using the `Array` type, make sure to always define your arrays as `const array: Array<T> = [...];`
- When using the `Record` type, make sure to always define your records as `const record: Record<KeyType, ValueType> = {...};`
Expand Down
4 changes: 2 additions & 2 deletions docs/content/docs/authorization.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ description: Authorization with Better Auth
### Showing UI based on authentication state

You can control which UI is shown when the user is signed in or signed out using
Convex's `<Authenticated>`, `<Unauthenticated>` and `<AuthLoading>` helper
Convex's `<Authenticated>`, `<Unauthenticated>`, and `<AuthLoading>` helper
components. These components are powered by Convex's `useConvexAuth()` hook,
which provides `isAuthenticated` and `isLoading` flags. This hook can be used
directly if preferred.
Expand Down Expand Up @@ -71,7 +71,7 @@ export const getCurrentUser = query({
},
});

// You can also just get the authenticated user id as you
// You can also just get the authenticated user ID as you
// normally would from ctx.auth.getUserIdentity
export const getForCurrentUser = query({
args: {},
Expand Down
8 changes: 4 additions & 4 deletions docs/content/docs/basic-usage.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ project, so their guides are a primary reference.
There are a few areas in the Better Auth basic usage guide that work differently
in Convex.

- #### Server side authentication
- #### Server-side authentication

Better Auth supports signing users in and out through server side functions. Because
Better Auth supports signing users in and out through server-side functions. Because
Convex functions run over websockets and don't return HTTP responses or set
cookies, signing up/in/out must be done from the client via
`authClient.signIn.*` methods.
Expand All @@ -29,11 +29,11 @@ in Convex.
installs](/local-install), which support generating schemas. For projects not
using local install, the default schema provided with the Better Auth
component (preconfigured with the [supported
plugins](/supported-plugins)) is used, and cannot be altered.
plugins](/supported-plugins)) is used and cannot be altered.

## Using server methods with `auth.api`

Better Auth's server side `auth.api` methods can be used with your `createAuth`
Better Auth's server-side `auth.api` methods can be used with your `createAuth`
function and the component `headers` method. Here's an example implementing the [`changePassword` server
method](https://www.better-auth.com/docs/concepts/users-accounts#api-method-change-password).

Expand Down
4 changes: 2 additions & 2 deletions docs/content/docs/debugging.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ export const authComponent = createClient(
);
```

## Client side
## Client-side

Verbose logs in the client can be enabled on the Convex client constructor.

```ts title="src/main.ts"
// Replace this with your framework prefixed environment variable
// Replace this with your framework-prefixed environment variable
// for your project's Convex cloud URL
const convexUrl = import.meta.env.PUBLIC_CONVEX_URL as string;
const convex = new ConvexReactClient(convexUrl, {
Expand Down
6 changes: 3 additions & 3 deletions docs/content/docs/framework-guides/expo.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ description: Install and configure Convex + Better Auth for Expo.
<div className="fd-step">
### Set environment variables

Generate a secret for encryption and generating hashes. Use the command below if you have openssl installed, or use the button to generate a random value instead. Or generate your own however you like.
Generate a secret for encryption and generating hashes. Use the command below if you have OpenSSL installed, or use the button to generate a random value instead. Or generate your own however you like.

```shell
npx convex env set BETTER_AUTH_SECRET=$(openssl rand -base64 32)
Expand Down Expand Up @@ -128,8 +128,8 @@ description: Install and configure Convex + Better Auth for Expo.
{ optionsOnly } = { optionsOnly: false },
) => {
return betterAuth({
// disable logging when createAuth is called just to generate options.
// this is not required, but there's a lot of noise in logs without it.
// Disable logging when createAuth is called just to generate options.
// This is not required, but there's a lot of noise in logs without it.
logger: {
disabled: optionsOnly,
},
Expand Down
6 changes: 3 additions & 3 deletions docs/content/docs/framework-guides/next.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ description: Install and configure Convex + Better Auth for Next.js.
<div className="fd-step">
### Set environment variables

Generate a secret for encryption and generating hashes. Use the command below if you have openssl installed, or use the button to generate a random value instead. Or generate your own however you like.
Generate a secret for encryption and generating hashes. Use the command below if you have OpenSSL installed, or use the button to generate a random value instead. Or generate your own however you like.

```shell
npx convex env set BETTER_AUTH_SECRET=$(openssl rand -base64 32)
Expand Down Expand Up @@ -134,8 +134,8 @@ description: Install and configure Convex + Better Auth for Next.js.
{ optionsOnly } = { optionsOnly: false },
) => {
return betterAuth({
// disable logging when createAuth is called just to generate options.
// this is not required, but there's a lot of noise in logs without it.
// Disable logging when createAuth is called just to generate options.
// This is not required, but there's a lot of noise in logs without it.
logger: {
disabled: optionsOnly,
},
Expand Down
10 changes: 5 additions & 5 deletions docs/content/docs/framework-guides/react.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ description: Install and configure Convex + Better Auth for React.
<div className="fd-step">
### Set environment variables

Generate a secret for encryption and generating hashes. Use the command below if you have openssl installed, or use the button to generate a random value instead. Or generate your own however you like.
Generate a secret for encryption and generating hashes. Use the command below if you have OpenSSL installed, or use the button to generate a random value instead. Or generate your own however you like.

```shell
npx convex env set BETTER_AUTH_SECRET=$(openssl rand -base64 32)
Expand Down Expand Up @@ -134,8 +134,8 @@ description: Install and configure Convex + Better Auth for React.
{ optionsOnly } = { optionsOnly: false },
) => {
return betterAuth({
// disable logging when createAuth is called just to generate options.
// this is not required, but there's a lot of noise in logs without it.
// Disable logging when createAuth is called just to generate options.
// This is not required, but there's a lot of noise in logs without it.
logger: {
disabled: optionsOnly,
},
Expand All @@ -147,7 +147,7 @@ description: Install and configure Convex + Better Auth for React.
requireEmailVerification: false,
},
plugins: [
// The cross domain plugin is required for client side frameworks
// The cross-domain plugin is required for client-side frameworks
crossDomain({ siteUrl }),
// The Convex plugin is required for Convex compatibility
convex(),
Expand Down Expand Up @@ -198,7 +198,7 @@ description: Install and configure Convex + Better Auth for React.

const http = httpRouter();

// CORS handling is required for client side frameworks
// CORS handling is required for client-side frameworks
authComponent.registerRoutes(http, createAuth, { cors: true });

export default http;
Expand Down
8 changes: 4 additions & 4 deletions docs/content/docs/framework-guides/tanstack-start.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ description: Install and configure Convex + Better Auth for TanStack Start.
<div className="fd-step">
### Set environment variables

Generate a secret for encryption and generating hashes. Use the command below if you have openssl installed, or use the button to generate a random value instead. Or generate your own however you like.
Generate a secret for encryption and generating hashes. Use the command below if you have OpenSSL installed, or use the button to generate a random value instead. Or generate your own however you like.

```shell
npx convex env set BETTER_AUTH_SECRET=$(openssl rand -base64 32)
Expand Down Expand Up @@ -135,8 +135,8 @@ description: Install and configure Convex + Better Auth for TanStack Start.
{ optionsOnly } = { optionsOnly: false },
) => {
return betterAuth({
// disable logging when createAuth is called just to generate options.
// this is not required, but there's a lot of noise in logs without it.
// Disable logging when createAuth is called just to generate options.
// This is not required, but there's a lot of noise in logs without it.
logger: {
disabled: optionsOnly,
},
Expand Down Expand Up @@ -278,7 +278,7 @@ description: Install and configure Convex + Better Auth for TanStack Start.
}),
// [!code ++:14]
beforeLoad: async (ctx) => {
// all queries, mutations and action made with TanStack Query will be
// All queries, mutations, and actions made with TanStack Query will be
// authenticated by an identity token.
const { userId, token } = await fetchAuth()

Expand Down
2 changes: 1 addition & 1 deletion docs/content/docs/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ docs](https://docs.convex.dev/home) to learn more about Convex.
<div className="fd-step">
### Run `convex dev`

Running the cli during setup will initialize your Convex deployment if it
Running the CLI during setup will initialize your Convex deployment if it
doesn't already exist, and keeps generated types current through the process.
Keep it running.

Expand Down
2 changes: 1 addition & 1 deletion docs/content/docs/integrations/hono.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export default http;

## Add CORS support

Required for client only / SPA installs like React/Vite.
Required for client-only / SPA installs like React/Vite.

```ts title="convex/http.ts"
import { Hono } from "hono";
Expand Down
8 changes: 4 additions & 4 deletions docs/content/docs/local-install.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ Local install gives you full control over your Better Auth schema, allows schema
related configuration to work, and makes it possible to use plugins beyond those
[supported](/supported-plugins) for Convex + Better Auth.

With this approach, the Better Auth plugin is defined in it's own Convex
subdirectory. Installation is a bit different from the default approach, and
With this approach, the Better Auth plugin is defined in its own Convex
subdirectory. Installation is a bit different from the default approach and
includes a schema generation step via Better Auth CLI, similar to the
installation experience with other providers.

Expand Down Expand Up @@ -144,7 +144,7 @@ installed component.

### Updating the schema

Certain options changes may require schema generation. The Better Auth docs will
Certain option changes may require schema generation. The Better Auth docs will
often note when this is the case. To regenerate the schema at any time (as it's
generally safe to do), move into the component directory and run the Better Auth
CLI generate command.
Expand All @@ -168,7 +168,7 @@ custom indexes aren't overwritten when the schema is regenerated.
<Callout>
Schema table names and fields should not be customized directly, as any
customizations won't match your Better Auth configuration, and will be
overwritten when the schema is regenerated. Instead, Better Auth schema can be
overwritten when the schema is regenerated. Instead, Better Auth's schema can be
[customized through
options](https://www.better-auth.com/docs/concepts/database#core-schema).
</Callout>
Expand Down
20 changes: 10 additions & 10 deletions docs/content/docs/migrate-to-0-8.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -122,9 +122,9 @@ description: Migrate to @convex-dev/[email protected]
### Move and update Better Auth config

The `createAuth` function should be moved to `convex/auth.ts`. This isn't
required, but better represents where the code actually runs, colocates it
with other related server side auth code, and avoids potentially writing
Convex code outside of the Convex directory for some function based config
required, but it better represents where the code actually runs, colocates it
with other related server-side auth code, and avoids potentially writing
Convex code outside of the Convex directory for some function-based config
properties.

The Convex database adapter is now provided through a method on the auth
Expand Down Expand Up @@ -177,9 +177,9 @@ This is not required, but helpful for reducing noise in logs.

### Update `ctx.auth.getUserIdentity()` usage

The `subject` property of the id token, as well as the user identity object returned from
`ctx.auth.getUserIdentity()`, was formerly the user id from the application user
table. It is now the user id from the Better Auth user table. Any direct usage
The `subject` property of the ID token, as well as the user identity object returned from
`ctx.auth.getUserIdentity()`, was formerly the user ID from the application user
table. It is now the user ID from the Better Auth user table. Any direct usage
of the `subject` property should be replaced with
`authComponent.getAuthUser(ctx)`, which returns the entire Better Auth user
object (formerly referred to as user metadata).
Expand Down Expand Up @@ -234,13 +234,13 @@ export const getCurrentUser = query({
</div>

<div className="fd-step">
### Framework specific changes
### Framework-specific changes

If your project uses TanStack Start, follow the [last few
steps](/framework-guides/tanstack-start#mount-handlers)
of the TanStack Start guide and make sure your code aligns.

This migration should not have framework specific impacts for any other
This migration should not have framework-specific impacts for any other
framework.

</div>
Expand All @@ -265,10 +265,10 @@ channel on Discord.
The named `options` parameter to the Convex plugin that accepted Better Auth
options has been removed. This was necessary because the Convex plugin
previously customized the session, breaking type inference for configuration
that affected the session, so the Better Auth options had to be separated to a
that affected the session, so the Better Auth options had to be separated into a
new function and passed in to the Convex plugin.

None of this is necessary anymore, if you were doing this you can go back to
None of this is necessary anymore; if you were doing this you can go back to
using a single `createAuth` function.

```ts title="convex/auth.ts"
Expand Down
4 changes: 2 additions & 2 deletions examples/next/.cursor/rules/convex_rules.mdc
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ Note: `paginationOpts` is an object with the following properties:
- Index fields must be queried in the same order they are defined. If you want to be able to query by "field1" then "field2" and by "field2" then "field1", you must create separate indexes.

## Typescript guidelines
- You can use the helper typescript type `Id` imported from './_generated/dataModel' to get the type of the id for a given table. For example if there is a table called 'users' you can use `Id<'users'>` to get the type of the id for that table.
- You can use the helper typescript type `Id` imported from './_generated/dataModel' to get the type of the ID for a given table. For example if there is a table called 'users' you can use `Id<'users'>` to get the type of the ID for that table.
- If you need to define a `Record` make sure that you correctly provide the type of the key and value in the type. For example a validator `v.record(v.id('users'), v.string())` would have the type `Record<Id<'users'>, string>`. Below is an example of using `Record` with an `Id` type in a query:
```ts
import { query } from "./_generated/server";
Expand All @@ -208,7 +208,7 @@ export const exampleQuery = query({
},
});
```
- Be strict with types, particularly around id's of documents. For example, if a function takes in an id for a document in the 'users' table, take in `Id<'users'>` rather than `string`.
- Be strict with types, particularly around IDs of documents. For example, if a function takes in an ID for a document in the 'users' table, take in `Id<'users'>` rather than `string`.
- Always use `as const` for string literals in discriminated union types.
- When using the `Array` type, make sure to always define your arrays as `const array: Array<T> = [...];`
- When using the `Record` type, make sure to always define your records as `const record: Record<KeyType, ValueType> = {...};`
Expand Down
2 changes: 1 addition & 1 deletion examples/tanstack/src/utils/posts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export type PostType = {
export const fetchPost = createServerFn({ method: 'GET' })
.validator((postId: string) => postId)
.handler(async ({ data }) => {
console.info(`Fetching post with id ${data}...`)
console.info(`Fetching post with ID ${data}...`)
const post = await axios
.get<PostType>(`https://jsonplaceholder.typicode.com/posts/${data}`)
.then((r) => r.data)
Expand Down
2 changes: 1 addition & 1 deletion src/client/adapter.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ describe("Convex Adapter Tests", async () => {
).toEqual([user]);
});

test("should handle compound indexes that include id field", async () => {
test("should handle compound indexes that include an ID field", async () => {
const t = convexTest(schema, import.meta.glob("../component/**/*.*s"));
const adapter = await getAdapter(t)();
const user = await adapter.create({
Expand Down
2 changes: 1 addition & 1 deletion src/client/adapterUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -532,7 +532,7 @@ export const paginate = async <
if (!Array.isArray(inWhere.value)) {
throw new Error("in clause value must be an array");
}
// For ids, just use asyncMap + .get()
// For IDs, just use asyncMap + .get()
if (inWhere.field === "id") {
const docs = await asyncMap(inWhere.value as any[], async (value) => {
return ctx.db.get(value as GenericId<T>);
Expand Down
2 changes: 1 addition & 1 deletion src/client/createSchema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ export const tables = {
const table = tables[tableKey]!;
const modelName = table.modelName;

// No id fields in Convex schema
// No ID fields in Convex schema
const fields = Object.fromEntries(
Object.entries(table.fields).filter(([key]) => key !== "id")
);
Expand Down
2 changes: 1 addition & 1 deletion src/client/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -497,7 +497,7 @@ export const createClient = <
return user;
},

// Replaces 0.7 behavior of returning a new user id from
// Replaces 0.7 behavior of returning a new user ID from
// onCreateUser
setUserId: async (
ctx: GenericMutationCtx<DataModel>,
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/convex/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export const convex = (
},
});
// Bearer plugin converts the session token to a cookie
// for cross domain social login after code verification,
// for cross-domain social login after code verification,
// and is required for the headers() helper to work.
const bearer = bearerPlugin();
const schema = {
Expand Down