mirror of
https://github.com/stack-auth/stack.git
synced 2026-06-04 21:04:37 +08:00
## Stack Auth → Hexclave rename — PR 5 (internal symbols, paths,
packages, brand strings)
PR 5 finishes the **internal / non-wire** half of the Stack→Hexclave
rename. It only touches things where nothing outside the repo depends on
the exact name: internal symbols, file/dir names, the
`@stackframe/template` package, and residual brand strings. Plan +
progress are in `HEXCLAVE-RENAME-PR5-PLAN.md`.
Every step was verified green (`pnpm typecheck` + `pnpm lint`, 28/28)
and committed as its own checkpoint, then a fan-out of review agents
audited all commits and the findings were fixed.
### What changed
- **Internal symbols** (`@hexclave/shared`, `packages/template`, apps):
`stack*`/`Stack*` → `hexclave*`/`Hexclave*` — incl.
`stackGlobalsSymbol`, the `_Stack*AppImpl` classes,
`stackAppInternalsSymbol`, `StackContext`, `getStackStripe`, etc. The
`stack*App` local-variable convention
(`stackServerApp`/`stackClientApp`/…) was renamed across 175
source/example/doc files.
- **File renames**: `hexclave-handler/provider/context.tsx`,
`backend/hexclave.tsx`, `internal-tool/hexclave.ts`,
`hexclave-app-internals.ts`.
- **Directory renames**: `lib/hexclave-app`, `hexclave-companion`,
`[...hexclave]` route segment, `skills/hexclave`,
`dashboard/src/hexclave`, and the package dirs
**`packages/{next,shared,ui,sc,cli}`** (dropping the `stack-` prefix to
match the `@hexclave/*` npm names).
- **Packages**: `@stackframe/template` → `@hexclave/template`; **deleted
`packages/init-stack`** (onboarding lives in `@hexclave/cli init`; the
published npm package is untouched).
- **Brand strings**: reworded `Stack Auth`/`Stack dashboard` prose in
code + docs-mintlify, renamed `hexclave-app.mdx`/`use-hexclave-app.mdx`
with redirects, regenerated OpenAPI, updated coupled e2e assertions;
`doctor`/`init` now prefer `hexclave.config.ts`.
### Intentionally kept (verified, not oversights)
Wire/compat identifiers (`x-stack-*` headers, `stack-*` cookies,
`STACK_*` env names, `*.stack-auth.com`, `stackauth_`, `ask_stack_auth`,
query params), public `Stack*` SDK aliases, crypto/JWT/vault
domain-separation tags, `*-brand-sentinel`s, the
`Symbol.for("StackAuth--…")` string, `_stack_sync_metadata`, Postgres
`stackframe` / docker image names, the `stack-auth-logo*.svg` (used by
the rebrand modal), and `migration.mdx` / "formerly known as Stack Auth"
notes. False positives (Phosphor `StackIcon`/`StackSimple`, `TanStack`,
`OrbStack`, `stackable`/`Stacked` charts) left alone.
### Review pass
Six review agents audited all commits. Found + fixed one real bug — a
build script (`bundle-type-definitions.ts`) hardcoded the old
`lib/stack-app` glob path (not an import, so typecheck/lint were blind),
silently emptying the dashboard AI type bundle — plus stale comments, a
dead CI env var, and stale `.gitignore`/`.dockerignore` entries.
Cross-cutting audit confirmed **zero wire-compat identifiers were
accidentally renamed**.
### ⚠️ Verification note
`typecheck` + `lint` are fully green locally. The **e2e suite was not
run** (needs a live backend+DB), so the brand-string assertion +
OpenAPI-regen changes are verified by grep/codegen only — please let CI
exercise e2e to confirm.
### Base-branch note
This branch was forked from the local-only `cl/friendly-lewin-72293f`
(not on origin, no separate PR), so this PR against `dev` also carries
that branch's ~11 preceding Hexclave-rename commits (config-file rename,
env-var dual-read, AI setup-prompt rebrand). If those should land
separately, re-parent before merge.
<!-- This is an auto-generated description by cubic. -->
---
## Summary by cubic
Finishes the internal Stack Auth → Hexclave rename and cleans up
remaining stragglers, including dev-tool and prompt copy. All changes
are internal-only; public/wire APIs remain unchanged. Re-merged `dev`
and resolved the payments create-purchase-url conflict.
- **Refactors**
- Internal symbols: stack*/Stack* → hexclave*/Hexclave* (e.g.,
`getHexclaveServerApp` via `@/hexclave`, `getHexclaveStripe`,
`hexclaveAppInternalsSymbol`, `hexclaveSchemaInfo`, Prisma
`__hexclave_*`, `data-hexclave-handler-page`, Stripe mock
`hexclavePortPrefix`).
- Files/dirs: moved to `lib/hexclave-app`; handler route
`[...hexclave]`; backend entry `src/hexclave.tsx`; dashboard internals
`hexclave-app-internals`; companion `hexclave-companion`; dropped
`stack-` prefix across package dirs
(`packages/{shared,ui,sc,cli,next}`); workflows/emulator paths now
`packages/cli`; Quetzal codegen env at `packages/next/.env.local`.
- Packages/docs: `@stackframe/template` → `@hexclave/template`; removed
`packages/init-stack`; regenerated OpenAPI and updated docs
slugs/redirects for hexclave-app/use-hexclave-app.
- Brand strings/prompts: reworded remaining “Stack” dashboard strings to
Hexclave; updated dev-tool copy and prompts; `doctor/init` now prefer
`hexclave.config.ts`. Kept all wire-compat identifiers and public
aliases (`x-stack-*`, `stack-*` cookies, `STACK_*` env,
`*.stack-auth.com`, `Stack*` SDK names).
- Rebased/merged onto latest `dev`: retained `@hexclave/template`, kept
`src` in published files, refreshed setup-prompt imports and docs JSON,
adopted 1.0.5 version bumps, and re-merged `dev` again (resolved
`create-purchase-url` with `getHexclaveStripe`).
- **Bug Fixes**
- Restored dashboard AI type bundle by pointing the glob to
`packages/template/src/lib/hexclave-app`.
- Addressed rename leftovers: updated lingering `@/stack` imports and
CSS selector, fixed schema/meta and port-prefix expansions, and aligned
emulator commands to `packages/cli`.
- CI/build: removed a dead env var and stale ignore entries; fixed
Docker by renaming `STACK_SKIP_TEMPLATE_GENERATION` →
`HEXCLAVE_SKIP_TEMPLATE_GENERATION`.
<sup>Written for commit 3c1af3bff3.
Summary will update on new commits.</sup>
<a
href="https://cubic.dev/pr/hexclave/hexclave/pull/1547?utm_source=github"
target="_blank" rel="noopener noreferrer"
data-no-image-dialog="true"><picture><source
media="(prefers-color-scheme: dark)"
srcset="https://cubic.dev/buttons/review-in-cubic-dark.svg"><source
media="(prefers-color-scheme: light)"
srcset="https://cubic.dev/buttons/review-in-cubic-light.svg"><img
alt="Review in cubic"
src="https://cubic.dev/buttons/review-in-cubic-dark.svg"></picture></a>
<!-- End of auto-generated description by cubic. -->
1132 lines
30 KiB
Plaintext
1132 lines
30 KiB
Plaintext
---
|
|
title: "StackApp"
|
|
description: "Reference documentation for HexclaveClientApp and HexclaveServerApp objects."
|
|
sidebarTitle: "StackApp"
|
|
mode: "wide"
|
|
---
|
|
|
|
import {
|
|
AsideSection,
|
|
ContentSection,
|
|
MethodAside,
|
|
MethodContent,
|
|
MethodLayout,
|
|
MethodReturns,
|
|
} from "/snippets/sdk-type-components.jsx";
|
|
|
|
This is a detailed reference for the `StackApp` object. For setup instructions, see [Setup](/guides/getting-started/setup).
|
|
|
|
## Overview
|
|
|
|
- [HexclaveClientApp](#stackclientapp) - Client-level permissions for frontend code
|
|
- [HexclaveServerApp](#stackserverapp) - Server-level permissions with full access
|
|
|
|
---
|
|
|
|
# HexclaveClientApp
|
|
|
|
A `StackApp` with client-level permissions. It contains most of the useful methods and hooks for your client-side code.
|
|
|
|
Most commonly you get an instance of `HexclaveClientApp` by calling [`useHexclaveApp()`](/sdk/hooks/use-hexclave-app) in a Client Component.
|
|
|
|
## Table of Contents
|
|
|
|
```typescript
|
|
type HexclaveClientApp = {
|
|
new(options): HexclaveClientApp;
|
|
|
|
getUser([options]): Promise<User>;
|
|
useUser([options]): User;
|
|
getProject(): Promise<Project>;
|
|
useProject(): Project;
|
|
|
|
signInWithOAuth(provider): void;
|
|
signInWithCredential([options]): Promise<...>;
|
|
signUpWithCredential([options]): Promise<...>;
|
|
sendForgotPasswordEmail(email): Promise<...>;
|
|
sendMagicLinkEmail(email): Promise<...>;
|
|
};
|
|
```
|
|
|
|
## Constructor
|
|
|
|
Creates a new `HexclaveClientApp` instance.
|
|
|
|
Because each app creates a new connection to Hexclave's backend, you should re-use existing instances wherever possible.
|
|
|
|
<Info>
|
|
This object is not usually constructed directly. More commonly, you would construct a [`HexclaveServerApp`](#stackserverapp) instead, pass it into your app setup (see the [setup guide](/guides/getting-started/setup)), and then use the `useHexclaveApp()` hook to obtain a `HexclaveClientApp`.
|
|
|
|
The [setup wizard](/guides/getting-started/setup) does these steps for you, so you don't need to worry about it unless you are manually setting up Hexclave.
|
|
|
|
If you're building a client-only app and don't have a `SECRET_SERVER_KEY`, you can construct a `HexclaveClientApp` directly.
|
|
|
|
</Info>
|
|
|
|
<MethodLayout>
|
|
<MethodContent>
|
|
<ContentSection title="Parameters">
|
|
<ParamField body="tokenStore" type='"nextjs-cookie" | "cookie" | { accessToken, refreshToken } | Request' required>
|
|
Token storage configuration.
|
|
</ParamField>
|
|
|
|
<ParamField body="baseUrl" type="string">
|
|
Base URL for the Hexclave API.
|
|
</ParamField>
|
|
|
|
<ParamField body="projectId" type="string">
|
|
Project ID. Defaults to the `NEXT_PUBLIC_STACK_PROJECT_ID` environment variable.
|
|
</ParamField>
|
|
|
|
<ParamField body="publishableClientKey" type="string">
|
|
Publishable client key. Defaults to the `NEXT_PUBLIC_STACK_PUBLISHABLE_CLIENT_KEY` environment variable.
|
|
</ParamField>
|
|
|
|
<ParamField body="urls" type="object">
|
|
Redirect URL configuration.
|
|
</ParamField>
|
|
|
|
<ParamField body="noAutomaticPrefetch" type="boolean">
|
|
Disable automatic prefetching.
|
|
</ParamField>
|
|
</ContentSection>
|
|
|
|
</MethodContent>
|
|
|
|
<MethodAside>
|
|
<AsideSection title="Signature">
|
|
```typescript
|
|
declare class HexclaveClientApp {
|
|
constructor(options: {
|
|
tokenStore: "nextjs-cookie" | "cookie" | {
|
|
accessToken: string;
|
|
refreshToken: string;
|
|
} | Request;
|
|
baseUrl?: string;
|
|
projectId?: string;
|
|
publishableClientKey?: string;
|
|
urls?: object;
|
|
noAutomaticPrefetch?: boolean;
|
|
});
|
|
}
|
|
```
|
|
</AsideSection>
|
|
|
|
<AsideSection title="Examples">
|
|
```typescript
|
|
const hexclaveClientApp = new HexclaveClientApp({
|
|
tokenStore: "nextjs-cookie",
|
|
baseUrl: "https://api.hexclave.com",
|
|
projectId: "123",
|
|
publishableClientKey: "123",
|
|
urls: {
|
|
home: "/",
|
|
},
|
|
});
|
|
```
|
|
|
|
```typescript
|
|
"use client";
|
|
|
|
function MyReactComponent() {
|
|
const hexclaveClientApp = useHexclaveApp();
|
|
}
|
|
```
|
|
</AsideSection>
|
|
|
|
</MethodAside>
|
|
</MethodLayout>
|
|
|
|
## User Management
|
|
|
|
### `hexclaveClientApp.getUser([options])`
|
|
|
|
<MethodLayout>
|
|
<MethodContent>
|
|
Gets the current user.
|
|
|
|
<ContentSection title="Parameters">
|
|
<ParamField body="options.or" type='"return-null" | "redirect" | "throw"'>
|
|
What to do if the user is not found.
|
|
</ParamField>
|
|
</ContentSection>
|
|
|
|
<MethodReturns type="Promise<CurrentUser | null>" />
|
|
|
|
</MethodContent>
|
|
|
|
<MethodAside>
|
|
<AsideSection title="Signature">
|
|
```typescript
|
|
declare function getUser(options?: {
|
|
or?: "return-null" | "redirect" | "throw";
|
|
}): Promise<CurrentUser | null>;
|
|
```
|
|
</AsideSection>
|
|
|
|
<AsideSection title="Examples">
|
|
```typescript
|
|
const userOrNull = await hexclaveClientApp.getUser();
|
|
console.log(userOrNull);
|
|
|
|
const user = await hexclaveClientApp.getUser({ or: "redirect" });
|
|
console.log(user);
|
|
```
|
|
</AsideSection>
|
|
|
|
</MethodAside>
|
|
</MethodLayout>
|
|
|
|
### `hexclaveClientApp.useUser([options])`
|
|
|
|
<MethodLayout>
|
|
<MethodContent>
|
|
React hook version of `getUser()`. Equivalent to the [`useUser()`](/sdk/hooks/use-user) standalone hook, which is an alias for `useHexclaveApp().useUser()`.
|
|
|
|
<ContentSection title="Parameters">
|
|
<ParamField body="options.or" type='"return-null" | "redirect" | "throw"'>
|
|
What to do if the user is not found.
|
|
</ParamField>
|
|
</ContentSection>
|
|
|
|
<MethodReturns type="CurrentUser | null" />
|
|
|
|
</MethodContent>
|
|
|
|
<MethodAside>
|
|
<AsideSection title="Signature">
|
|
```typescript
|
|
declare function useUser(options?: {
|
|
or?: "return-null" | "redirect" | "throw";
|
|
}): CurrentUser | null;
|
|
```
|
|
</AsideSection>
|
|
|
|
<AsideSection title="Examples">
|
|
```jsx
|
|
"use client";
|
|
|
|
function MyReactComponent() {
|
|
const user = useUser();
|
|
return user ? <div>Hello, {user.name}</div> : <div>Not signed in</div>;
|
|
}
|
|
```
|
|
|
|
```tsx
|
|
"use client";
|
|
|
|
function MyProtectedComponent() {
|
|
useUser({ or: "redirect" });
|
|
return <div>You can only see this if you are authenticated</div>;
|
|
}
|
|
```
|
|
</AsideSection>
|
|
|
|
</MethodAside>
|
|
</MethodLayout>
|
|
|
|
### `hexclaveClientApp.getProject()`
|
|
|
|
<MethodLayout>
|
|
<MethodContent>
|
|
Gets the current project.
|
|
|
|
<MethodReturns type="Promise<Project>" />
|
|
|
|
</MethodContent>
|
|
|
|
<MethodAside>
|
|
<AsideSection title="Signature">
|
|
```typescript
|
|
declare function getProject(): Promise<Project>;
|
|
```
|
|
</AsideSection>
|
|
|
|
<AsideSection title="Examples">
|
|
```typescript
|
|
const project = await hexclaveClientApp.getProject();
|
|
```
|
|
</AsideSection>
|
|
|
|
</MethodAside>
|
|
</MethodLayout>
|
|
|
|
### `hexclaveClientApp.useProject()`
|
|
|
|
<MethodLayout>
|
|
<MethodContent>
|
|
React hook version of `getProject()`.
|
|
|
|
<MethodReturns type="Project" />
|
|
|
|
</MethodContent>
|
|
|
|
<MethodAside>
|
|
<AsideSection title="Signature">
|
|
```typescript
|
|
declare function useProject(): Project;
|
|
```
|
|
</AsideSection>
|
|
|
|
<AsideSection title="Examples">
|
|
```typescript
|
|
function MyReactComponent() {
|
|
const project = useProject();
|
|
}
|
|
```
|
|
</AsideSection>
|
|
|
|
</MethodAside>
|
|
</MethodLayout>
|
|
|
|
## Authentication
|
|
|
|
### `hexclaveClientApp.signInWithOAuth(provider)`
|
|
|
|
<MethodLayout>
|
|
<MethodContent>
|
|
Initiates the OAuth sign-in process with the specified provider.
|
|
|
|
<ContentSection title="Parameters">
|
|
<ParamField body="provider" type="string">
|
|
The OAuth provider type.
|
|
</ParamField>
|
|
</ContentSection>
|
|
|
|
<MethodReturns type="Promise<void>" />
|
|
|
|
</MethodContent>
|
|
|
|
<MethodAside>
|
|
<AsideSection title="Signature">
|
|
```typescript
|
|
declare function signInWithOAuth(provider: string): Promise<void>;
|
|
```
|
|
</AsideSection>
|
|
|
|
<AsideSection title="Examples">
|
|
```typescript
|
|
await hexclaveClientApp.signInWithOAuth("google");
|
|
```
|
|
</AsideSection>
|
|
|
|
</MethodAside>
|
|
</MethodLayout>
|
|
|
|
### `hexclaveClientApp.signInWithCredential([options])`
|
|
|
|
<MethodLayout>
|
|
<MethodContent>
|
|
Sign in using email and password credentials.
|
|
|
|
<ContentSection title="Parameters">
|
|
<ParamField body="options.email" type="string">
|
|
User's email.
|
|
</ParamField>
|
|
|
|
<ParamField body="options.password" type="string">
|
|
User's password.
|
|
</ParamField>
|
|
|
|
<ParamField body="options.noRedirect" type="boolean">
|
|
Whether to skip redirect after sign-in.
|
|
</ParamField>
|
|
</ContentSection>
|
|
|
|
<MethodReturns type='Promise<Result<undefined, KnownErrors["EmailPasswordMismatch"]>>' />
|
|
|
|
</MethodContent>
|
|
|
|
<MethodAside>
|
|
<AsideSection title="Signature">
|
|
```typescript
|
|
declare function signInWithCredential(options?: {
|
|
email?: string;
|
|
password?: string;
|
|
noRedirect?: boolean;
|
|
}): Promise<Result<undefined, KnownErrors["EmailPasswordMismatch"]>>;
|
|
```
|
|
</AsideSection>
|
|
|
|
<AsideSection title="Examples">
|
|
```typescript
|
|
const result = await hexclaveClientApp.signInWithCredential({
|
|
email: "test@example.com",
|
|
password: "password",
|
|
});
|
|
|
|
if (result.status === "error") {
|
|
console.error("Sign in failed", result.error.message);
|
|
}
|
|
```
|
|
</AsideSection>
|
|
|
|
</MethodAside>
|
|
</MethodLayout>
|
|
|
|
### `hexclaveClientApp.signUpWithCredential([options])`
|
|
|
|
<MethodLayout>
|
|
<MethodContent>
|
|
Sign up using email and password credentials.
|
|
|
|
<ContentSection title="Parameters">
|
|
<ParamField body="options.email" type="string">
|
|
User's email.
|
|
</ParamField>
|
|
|
|
<ParamField body="options.password" type="string">
|
|
User's password.
|
|
</ParamField>
|
|
|
|
<ParamField body="options.noRedirect" type="boolean">
|
|
Whether to skip redirect after sign-up.
|
|
</ParamField>
|
|
</ContentSection>
|
|
|
|
<MethodReturns type='Promise<Result<undefined, KnownErrors["UserWithEmailAlreadyExists"] | KnownErrors["PasswordRequirementsNotMet"]>>' />
|
|
|
|
</MethodContent>
|
|
|
|
<MethodAside>
|
|
<AsideSection title="Signature">
|
|
```typescript
|
|
declare function signUpWithCredential(options?: {
|
|
email?: string;
|
|
password?: string;
|
|
noRedirect?: boolean;
|
|
}): Promise<Result<
|
|
undefined,
|
|
KnownErrors["UserWithEmailAlreadyExists"] | KnownErrors["PasswordRequirementsNotMet"]
|
|
>>;
|
|
```
|
|
</AsideSection>
|
|
|
|
<AsideSection title="Examples">
|
|
```typescript
|
|
const result = await hexclaveClientApp.signUpWithCredential({
|
|
email: "test@example.com",
|
|
password: "password",
|
|
});
|
|
|
|
if (result.status === "error") {
|
|
console.error("Sign up failed", result.error.message);
|
|
}
|
|
```
|
|
</AsideSection>
|
|
|
|
</MethodAside>
|
|
</MethodLayout>
|
|
|
|
### `hexclaveClientApp.sendForgotPasswordEmail(email)`
|
|
|
|
<MethodLayout>
|
|
<MethodContent>
|
|
Send a forgot-password email to an email address.
|
|
|
|
<ContentSection title="Parameters">
|
|
<ParamField body="email" type="string">
|
|
The email to send the forgot-password email to.
|
|
</ParamField>
|
|
</ContentSection>
|
|
|
|
<MethodReturns type='Promise<Result<undefined, KnownErrors["UserNotFound"]>>' />
|
|
|
|
</MethodContent>
|
|
|
|
<MethodAside>
|
|
<AsideSection title="Signature">
|
|
```typescript
|
|
declare function sendForgotPasswordEmail(
|
|
email: string,
|
|
): Promise<Result<undefined, KnownErrors["UserNotFound"]>>;
|
|
```
|
|
</AsideSection>
|
|
|
|
<AsideSection title="Examples">
|
|
```typescript
|
|
const result = await hexclaveClientApp.sendForgotPasswordEmail("test@example.com");
|
|
|
|
if (result.status === "success") {
|
|
console.log("Forgot password email sent");
|
|
} else {
|
|
console.error("Failed to send forgot password email", result.error.message);
|
|
}
|
|
```
|
|
</AsideSection>
|
|
|
|
</MethodAside>
|
|
</MethodLayout>
|
|
|
|
### `hexclaveClientApp.sendMagicLinkEmail(email)`
|
|
|
|
<MethodLayout>
|
|
<MethodContent>
|
|
Send a magic-link or OTP sign-in email to an email address.
|
|
|
|
<ContentSection title="Parameters">
|
|
<ParamField body="email" type="string">
|
|
The email to send the magic link to.
|
|
</ParamField>
|
|
</ContentSection>
|
|
|
|
<MethodReturns type='Promise<Result<{ nonce: string }, KnownErrors["RedirectUrlNotWhitelisted"]>>' />
|
|
|
|
</MethodContent>
|
|
|
|
<MethodAside>
|
|
<AsideSection title="Signature">
|
|
```typescript
|
|
declare function sendMagicLinkEmail(
|
|
email: string,
|
|
): Promise<Result<{ nonce: string }, KnownErrors["RedirectUrlNotWhitelisted"]>>;
|
|
```
|
|
</AsideSection>
|
|
|
|
<AsideSection title="Examples">
|
|
```typescript
|
|
const result = await hexclaveClientApp.sendMagicLinkEmail("test@example.com");
|
|
```
|
|
</AsideSection>
|
|
|
|
</MethodAside>
|
|
</MethodLayout>
|
|
|
|
---
|
|
|
|
# HexclaveServerApp
|
|
|
|
Like `HexclaveClientApp`, but with server permissions. Has full read and write access to all users.
|
|
|
|
<Warning>
|
|
Since this functionality should only be available in environments you trust
|
|
(ie. your own server), it requires a `SECRET_SERVER_KEY`. In some cases, you
|
|
may want to use a `HexclaveServerApp` on the client; an example for this is an
|
|
internal dashboard that only your own employees have access to. We generally
|
|
recommend against doing this unless you are aware of and protected against the
|
|
(potentially severe) security implications of exposing `SECRET_SERVER_KEY` on
|
|
the client.
|
|
</Warning>
|
|
|
|
## Table of Contents
|
|
|
|
```typescript
|
|
type HexclaveServerApp =
|
|
// Inherits all functionality from HexclaveClientApp
|
|
& HexclaveClientApp
|
|
& {
|
|
new(options): HexclaveServerApp;
|
|
|
|
getUser([id][, options]): Promise<ServerUser | null>;
|
|
useUser([id][, options]): ServerUser;
|
|
listUsers([options]): Promise<ServerUser[]>;
|
|
useUsers([options]): ServerUser[];
|
|
createUser([options]): Promise<ServerUser>;
|
|
sendEmail(options): Promise<Result<void, KnownErrors>>;
|
|
|
|
getTeam(id): Promise<ServerTeam | null>;
|
|
useTeam(id): ServerTeam;
|
|
listTeams([options]): Promise<ServerTeam[]>;
|
|
useTeams([options]): ServerTeam[];
|
|
listTeamsPaginated([options]): Promise<{ items: ServerTeam[]; nextCursor: string | null }>;
|
|
useTeamsPaginated([options]): { items: ServerTeam[]; nextCursor: string | null };
|
|
createTeam([options]): Promise<ServerTeam>;
|
|
}
|
|
```
|
|
|
|
## Constructor
|
|
|
|
Creates a new `HexclaveServerApp` instance.
|
|
|
|
<MethodLayout>
|
|
<MethodContent>
|
|
<ContentSection title="Parameters">
|
|
<ParamField body="tokenStore" type='"nextjs-cookie" | "cookie" | { accessToken, refreshToken } | Request' required>
|
|
Token storage configuration.
|
|
</ParamField>
|
|
|
|
<ParamField body="baseUrl" type="string">
|
|
Base URL for the Hexclave API.
|
|
</ParamField>
|
|
|
|
<ParamField body="projectId" type="string">
|
|
Project ID.
|
|
</ParamField>
|
|
|
|
<ParamField body="publishableClientKey" type="string">
|
|
Publishable client key.
|
|
</ParamField>
|
|
|
|
<ParamField body="secretServerKey" type="string">
|
|
Secret server key. Defaults to the `SECRET_SERVER_KEY` environment variable.
|
|
</ParamField>
|
|
|
|
<ParamField body="urls" type="object">
|
|
Redirect URL configuration.
|
|
</ParamField>
|
|
|
|
<ParamField body="noAutomaticPrefetch" type="boolean">
|
|
Disable automatic prefetching.
|
|
</ParamField>
|
|
</ContentSection>
|
|
|
|
</MethodContent>
|
|
|
|
<MethodAside>
|
|
<AsideSection title="Signature">
|
|
```typescript
|
|
declare class HexclaveServerApp {
|
|
constructor(options: {
|
|
tokenStore: "nextjs-cookie" | "cookie" | {
|
|
accessToken: string;
|
|
refreshToken: string;
|
|
} | Request;
|
|
baseUrl?: string;
|
|
projectId?: string;
|
|
publishableClientKey?: string;
|
|
secretServerKey?: string;
|
|
urls?: object;
|
|
noAutomaticPrefetch?: boolean;
|
|
});
|
|
}
|
|
```
|
|
</AsideSection>
|
|
|
|
<AsideSection title="Examples">
|
|
```typescript
|
|
const hexclaveServerApp = new HexclaveServerApp({
|
|
tokenStore: "nextjs-cookie",
|
|
urls: {
|
|
signIn: "/my-custom-sign-in-page",
|
|
},
|
|
});
|
|
```
|
|
</AsideSection>
|
|
|
|
</MethodAside>
|
|
</MethodLayout>
|
|
|
|
## User Operations
|
|
|
|
### `hexclaveServerApp.getUser([id], [options])`
|
|
|
|
<MethodLayout>
|
|
<MethodContent>
|
|
Enhanced version of `HexclaveClientApp.getUser()` with server permissions.
|
|
|
|
**Overloads:**
|
|
|
|
1. `getUser(id: string): Promise<ServerUser | null>` to get a user by ID.
|
|
2. `getUser(options?: { or?: "return-null" | "redirect" | "throw" }): Promise<CurrentServerUser | null>` to get the current user.
|
|
|
|
</MethodContent>
|
|
|
|
<MethodAside>
|
|
<AsideSection title="Signature">
|
|
```typescript
|
|
declare function getUser(id: string): Promise<ServerUser | null>;
|
|
declare function getUser(options?: {
|
|
or?: "return-null" | "redirect" | "throw";
|
|
}): Promise<CurrentServerUser | null>;
|
|
```
|
|
</AsideSection>
|
|
|
|
<AsideSection title="Examples">
|
|
```typescript
|
|
const currentUser = await hexclaveServerApp.getUser();
|
|
console.log(currentUser);
|
|
|
|
const serverUser = await hexclaveServerApp.getUser(
|
|
"12345678-1234-1234-1234-123456789abc",
|
|
);
|
|
console.log(serverUser);
|
|
```
|
|
</AsideSection>
|
|
|
|
</MethodAside>
|
|
</MethodLayout>
|
|
|
|
### `hexclaveServerApp.useUser([id], [options])`
|
|
|
|
<MethodLayout>
|
|
<MethodContent>
|
|
Functionally equivalent to [`getUser()`](#stackserverappgetuserid-options), but as a React hook.
|
|
|
|
<Info>
|
|
This should be used on the server-side only.
|
|
</Info>
|
|
|
|
</MethodContent>
|
|
|
|
<MethodAside>
|
|
<AsideSection title="Signature">
|
|
```typescript
|
|
declare function useUser(
|
|
idOrOptions?: string | { or?: "return-null" | "redirect" | "throw" },
|
|
options?: { or?: "return-null" | "redirect" | "throw" },
|
|
): ServerUser | CurrentServerUser | null;
|
|
```
|
|
</AsideSection>
|
|
</MethodAside>
|
|
</MethodLayout>
|
|
|
|
### `hexclaveServerApp.listUsers([options])`
|
|
|
|
<MethodLayout>
|
|
<MethodContent>
|
|
Lists all users on the project.
|
|
|
|
<ContentSection title="Parameters">
|
|
<ParamField body="options.cursor" type="string">
|
|
The cursor to start the result set from.
|
|
</ParamField>
|
|
|
|
<ParamField body="options.limit" type="number">
|
|
Maximum number of items to return. If omitted, all users are returned.
|
|
</ParamField>
|
|
|
|
<ParamField body="options.orderBy" type='"signedUpAt"'>
|
|
The field to sort results by.
|
|
</ParamField>
|
|
|
|
<ParamField body="options.desc" type="boolean">
|
|
Whether to sort in descending order. Defaults to `false`.
|
|
</ParamField>
|
|
|
|
<ParamField body="options.query" type="string">
|
|
Free-text search on the user's display name and emails.
|
|
</ParamField>
|
|
</ContentSection>
|
|
|
|
<MethodReturns type="Promise<ServerUser[] & { nextCursor: string | null }>" />
|
|
|
|
</MethodContent>
|
|
|
|
<MethodAside>
|
|
<AsideSection title="Signature">
|
|
```typescript
|
|
declare function listUsers(options?: {
|
|
cursor?: string;
|
|
limit?: number;
|
|
orderBy?: "signedUpAt";
|
|
desc?: boolean;
|
|
query?: string;
|
|
}): Promise<ServerUser[] & { nextCursor: string | null }>;
|
|
```
|
|
</AsideSection>
|
|
|
|
<AsideSection title="Examples">
|
|
```typescript
|
|
const users = await hexclaveServerApp.listUsers({ limit: 20 });
|
|
console.log(users);
|
|
|
|
if (users.nextCursor) {
|
|
const nextPageUsers = await hexclaveServerApp.listUsers({
|
|
cursor: users.nextCursor,
|
|
limit: 20,
|
|
});
|
|
console.log(nextPageUsers);
|
|
}
|
|
```
|
|
</AsideSection>
|
|
|
|
</MethodAside>
|
|
</MethodLayout>
|
|
|
|
### `hexclaveServerApp.useUsers([options])`
|
|
|
|
<MethodLayout>
|
|
<MethodContent>
|
|
Functionally equivalent to [`listUsers()`](#stackserverapplistusersoptions), but as a React hook.
|
|
|
|
<Info>This should be used on the server-side only.</Info>
|
|
|
|
</MethodContent>
|
|
|
|
<MethodAside>
|
|
<AsideSection title="Signature">
|
|
```typescript
|
|
declare function useUsers(options?: {
|
|
cursor?: string;
|
|
limit?: number;
|
|
orderBy?: "signedUpAt";
|
|
desc?: boolean;
|
|
query?: string;
|
|
}): ServerUser[];
|
|
```
|
|
</AsideSection>
|
|
</MethodAside>
|
|
</MethodLayout>
|
|
|
|
### `hexclaveServerApp.createUser([options])`
|
|
|
|
<MethodLayout>
|
|
<MethodContent>
|
|
Creates a new user from the server.
|
|
|
|
<ContentSection title="Parameters">
|
|
<ParamField body="options.primaryEmail" type="string">
|
|
User's primary email.
|
|
</ParamField>
|
|
|
|
<ParamField body="options.primaryEmailVerified" type="boolean">
|
|
Whether the email is verified.
|
|
</ParamField>
|
|
|
|
<ParamField body="options.primaryEmailAuthEnabled" type="boolean">
|
|
Whether email auth is enabled.
|
|
</ParamField>
|
|
|
|
<ParamField body="options.password" type="string">
|
|
User's password.
|
|
</ParamField>
|
|
|
|
<ParamField body="options.otpAuthEnabled" type="boolean">
|
|
Enable OTP or magic-link auth.
|
|
</ParamField>
|
|
|
|
<ParamField body="options.displayName" type="string">
|
|
User's display name.
|
|
</ParamField>
|
|
</ContentSection>
|
|
|
|
<MethodReturns type="Promise<ServerUser>" />
|
|
|
|
</MethodContent>
|
|
|
|
<MethodAside>
|
|
<AsideSection title="Signature">
|
|
```typescript
|
|
declare function createUser(options?: {
|
|
primaryEmail?: string;
|
|
primaryEmailVerified?: boolean;
|
|
primaryEmailAuthEnabled?: boolean;
|
|
password?: string;
|
|
otpAuthEnabled?: boolean;
|
|
displayName?: string;
|
|
}): Promise<ServerUser>;
|
|
```
|
|
</AsideSection>
|
|
|
|
<AsideSection title="Examples">
|
|
```typescript
|
|
const passwordUser = await hexclaveServerApp.createUser({
|
|
primaryEmail: "test@example.com",
|
|
primaryEmailAuthEnabled: true,
|
|
password: "password123",
|
|
});
|
|
|
|
const magicLinkUser = await hexclaveServerApp.createUser({
|
|
primaryEmail: "test@example.com",
|
|
primaryEmailVerified: true,
|
|
primaryEmailAuthEnabled: true,
|
|
otpAuthEnabled: true,
|
|
});
|
|
```
|
|
</AsideSection>
|
|
|
|
</MethodAside>
|
|
</MethodLayout>
|
|
|
|
### `hexclaveServerApp.sendEmail(options)`
|
|
|
|
<MethodLayout>
|
|
<MethodContent>
|
|
Send custom emails to users. You can send either custom HTML emails or use predefined templates with variables.
|
|
|
|
<ContentSection title="Parameters">
|
|
<ParamField body="options" type="SendEmailOptions">
|
|
Email configuration and content.
|
|
</ParamField>
|
|
</ContentSection>
|
|
|
|
<MethodReturns type="Promise<Result<void, KnownErrors>>">
|
|
The method returns a `Result` that can include `RequiresCustomEmailServer`, `SchemaError`, and `UserIdDoesNotExist`.
|
|
</MethodReturns>
|
|
|
|
</MethodContent>
|
|
|
|
<MethodAside>
|
|
<AsideSection title="Signature">
|
|
```typescript
|
|
declare function sendEmail(
|
|
options: SendEmailOptions,
|
|
): Promise<Result<void, KnownErrors>>;
|
|
```
|
|
</AsideSection>
|
|
|
|
<AsideSection title="Examples">
|
|
```typescript
|
|
const htmlResult = await hexclaveServerApp.sendEmail({
|
|
userIds: ["user-1", "user-2"],
|
|
subject: "Welcome to our platform!",
|
|
html: "<h1>Welcome!</h1><p>Thanks for joining us.</p>",
|
|
});
|
|
|
|
if (htmlResult.status === "error") {
|
|
console.error("Failed to send email:", htmlResult.error);
|
|
}
|
|
```
|
|
|
|
```typescript
|
|
const templateResult = await hexclaveServerApp.sendEmail({
|
|
userIds: ["user-1"],
|
|
templateId: "welcome-template",
|
|
variables: {
|
|
userName: "John Doe",
|
|
activationUrl: "https://app.com/activate/token123",
|
|
},
|
|
});
|
|
```
|
|
</AsideSection>
|
|
|
|
</MethodAside>
|
|
</MethodLayout>
|
|
|
|
## Team Management
|
|
|
|
### `hexclaveServerApp.getTeam(id)`
|
|
|
|
<MethodLayout>
|
|
<MethodContent>
|
|
Get a team by its ID.
|
|
|
|
<ContentSection title="Parameters">
|
|
<ParamField body="id" type="string">
|
|
Team ID.
|
|
</ParamField>
|
|
</ContentSection>
|
|
|
|
<MethodReturns type="Promise<ServerTeam | null>" />
|
|
|
|
</MethodContent>
|
|
|
|
<MethodAside>
|
|
<AsideSection title="Signature">
|
|
```typescript
|
|
declare function getTeam(id: string): Promise<ServerTeam | null>;
|
|
```
|
|
</AsideSection>
|
|
|
|
<AsideSection title="Examples">
|
|
```typescript
|
|
const team = await hexclaveServerApp.getTeam("team_id_123");
|
|
```
|
|
</AsideSection>
|
|
|
|
</MethodAside>
|
|
</MethodLayout>
|
|
|
|
### `hexclaveServerApp.useTeam(id)`
|
|
|
|
<MethodLayout>
|
|
<MethodContent>
|
|
Functionally equivalent to [`getTeam(id)`](#stackserverappgetteamid), but as a React hook.
|
|
|
|
<Info>This should be used on the server-side only.</Info>
|
|
|
|
</MethodContent>
|
|
|
|
<MethodAside>
|
|
<AsideSection title="Signature">
|
|
```typescript
|
|
declare function useTeam(id: string): ServerTeam;
|
|
```
|
|
</AsideSection>
|
|
</MethodAside>
|
|
</MethodLayout>
|
|
|
|
### `hexclaveServerApp.listTeams([options])`
|
|
|
|
<MethodLayout>
|
|
<MethodContent>
|
|
Lists all teams on the current project.
|
|
|
|
For cursor-based pagination over teams, see [`listTeamsPaginated`](#stackserverapplistteamspaginatedoptions).
|
|
|
|
<ContentSection title="Parameters">
|
|
<ParamField body="options.orderBy" type='"createdAt"'>
|
|
The field to sort results by.
|
|
</ParamField>
|
|
|
|
<ParamField body="options.desc" type="boolean">
|
|
Whether to sort in descending order. Defaults to `false`.
|
|
</ParamField>
|
|
</ContentSection>
|
|
|
|
<MethodReturns type="Promise<ServerTeam[]>" />
|
|
|
|
</MethodContent>
|
|
|
|
<MethodAside>
|
|
<AsideSection title="Signature">
|
|
```typescript
|
|
declare function listTeams(options?: {
|
|
orderBy?: "createdAt";
|
|
desc?: boolean;
|
|
}): Promise<ServerTeam[]>;
|
|
```
|
|
</AsideSection>
|
|
|
|
<AsideSection title="Examples">
|
|
```typescript
|
|
const teams = await hexclaveServerApp.listTeams();
|
|
console.log(teams);
|
|
```
|
|
</AsideSection>
|
|
|
|
</MethodAside>
|
|
</MethodLayout>
|
|
|
|
### `hexclaveServerApp.useTeams([options])`
|
|
|
|
<MethodLayout>
|
|
<MethodContent>
|
|
Functionally equivalent to [`listTeams()`](#stackserverapplistteamsoptions), but as a React hook.
|
|
|
|
<Info>This should be used on the server-side only.</Info>
|
|
|
|
</MethodContent>
|
|
|
|
<MethodAside>
|
|
<AsideSection title="Signature">
|
|
```typescript
|
|
declare function useTeams(options?: {
|
|
orderBy?: "createdAt";
|
|
desc?: boolean;
|
|
}): ServerTeam[];
|
|
```
|
|
</AsideSection>
|
|
</MethodAside>
|
|
</MethodLayout>
|
|
|
|
### `hexclaveServerApp.listTeamsPaginated([options])`
|
|
|
|
<MethodLayout>
|
|
<MethodContent>
|
|
Lists teams on the current project with cursor-based pagination, optional filtering, and ordering. The returned array carries an extra `nextCursor` property; pass it back as `cursor` to load the next page.
|
|
|
|
<ContentSection title="Parameters">
|
|
<ParamField body="options.cursor" type="string">
|
|
Cursor returned as `nextCursor` from a previous response.
|
|
</ParamField>
|
|
|
|
<ParamField body="options.limit" type="number">
|
|
Maximum number of items to return. If omitted, all matching teams are returned.
|
|
</ParamField>
|
|
|
|
<ParamField body="options.orderBy" type='"createdAt"'>
|
|
The field to sort results by.
|
|
</ParamField>
|
|
|
|
<ParamField body="options.desc" type="boolean">
|
|
Whether to sort in descending order. Defaults to `false`.
|
|
</ParamField>
|
|
|
|
<ParamField body="options.query" type="string">
|
|
Free-text search on the team's display name (and team ID if the query is a UUID).
|
|
</ParamField>
|
|
</ContentSection>
|
|
|
|
<MethodReturns type="Promise<{ items: ServerTeam[]; nextCursor: string | null }>" />
|
|
|
|
</MethodContent>
|
|
|
|
<MethodAside>
|
|
<AsideSection title="Signature">
|
|
```typescript
|
|
declare function listTeamsPaginated(options?: {
|
|
cursor?: string;
|
|
limit?: number;
|
|
orderBy?: "createdAt";
|
|
desc?: boolean;
|
|
query?: string;
|
|
}): Promise<{ items: ServerTeam[]; nextCursor: string | null }>;
|
|
```
|
|
</AsideSection>
|
|
|
|
<AsideSection title="Examples">
|
|
```typescript
|
|
const teams = await hexclaveServerApp.listTeamsPaginated({ limit: 20 });
|
|
console.log(teams);
|
|
|
|
if (teams.nextCursor) {
|
|
const nextPageTeams = await hexclaveServerApp.listTeamsPaginated({
|
|
cursor: teams.nextCursor,
|
|
limit: 20,
|
|
});
|
|
console.log(nextPageTeams);
|
|
}
|
|
```
|
|
</AsideSection>
|
|
|
|
</MethodAside>
|
|
</MethodLayout>
|
|
|
|
### `hexclaveServerApp.useTeamsPaginated([options])`
|
|
|
|
<MethodLayout>
|
|
<MethodContent>
|
|
Functionally equivalent to [`listTeamsPaginated()`](#stackserverapplistteamspaginatedoptions), but as a React hook.
|
|
|
|
<Info>This should be used on the server-side only.</Info>
|
|
|
|
</MethodContent>
|
|
|
|
<MethodAside>
|
|
<AsideSection title="Signature">
|
|
```typescript
|
|
declare function useTeamsPaginated(options?: {
|
|
cursor?: string;
|
|
limit?: number;
|
|
orderBy?: "createdAt";
|
|
desc?: boolean;
|
|
query?: string;
|
|
}): { items: ServerTeam[]; nextCursor: string | null };
|
|
```
|
|
</AsideSection>
|
|
</MethodAside>
|
|
</MethodLayout>
|
|
|
|
### `hexclaveServerApp.createTeam([options])`
|
|
|
|
<MethodLayout>
|
|
<MethodContent>
|
|
Creates a team without adding a user to it.
|
|
|
|
<ContentSection title="Parameters">
|
|
<ParamField body="options.displayName" type="string">
|
|
Team display name.
|
|
</ParamField>
|
|
|
|
<ParamField body="options.profileImageUrl" type="string | null">
|
|
Team profile image URL.
|
|
</ParamField>
|
|
</ContentSection>
|
|
|
|
<MethodReturns type="Promise<ServerTeam>" />
|
|
|
|
</MethodContent>
|
|
|
|
<MethodAside>
|
|
<AsideSection title="Signature">
|
|
```typescript
|
|
declare function createTeam(options?: {
|
|
displayName?: string;
|
|
profileImageUrl?: string | null;
|
|
}): Promise<ServerTeam>;
|
|
```
|
|
</AsideSection>
|
|
|
|
<AsideSection title="Examples">
|
|
```typescript
|
|
const team = await hexclaveServerApp.createTeam({
|
|
displayName: "New Team",
|
|
profileImageUrl: "https://example.com/profile.jpg",
|
|
});
|
|
```
|
|
</AsideSection>
|
|
|
|
</MethodAside>
|
|
</MethodLayout>
|