Auth

BusinessDash provides a drop-in auth system for your externally-hosted site — sign-in, sign-up, password reset, and session management, all backed by WorkOS.

import { createAuthHandler } from '@businessdash/sdk/next'
// Also available: @businessdash/sdk/astro, @businessdash/sdk/remix, etc.

export const { GET, POST } = createAuthHandler({
  successUrl: '/dashboard',
  callbackUrl: `${process.env.NEXT_PUBLIC_SITE_URL}/api/bd-auth/callback`,
})

Protect a route

import { getTenantSession } from '@businessdash/sdk/next'

export default async function DashboardPage() {
  const session = await getTenantSession()
  if (!session) return <SignIn />
  return <Dashboard user={session.user} />
}

React components

import { SignIn, SignUp, SignOut, useUser } from '@businessdash/sdk/react'

function AuthButtons() {
  const user = useUser()
  if (user) return <SignOut />
  return (
    <>
      <SignIn />
      <SignUp mode="modal" />
    </>
  )
}

Programmatic auth

import { signIn, signUp, signOut, requestPasswordReset }
  from '@businessdash/sdk'

await signIn({ email: 'jane@example.com' })
await signUp({ email: 'jane@example.com', password: '…' })
await signOut()
await requestPasswordReset({ email: 'jane@example.com' })

Requires the site's auth callback URL to be registered as a WorkOS redirect URI in Settings → Integrations.