Sign in

Your own buttons, each sending the hosted page straight to one method.

Built on @synqauth/react over @synqauth/nextjs’s route mount, so it needs a server of yours. In a single-page app, createSynqClient from @synqauth/js signs in: signIn(), then handleCallback() where Synq sends the browser back. @synqauth/js in the docs

src/examples/sign-in/Headless.tsx
'use client'

import { type SignInMethod, useAuth } from '@synqauth/react'

// Sign-in headless: the app's own buttons, each with a method hint, so the
// hosted page goes straight to that method instead of showing its list.
// Apple, X and Facebook are Synq methods too; the app names them for
// TypeScript by augmenting SignInMethods (see the bottom of this file).
const METHODS: readonly { method: SignInMethod; label: string }[] = [
  { method: 'passkey', label: 'Passkey' },
  { method: 'email', label: 'Email code' },
  { method: 'password', label: 'Password' },
  { method: 'wallet', label: 'Solana wallet' },
  { method: 'google', label: 'Google' },
  { method: 'apple', label: 'Apple' },
  { method: 'microsoft', label: 'Microsoft' },
  { method: 'discord', label: 'Discord' },
  { method: 'x', label: 'X' },
  { method: 'facebook', label: 'Facebook' },
]

export function SignInHeadless() {
  const { isSignedIn, userId, signIn, signOut } = useAuth()
  if (isSignedIn) {
    return (
      <p>
        Signed in as <code>{userId}</code>{' '}
        <button type="button" onClick={() => void signOut()}>
          Sign out
        </button>
      </p>
    )
  }
  return (
    <ul aria-label="Sign in with">
      {METHODS.map(({ method, label }) => (
        <li key={method}>
          <button type="button" onClick={() => void signIn({ method, returnTo: '/build/sign-in' })}>
            {label}
          </button>
        </li>
      ))}
    </ul>
  )
}