src/examples/admin/Connections.tsx

Every source

src/examples/admin/Connections.tsx
import { demoOrg } from '../../lib/management'

// The brand's sign-in providers, read on the server through the management
// API with an org API key: each provider, whether it's on, and whose app at
// the provider it signs in through (Synq's own, or the brand's or the org's
// own app, which they bring with their credentials: bring-your-own
// connections), or none yet.

/** Whose app a provider signs in through (`signs_in_through`), in words. */
const THROUGH: Record<string, string> = {
  synq: 'Synq’s app',
  brand: 'The brand’s own app',
  org: 'The org’s own app',
}

export async function Connections() {
  const tenant = await demoOrg()
  if (!tenant) return <p>The demo tenant isn’t set up.</p>
  // A list answers a page at a time: paginate reads every page.
  const data = []
  for await (const provider of tenant.synq.paginate(
    '/v1/orgs/{org}/brands/{brand}/sign-in-providers',
    { path: tenant.path },
  )) {
    data.push(provider)
  }
  return (
    <table className="w-full text-left">
      <thead>
        <tr>
          <th>Provider</th>
          <th>On</th>
          <th>Signs in through</th>
          <th>Redirect URI</th>
        </tr>
      </thead>
      <tbody>
        {data.map((p) => (
          <tr key={p.provider}>
            <td>{p.provider}</td>
            <td>{p.offered ? 'Yes' : 'No'}</td>
            <td>
              {p.signs_in_through === null
                ? 'No app yet'
                : (THROUGH[p.signs_in_through] ?? p.signs_in_through)}
            </td>
            <td>
              <code>{p.redirect_uri}</code>
            </td>
          </tr>
        ))}
      </tbody>
    </table>
  )
}