LogoLogo
  • Welcome to OneAuxilia Docx
  • UI Component
    • Overview
    • <OneAuxiliaProvider>
    • Authentication Components
      • <SignIn />
      • <SignUp />
      • <GoogleOneTap />
    • User Components
      • <UserButton />
      • <UserProfile />
    • Organization Components
      • <CreateOrganization />
      • <OrganizationProfile />
      • <OrganizationSwitcher />
      • <OrganizationList />
    • Control Components
      • <AuthenticateWithRedirectCallback />
      • <OneAuxiliaLoaded>
      • <OneAuxiliaLoading>
      • <Protect>
      • <MultisessionAppSupport>
      • <RedirectToSignIn />
      • <RedirectToSignUp />
      • <RedirectToUserProfile />
      • <RedirectToOrganizationProfile />
      • <RedirectToCreateOrganization />
      • <SignedIn>
      • <SignedOut>
    • Unstyled Components
      • <SignInButton>
      • <SignInWithMetamaskButton>
      • <SignUpButton>
      • <SignOutButton>
  • Quick Start
  • Users
    • Overview
    • Metadata
    • Delete User
  • Organization
    • Organization, Role and Permission
      • Overview
      • Role and Permission
      • Guides
        • Create Role and assign Permission
        • Verify the active user's permission
        • Reassign the Creator role
      • Building custom flow
    • Multi Tenant Setting
  • Application
    • Application
    • User Portal
  • Authentication
    • Setting
    • Social Connectors
    • Multi Factor
  • Customize
    • Branding
    • Sign Up vs Sign In
      • Overview
      • Configuration
        • Sign-up and Sign-in options
        • Session Option
        • Email and SMS templates
      • Social Connection
        • Overview
        • Social connections (OAuth)
        • Account Linking
        • Setup Social Account Linking
  • Development
    • API Key
    • Local Path
    • Custom JWT templates
    • Domain
    • Webhook
    • Backend Request
      • Overview
      • Making requests
        • Same-origin requests
        • Cross-origin requests
        • Customize your session token
      • Handling requests
        • Manual JWT verification
      • Session Management
  • SDK References
    • React
      • Overview
      • Guides
        • Add React Router
      • Client-side Helpers
        • useUser()
        • useOneAuxilia()
        • useAuth()
        • useSignIn()
        • useSignUp()
        • useSession()
        • useSessionList()
        • useOrganization()
        • useOrganizationList()
  • API References
    • Open API
  • industry reference
    • Ecommerce
    • Broadcasting
    • IoT
Powered by GitBook
On this page
  • useAuth() returns
  • How to use the useAuth() hook
  1. SDK References
  2. React
  3. Client-side Helpers

useAuth()

The useAuth() hook is a convenient way to access the current auth state. This hook provides the minimal information needed for data-loading and helper methods to manage the current active session.

useAuth() returns


isSignedIn boolean

A boolean that returns true if the user is signed in.


isLoaded boolean

A boolean that until OneAuxilia loads and initializes, will be set to false. Once OneAuxilia loads, isLoaded will be set to true.


userId string

The current user's ID.


sessionId string

The current user's session ID.


orgId string

The current user's active organization ID.


orgRole string

The current user's active organization role.


orgSlug string

The current user's organization slug.


signOut() (options?: SignOutOptions) => Promise<void>

A function that signs the user out. See the reference documentation for more information.


getToken() (options?: GetTokenOptions) => Promise<string | null>

A function that returns a promise that resolves to the current user's session token. Can also be used to retrieve a custom JWT template. See the reference documentation for more information.


has() (isAuthorizedParams: CheckAuthorizationParamsWithCustomPermissions) => boolean

How to use the useAuth() hook

The following example demonstrates how to use the useAuth() hook to access the current auth state, like whether the user is signed in or not. It also demonstrates a basic example of how you could use the getToken() method to retrieve a session token for fetching data from an external resource.

external-data-page.tsx
import { useAuth } from '@oneauxilia/oneauxilia-react';

export default function ExternalDataPage() {
  const { getToken, isLoaded, isSignedIn } = useAuth();

  if (!isLoaded) {
    // Handle loading state however you like
    return <div>Loading...</div>;
  }

  if (!isSignedIn) {
    // Handle signed out state however you like
    return <div>Sign in to view this page</div>;
  }

  const fetchDataFromExternalResource = async () => {
    const token = await getToken();
    // Add logic to fetch your data
    return data;
  }

  return <div>...</div>;
}
PrevioususeOneAuxilia()NextuseSignIn()

Last updated 10 months ago

A function that returns a boolean based on the permission or role provided as parameter. Can be used for authorization. See the for more information.

reference documentation