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

Your app

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

import { AccountPanel, useAccountPanelSection, useUser } from '@synqauth/react'
import { useState } from 'react'

// The account button of an app's header, with Synq's UI: signed out, the
// brand's ways in (the one this browser last used marked, and lifted out of
// More options); signed in, the profile. A first sign-in gets a welcome once, with
// the cards to set up, each skippable. The sections render in source order,
// so the app's own card sits between them, drawn as theirs are with
// AccountPanel.Card. Signing out stays on the page. Wrap the app in
// <SynqWalletProvider> (components/Providers.tsx) and a wallet signs in with
// one signature, in place.
function MemberCard() {
  const { profile } = useUser()
  // A first sign-in's onboarding keeps to what to set up.
  const { firstRun } = useAccountPanelSection()
  if (firstRun || !profile) return null
  return (
    <AccountPanel.Card title="Member since">
      <p>{new Date(profile.created_at).toLocaleDateString('en-US', { dateStyle: 'long' })}</p>
    </AccountPanel.Card>
  )
}

export function AccountPanelWithUi() {
  const [said, setSaid] = useState('')
  return (
    <header className="flex items-center justify-between gap-4">
      <span className="font-display text-lg font-bold">Your app</span>
      <AccountPanel
        methods={['wallet', 'google', 'github', 'email']}
        description="One profile for every way you sign in."
        accountHref="/build/accounts"
        onSignedOut={() => setSaid('Signed out.')}
      >
        <AccountPanel.Username />
        <MemberCard />
        <AccountPanel.Wallets />
        <AccountPanel.Linked>
          <AccountPanel.LinkRow
            provider="discord"
            description="Show your Discord on your profile."
          />
          <AccountPanel.LinkRow provider="x" />
        </AccountPanel.Linked>
      </AccountPanel>
      <p role="status" className="sr-only">
        {said}
      </p>
    </header>
  )
}