@synqauth/plugin-siws
v0.3.0
Published
A Synq plugin for Sign In With Solana from your own UI.
Readme
@synqauth/plugin-siws
A Synq plugin for Sign In With Solana from your own UI.
Synq is customer identity for businesses: an OpenID Connect issuer for each of your brands, with Solana wallet, social, email and passkey sign-in. The documentation is at docs.synq.build.
This package is at 0.x, so a minor release can change its API: see its CHANGELOG.md.
Usage
With @synqauth/nextjs, for the brand's own apps. On the server:
import { siwsServerPlugin } from '@synqauth/plugin-siws/server'
export const synq = synqAuth({ plugins: [siwsServerPlugin()] })In the page:
'use client'
import { mountRequest } from '@synqauth/nextjs/client'
import { siwsPlugin } from '@synqauth/plugin-siws'
import { useSolanaWallets } from '@synqauth/solana/react'
const siws = siwsPlugin().actions(mountRequest())
const wallets = useSolanaWallets()
// When the sign-in comes into view: the issuer's request, before the tap.
useEffect(() => void siws.prepare(), [])
// On the tap: straight to the wallet.
const { error } = await siws.signIn(wallets[0], { returnTo: '/account' })prepare() asks for the request the wallet signs before the tap and keeps it fresh, so the tap reaches the wallet with nothing fetched first: Safari blocks a wallet's prompt that opens after a network wait.
The wallet signs the issuer's own request on your page, and your server pushes the signature to Synq, which checks it. Your server verifies nothing.
License
MIT
