Documentation

React quick start

Add sign-in to a React app with the provider, RequireAuth and ready-made components.

All documentation

Before you start

  • Create a workspace at https://auth.ziqme.com/signup. It starts on the Free plan; no card is needed.
  • Open https://app.ziqme.com/auth-admin, choose "Register application", and add your redirect URI. A browser or mobile app is a public application (no secret). A server is confidential and gets a client secret, shown once.
  • Note the client ID (it starts with app_). It is safe to ship in a browser: it is not a secret.

The SDK and component packages are not on npm or NuGet yet. For early access, contact Ziqme support at https://ziqme.com/contact. Meanwhile any standard OpenID Connect or JWT library works against Auth: every step here also works with one; see the plain OIDC quick start.

Wrap your app

main.tsx
import { RequireAuth, UserButton, ZiqmeAuthProvider } from '@smartdesk/auth-react'

export function Root() {
  const navigate = useNavigate()
  return (
    <ZiqmeAuthProvider
      issuer="https://auth.ziqme.com"
      clientId="app_your_client_id"
      redirectUri={`${location.origin}/callback`}
      postLogoutRedirectUri={`${location.origin}/`}
      applicationName="Bistro"
      onSignedIn={returnTo => navigate(returnTo, { replace: true })}
    >
      <UserButton showName />
      <RequireAuth fallback={<p>Loading…</p>}>
        <Orders />
      </RequireAuth>
    </ZiqmeAuthProvider>
  )
}

RequireAuth renders its children only for a signed-in person. An anonymous visitor is sent to the hosted login and comes back to the same place. Give it roles to require one of them, and forbidden for what to show otherwise.

Call your API

Orders.tsx
import { useAuth } from '@smartdesk/auth-react'

export function Orders() {
  const { user, getAccessToken } = useAuth()

  async function load() {
    const response = await fetch('/api/orders', {
      headers: { Authorization: `Bearer ${await getAccessToken()}` },
    })
    return response.json()
  }

  return <h1>Orders for {user?.name}</h1>
}

getAccessToken returns a valid token and refreshes it when it is about to expire. Ask for the offline_access scope to stay signed in past the access token's 15 minutes.

Components

ComponentWhat it does
SignInA card whose button goes to the hosted login
SignUpSays accounts come by invitation, or links to your page with signUpUrl
UserButtonAvatar with a menu: account page, sign out
UserProfileName, email, roles and organization, with a link to the hosted account page
OrganizationSwitcherThe current organization and a way to change it
RequireAuthRenders its children only for a signed-in person