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
59 changes: 45 additions & 14 deletions packages/auth/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,18 @@ npm install @object-ui/auth
## Quick Start

```tsx
import { AuthProvider, useAuth, AuthGuard } from '@object-ui/auth';
import { createAuthClient } from '@object-ui/auth';
import type { ReactNode } from 'react';
import { AuthProvider, AuthGuard, createAuthClient, useAuth } from '@object-ui/auth';

const authClient = createAuthClient({
baseURL: 'https://api.example.com/auth',
});
// Your app supplies the sign-in page shown to unauthenticated visitors.
declare const LoginPage: () => ReactNode;

const authUrl = 'https://api.example.com/auth';
const authClient = createAuthClient({ baseURL: authUrl });

function App() {
return (
<AuthProvider client={authClient}>
<AuthProvider authUrl={authUrl} client={authClient}>
<AuthGuard fallback={<LoginPage />}>
<Dashboard />
</AuthGuard>
Expand All @@ -57,19 +59,30 @@ function Dashboard() {

### AuthProvider

Wraps your application with authentication context:
Wraps your application with authentication context. `authUrl` is **required**;
`client` is optional, and when you pass one it is used instead of the client
`AuthProvider` would otherwise build from `authUrl`:

```tsx
<AuthProvider client={authClient}>
import type { ReactNode } from 'react';
import { AuthProvider } from '@object-ui/auth';
import type { AuthClient } from '@object-ui/auth';

declare const authClient: AuthClient;
declare const App: () => ReactNode;

<AuthProvider authUrl="/api/v1/auth" client={authClient}>
<App />
</AuthProvider>
</AuthProvider>;
```

### useAuth

Hook for accessing auth state and methods:

```tsx
import { useAuth } from '@object-ui/auth';

const {
user,
session,
Expand Down Expand Up @@ -100,27 +113,38 @@ const {
Protects children from unauthenticated access:

```tsx
import type { ReactNode } from 'react';
import { AuthGuard, LoginForm } from '@object-ui/auth';

declare const ProtectedContent: () => ReactNode;

<AuthGuard fallback={<LoginForm />}>
<ProtectedContent />
</AuthGuard>
</AuthGuard>;
```

### LoginForm / RegisterForm / ForgotPasswordForm

Pre-built authentication form components:

```tsx
<LoginForm onSuccess={() => navigate('/dashboard')} />
<RegisterForm onSuccess={() => navigate('/welcome')} />
<ForgotPasswordForm onSuccess={() => navigate('/check-email')} />
import { ForgotPasswordForm, LoginForm, RegisterForm } from '@object-ui/auth';

declare const navigate: (to: string) => void;

<LoginForm onSuccess={() => navigate('/dashboard')} />;
<RegisterForm onSuccess={() => navigate('/welcome')} />;
<ForgotPasswordForm onSuccess={() => navigate('/check-email')} />;
```

### UserMenu

Displays current user info with avatar and sign-out:

```tsx
<UserMenu />
import { UserMenu } from '@object-ui/auth';

<UserMenu />;
```

### createAuthenticatedFetch
Expand All @@ -129,6 +153,8 @@ Creates a fetch wrapper that injects the stored Bearer token (plus
`X-Tenant-ID` and `Accept-Language`) into API requests:

```tsx
import { createAuthenticatedFetch } from '@object-ui/auth';

const authedFetch = createAuthenticatedFetch();

// For fetches whose target URL comes from view metadata (`provider: 'api'`
Expand Down Expand Up @@ -330,8 +356,11 @@ This feature aligns with the `PreviewModeConfig` from `@objectstack/spec/kernel`
### Usage

```tsx
import type { ReactNode } from 'react';
import { AuthProvider, PreviewBanner } from '@object-ui/auth';

declare const Dashboard: () => ReactNode;

function App() {
return (
<AuthProvider
Expand Down Expand Up @@ -377,6 +406,8 @@ import { PreviewBanner } from '@object-ui/auth';
Use the `useAuth` hook to check if the app is in preview mode:

```tsx
import { useAuth } from '@object-ui/auth';

function MyComponent() {
const { isPreviewMode, previewMode } = useAuth();

Expand Down
2 changes: 0 additions & 2 deletions scripts/check-doc-snippet-types.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -775,8 +775,6 @@ const UNGATED_DOCS = {
'diagnostic(s) (TS2420, TS2355) — a `DataSource` implementation written as `// ... other ' +
'methods`. This entry read 9 until objectui#7417 paid down the three TS2305s it carried; ' +
'what is left is fragment shape, and no gate reads this page\'s import names.',
'packages/auth/README.md':
'1 parse diagnostic(s) — blocks fenced `ts` that are bare object literals or elided bodies; 15 undefined-name diagnostic(s) — blocks continue an earlier block, or use ambient names the page never defines; plus TS2741x1 — candidate real defects, un-triaged',
'packages/fields/README.md':
'2 undefined-name diagnostic(s) — blocks continue an earlier block, or use ambient names the page never defines; 1 unresolved-module diagnostic(s)',
'packages/plugin-charts/README.md':
Expand Down
Loading