Skip to main content
User authentication

Auth built right into your backend

Fully transactional auth functions, with no third-party service to integrate.

Typesafe auth your agents won’t break

Get user authentication up and running in just a few lines of code. Sessions, tokens, and multiple auth methods, all built in.

  1. Register components

    import passkey from "@convex-dev/auth/components/passkey/convex.config.js";
    import username from "@convex-dev/auth/components/username/convex.config.js";
    
    const app = defineApp({ /* … */ });
    app.use(auth);
    app.use(passkey);
    app.use(username);
    
    export default app;

    NOTE: Simplified Example

  2. Configure passkeys

    import { setupUsernamePasskey } from "@convex-dev/auth/methods/username-passkey/server";
    
    export const {
      startSignInWithUsernamePasskey,
      startAutofillSignInWithUsernamePasskey,
      finishSignUpWithUsernamePasskey,
      finishSignInWithUsernamePasskey,
    } = setupUsernamePasskey(core, {
      component: components.authPasskey,
      usernameComponent: components.authUsername,
      rpId: "example.com",
      origin: "https://example.com",
    }).attachUserCallbacks({ createUser: internal.users.createUser });

    NOTE: Simplified Example

  3. Sign in

    import { useSignInWithUsernamePasskey } from "@convex-dev/auth/methods/username-passkey/react";
    
    export function LogIn() {
      const { signIn, pending } = useSignInWithUsernamePasskey(api.auth);
      const [username, setUsername] = useState("");
    
      return (
        <form onSubmit={(e) => { e.preventDefault(); signIn({ username }); }}>
          <input value={username} autoComplete="username webauthn"
            onChange={(e) => setUsername(e.target.value)} />
          <button disabled={pending}>Continue with a passkey</button>
        </form>
      );
    }

    NOTE: Simplified Example

convex/convex.config.tsSimplified Example
import passkey from "@convex-dev/auth/components/passkey/convex.config.js";
import username from "@convex-dev/auth/components/username/convex.config.js";

const app = defineApp({ /* … */ });
app.use(auth);
app.use(passkey);
app.use(username);

export default app;
convex/auth.tsSimplified Example
import { setupUsernamePasskey } from "@convex-dev/auth/methods/username-passkey/server";

export const {
  startSignInWithUsernamePasskey,
  startAutofillSignInWithUsernamePasskey,
  finishSignUpWithUsernamePasskey,
  finishSignInWithUsernamePasskey,
} = setupUsernamePasskey(core, {
  component: components.authPasskey,
  usernameComponent: components.authUsername,
  rpId: "example.com",
  origin: "https://example.com",
}).attachUserCallbacks({ createUser: internal.users.createUser });
src/LogIn.tsxSimplified Example
import { useSignInWithUsernamePasskey } from "@convex-dev/auth/methods/username-passkey/react";

export function LogIn() {
  const { signIn, pending } = useSignInWithUsernamePasskey(api.auth);
  const [username, setUsername] = useState("");

  return (
    <form onSubmit={(e) => { e.preventDefault(); signIn({ username }); }}>
      <input value={username} autoComplete="username webauthn"
        onChange={(e) => setUsername(e.target.value)} />
      <button disabled={pending}>Continue with a passkey</button>
    </form>
  );
}

Give your users the sign-in experience they expect

From passwords to passkeys, Convex Auth is ready.

Email & Password

Verification, recovery, and password change with re-auth.

import { components, internal } from "./_generated/api";
import { env } from "./_generated/server";
import { setupConvexAuth } from "@convex-dev/auth/server";
import { setupEmailPassword } from "@convex-dev/auth/methods/email-password/server";

// The frontend origin the emailed links point at. Set SITE_URL on the
// deployment when the frontend does not run on the Vite default.
const SITE_URL = env.SITE_URL ?? "http://localhost:5173";

const auth = setupConvexAuth({ component: components.auth });
export const { signOut, refreshSession, isAuthenticated } = auth;

export const {
  signUpWithEmailPassword,
  completeSignUpWithEmailPassword,
  signInWithEmailPassword,
  // changePassword, startChangeEmail, etc ...
} = setupEmailPassword(auth, {
  component: components.authEmail,
  passwordComponent: components.authPassword,
  emailSender: {
    kind: "resend",
    sendEmail: components.resend.lib.sendEmail,
    apiKey: env.RESEND_API_KEY,
    // SENDER_EMAIL must be on a domain you verified with Resend, or Resend's
    // onboarding sender (onboarding@resend.dev), which only delivers to the
    // email address of your own Resend account.
    from: `${env.SENDER_NAME ?? "My App"} <${env.SENDER_EMAIL}>`,
  },
  urls: {
    signUp: `${SITE_URL}/validate-email`,
    changeEmail: `${SITE_URL}/confirm-email-change`,
    recovery: `${SITE_URL}/reset-password`,
  },
}).attachUserCallbacks({
  createUser: internal.users.createUser,
});

Passkeys

Offer to users as a primary credential. List, rename, and revoke per user.

import { components, internal } from "./_generated/api";
import { setupConvexAuth } from "@convex-dev/auth/server";
import { setupUsernamePasskey } from "@convex-dev/auth/methods/username-passkey/server";

const auth = setupConvexAuth({ component: components.auth });
export const { signOut, refreshSession, isAuthenticated } = auth;

export const {
  startSignInWithUsernamePasskey,
  startAutofillSignInWithUsernamePasskey,
  finishSignUpWithUsernamePasskey,
  finishSignInWithUsernamePasskey,
  // listPasskeys, renamePasskey, etc ...
} = setupUsernamePasskey(auth, {
  component: components.authPasskey,
  usernameComponent: components.authUsername,
  // The relying party ID and the origin of the Vite dev server. A deployed
  // app uses its own domain here.
  rpId: "localhost",
  origin: "http://localhost:5173",
}).attachUserCallbacks({ createUser: internal.users.createUser });

Social logins

Sign in with Google, GitHub, Apple, or your own custom OAuth provider.

import { components, internal } from "./_generated/api";
import { setupConvexAuth } from "@convex-dev/auth/server";
import { setupGithub } from "@convex-dev/auth/methods/github/server";

const auth = setupConvexAuth({ component: components.auth });
export const { signOut, refreshSession, isAuthenticated } = auth;

export const { startSignInWithGithub, completeSignInWithGithub } = setupGithub(
  auth,
  {
    component: components.authGithub,
    allowedRedirectOrigins: ["http://localhost:5173"],
  },
).attachUserCallbacks({ createUser: internal.users.createUser });

Email & Password

Verification, recovery, and password change with re-auth.

convex/auth.ts
import { components, internal } from "./_generated/api";
import { env } from "./_generated/server";
import { setupConvexAuth } from "@convex-dev/auth/server";
import { setupEmailPassword } from "@convex-dev/auth/methods/email-password/server";

// The frontend origin the emailed links point at. Set SITE_URL on the
// deployment when the frontend does not run on the Vite default.
const SITE_URL = env.SITE_URL ?? "http://localhost:5173";

const auth = setupConvexAuth({ component: components.auth });
export const { signOut, refreshSession, isAuthenticated } = auth;

export const {
  signUpWithEmailPassword,
  completeSignUpWithEmailPassword,
  signInWithEmailPassword,
  // changePassword, startChangeEmail, etc ...
} = setupEmailPassword(auth, {
  component: components.authEmail,
  passwordComponent: components.authPassword,
  emailSender: {
    kind: "resend",
    sendEmail: components.resend.lib.sendEmail,
    apiKey: env.RESEND_API_KEY,
    // SENDER_EMAIL must be on a domain you verified with Resend, or Resend's
    // onboarding sender (onboarding@resend.dev), which only delivers to the
    // email address of your own Resend account.
    from: `${env.SENDER_NAME ?? "My App"} <${env.SENDER_EMAIL}>`,
  },
  urls: {
    signUp: `${SITE_URL}/validate-email`,
    changeEmail: `${SITE_URL}/confirm-email-change`,
    recovery: `${SITE_URL}/reset-password`,
  },
}).attachUserCallbacks({
  createUser: internal.users.createUser,
});

Secure by default

Convex ensures your app data is private by default. Nothing is reachable until you write a function to expose it.

  • Credentials never land in app code
  • Rate limits always enforced
  • Common passwords disallowed
  • SOC 2 Type 2 compliant
  • HIPAA compliant
  • GDPR verified
  • DDoS protection

FAQ

Didn’t Convex already have auth?

This is a full rebuild as a first-class Convex component. It’s transactional, fully supported, and built to run production at enterprise scale.

How much does Convex Auth cost?

Convex Auth comes included on all plans, with function and database usage billed at posted rates. No per-user pricing like other third party authentication providers.

What sign-in methods are supported?

Email and password, passkeys, and OAuth (Google, GitHub, Apple, and custom providers).

Do I still own my user data?

Yes. Your app owns the user table — its schema, fields, and indexes. Auth runs alongside it as a component, so credential internals stay isolated and can't be broken by an app-side change.

How is this different from Clerk or WorkOS?

Auth lives in your backend instead of a separate service, so there's no webhook lag and one source of truth for user data. Revocation is reactive and propagates to live clients instantly. And there's no per-user pricing.

Can I use Clerk or WorkOS with Convex if it’s already set up?

Yes. Clerk, WorkOS, and other OIDC providers still integrate with Convex. Keep your current setup and move to Convex Auth whenever you're ready.

Can I start without setting up any providers?

Yes. Password and passkey sign-in work with zero third-party accounts, so you can build and test right away. Add OAuth and email when you're ready.

What about SSO, SCIM, and orgs?

Generic OIDC covers most SSO setups today. SAML and SCIM aren't supported natively yet. If you need them now, you can use a provider like WorkOS with Convex in place of Convex Auth.

  • This is a full rebuild as a first-class Convex component. It’s transactional, fully supported, and built to run production at enterprise scale.

Build a production app this afternoon

Scale it for decades.

Set up Convex with your agent

Works great with any model, any agent, any editor

Set up Convex with your agent:

# Convex setup

Set up Convex in the current folder. Run the commands yourself, without asking the user.

- Empty folder: `npm create convex@latest . -- -t bare`
- Convex project (`convex` in `package.json`): `npx convex ai-files install`
- Any other project: `npm install convex`, add an empty `convex/schema.ts` and a `convex dev` script, then `npx convex ai-files install`. Never `npm create convex` here, it replaces the folder.

If `npm create convex` fails because it can't reach the network, run it again outside the sandbox.

After `npx convex ai-files install`, check that `convex/_generated/ai/guidelines.md` and `.agents/skills` exist. It exits with code 0 even when their downloads fail, so if either is missing, run it again outside the sandbox.

Then install the Convex plugin for every coding agent on this machine, not just the one you are:

- Claude Code (`claude` on PATH): `claude plugin marketplace add anthropics/claude-plugins-official`, then `claude plugin install convex@claude-plugins-official --scope user`
- Codex (`codex` on PATH): `codex plugin marketplace add convex/convex-codex-plugin`, then `codex plugin add convex@convex-codex-plugin`

Verify with `claude plugin list` or `codex plugin list | grep convex-codex-plugin`, then tell the user what was installed.

Works great with any model, any agent, any editor

Start a new Convex project

Build anything with Convex
Build a multiplayer YouTube app

Start a new Convex project: npm create convex@latest