Skip to Content

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)
ParameterTypeDescription
appKeystringYour Myco app key
options.baseUrlstringBase URL override
options.redirectOnUnauthbooleanRedirect to login when unauthenticated (default: true)

Properties

PropertyTypeDescription
readyPromise<void>Resolves when SDK is initialized (workspace ready)
authAuthManagerAuth namespace
workspaceWorkspaceManagerWorkspace namespace
dataDataManager<T>Data namespace
chatChatManagerChat namespace
filesFilesManagerFile upload namespace
fetch(path, options?) => Promise<Response>Authenticated fetch
queryClientQueryClientShared 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

PropTypeDescription
mycoMycoSDKSDK instance
childrenReactNodeApp 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(): UseAuthResult

Return type: UseAuthResult

PropertyTypeDescription
isLoadingbooleanSession being verified
isLoggedInbooleanUser has a valid session
userMycoUser | undefinedCurrent user
userIdstring | undefinedUser ID shortcut
login(returnTo?: string) => voidRedirect to login
logout() => voidClear 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

PropTypeDefaultDescription
childrenReactNodeContent to protect
fallbackReactNodenullShown 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 }