Auth API
Authentication exports from @myco-dev/sdk and @myco-dev/sdk/auth.
MycoSDK
import { MycoSDK } from "@myco-dev/sdk";Constructor
new MycoSDK<TEntities>(appKey: string, options?: MycoSDKOptions)| Parameter | Type | Description |
|---|---|---|
appKey | string | Your Myco app key |
options.baseUrl | string | Base URL override |
options.redirectOnUnauth | boolean | Redirect to login when unauthenticated (default: true) |
Properties
| Property | Type | Description |
|---|---|---|
ready | Promise<void> | Resolves when SDK is initialized (workspace ready) |
auth | AuthManager | Auth namespace |
workspace | WorkspaceManager | Workspace namespace |
data | DataManager<T> | Data namespace |
chat | ChatManager | Chat namespace |
files | FilesManager | File upload namespace |
fetch | (path, options?) => Promise<Response> | Authenticated fetch |
queryClient | QueryClient | Shared React Query client |
MycoProvider
import { MycoProvider } from "@myco-dev/sdk";Wraps your app with auth state and React Query. Must be near the root.
Props
| Prop | Type | Description |
|---|---|---|
myco | MycoSDK | SDK instance |
children | ReactNode | App content |
useMyco
import { useMyco } from "@myco-dev/sdk";Access the SDK instance from any component within MycoProvider.
function useMyco<T extends Record<string, unknown>>(): MycoSDK<T>Throws if used outside MycoProvider.
useAuth
import { useAuth } from "@myco-dev/sdk/auth";Access auth state and methods.
function useAuth(): UseAuthResultReturn type: UseAuthResult
| Property | Type | Description |
|---|---|---|
isLoading | boolean | Session being verified |
isLoggedIn | boolean | User has a valid session |
user | MycoUser | undefined | Current user |
userId | string | undefined | User ID shortcut |
login | (returnTo?: string) => void | Redirect to login |
logout | () => void | Clear session |
refresh | () => Promise<void> | Re-fetch session |
ProtectedRoute
import { ProtectedRoute } from "@myco-dev/sdk/auth";Wrapper component that requires authentication. Redirects to login if unauthenticated.
Props
| Prop | Type | Default | Description |
|---|---|---|---|
children | ReactNode | — | Content to protect |
fallback | ReactNode | null | Shown while auth is loading |
Types
import type { MycoUser, MycoSession } from "@myco-dev/sdk/auth";MycoUser
interface MycoUser {
id: string;
name: string;
email: string;
emailVerified: boolean;
image?: string | null;
createdAt: Date;
updatedAt: Date;
}MycoSession
interface MycoSession {
user: MycoUser;
session: {
id: string;
userId: string;
expiresAt: Date;
token: string;
};
}MycoSDKOptions
interface MycoSDKOptions {
baseUrl?: string;
redirectOnUnauth?: boolean; // default: true
}