Account panel

The account button of your header: the brand’s ways to sign in, a welcome on a first sign-in with the cards to set up, and the profile after, in a popover on a laptop and a sheet on a phone. Back closes it, and a sign-in that leaves the page comes back into it.

Built on @synqauth/react over @synqauth/nextjs’s route mount, so it needs a server of yours. In a single-page app, draw the panel yourself on @synqauth/js: createSynqClient signs in, and createAccountClient reads the account. @synqauth/js in the docs

src/examples/account-panel/Headless.tsx
'use client'

import { useAccountPanel, useSession, useSignInMethods } from '@synqauth/react'

// The same panel headless: useAccountPanel() keeps it open in ?panel=account
// (so Back closes it), keeps the focus inside, closes on Escape or a click
// outside, and says which view to show. Spread its props on your own button
// and dialog, and draw each view your way.
export function AccountPanelHeadless() {
  const panel = useAccountPanel()
  const { user } = useSession()
  const { data: methods } = useSignInMethods()
  return (
    <>
      <button {...panel.triggerProps}>
        {user ? `Your profile, ${user.name ?? user.sub}` : 'Sign in'}
      </button>
      {panel.open && (
        <div {...panel.panelProps} className="mt-4 space-y-3 rounded-2xl border border-plum p-4">
          <h2 id={panel.titleId}>
            {panel.view === 'onboarding' ? 'Welcome!' : user ? 'Your profile' : 'Sign in'}
          </h2>
          {panel.view === 'sign-in' &&
            methods
              ?.filter((method) => !method.in_place)
              .map((method) => (
                <button key={method.id} onClick={() => void panel.signIn(method.id)}>
                  Continue with {method.name}
                </button>
              ))}
          {panel.view === 'progress' && (
            <p>
              Finish with {panel.pending?.name}… <button onClick={panel.cancel}>Cancel</button>
            </p>
          )}
          {panel.problem && <p role="alert">{panel.problem.message}</p>}
          {user && <button onClick={() => void panel.signOut()}>Sign out</button>}
          <button onClick={() => panel.setOpen(false)}>Close</button>
        </div>
      )}
    </>
  )
}