Reown Authentication SIWX Usage
Reown Authentication is our flagship SIWX (Sign In With X) solution - the recommended way to handle user authentication for modern web3 applications. Built specifically for multi-chain environments, it abstracts away the complexity of validating wallets across EVM, Solana, and Bitcoin networks.
With Reown Authentication you will be able to see and control the sessions of your users, get insights and much more. Read more about Reown Authentication features in the dedicated documentation.
ReownAuthentication was previously named CloudAuthSIWX, it has been renamed since version 1.7.13. If you were using
the previous class, you will not need to update your code, both class names work identically.
Installation
npm install @reown/appkit-siwx
Usage
import { createAppKit } from '@reown/appkit'
// Add the following code line
import { ReownAuthentication } from '@reown/appkit-siwx'
const appkit = createAppKit({
  projectId,
  networks,
  metadata,
  // Add the following code line
  siwx: new ReownAuthentication()
})
ReownAuthentication you don’t need to do anything else, it will work out of the box, but you can configure some parameters to customize the experience.
Available Parameters
new ReownAuthentication({
  localAuthStorageKey?: string    // Default: '@appkit/siwx-auth-token'
  localNonceStorageKey?: string   // Default: '@appkit/siwx-nonce-token'
  required?: boolean              // Default: true
})
Examples
Custom storage keys:
new ReownAuthentication({
  localAuthStorageKey: 'my-app-auth',
  localNonceStorageKey: 'my-app-nonce'
})
new ReownAuthentication({
  required: false
})
Interacting with Reown Authentication
AppKit provides a getSIWX function that allows you to grab and interact with Reown Authentication.
import type { ReownAuthentication } from '@reown/appkit-siwx'
const siwx = appkit.getSIWX<ReownAuthentication>()
Interactions
getSessionAccount
You can retrieve the session account data using the getSessionAccount method:
const siwx = appkit.getSIWX<ReownAuthentication>()
if (siwx) {
  const sessionAccount = await siwx.getSessionAccount()
  console.log(sessionAccount)
}
setSessionAccountMetadata method:
const siwx = appkit.getSIWX<ReownAuthentication>()
const metadata = { username: 'satoshi', preferences: { theme: 'dark' } }
if (siwx) {
  await siwx.setSessionAccountMetadata(metadata)
}
getSessionAccount method:
const siwx = appkit.getSIWX<ReownAuthentication>()
if (siwx) {
  const account = await siwx.getSessionAccount()
  const metadata = account.appKitAccount?.metadata
  console.log(metadata)
}
events
Reown Authentication provides events that you can listen to for session management and authentication state changes:
import type { SIWXSession, ReownAuthentication } from '@reown/appkit-siwx'
const siwx = appkit.getSIWX<ReownAuthentication>()
if (siwx) {
  // Add event listeners
  const unsubscribe = siwx.on('sessionChanged', (session) => {
    console.log('Session changed:', session)
  })
  // Cleanup listeners when needed
  unsubscribe()
  // or
  siwx.removeAllListeners()
}