Use your own SIWS (Sign-in-with-Solana) implementation
By default, the TorqueProvider will automatically initialize the user with Torque using SIWS when a wallet is detected. This is not ideal for applications that already have SIWS set up.
Setting autoInit to false in the TorqueProvider
In cases where you want to manually initialize the user with Torque, or if you already have Sign-in-with-Solana (SIWS) set up for your application, you can set the autoInit prop to false and initialize the user manually.
If you want to initialize the user manually, you can use the initialize function provided by the useTorque hook. The Torque SDK provides a public convenience function to construct the login body required to initialize the user with Torque.
import { useTorque } from"@torque-labs/torque-ui";import { TorqueSDK } from"@torque-labs/torque-ts-sdk";import { useWallet } from"@solana/wallet-adapter-react";exportfunctionMyApp() {const { initialize } =useTorque();const { publicKey,signIn } =useWallet();return ( <div> <h1>My Solana App</h1> <buttononClick={async () => {constpayload="<sign in payload object>";// Prompt the user to sign in with their walletconstsignInOutput=awaitsignIn(payload);// Construct the login body using the TorqueSDK `constructLoginBody` function loginBody =TorqueSDK.constructLoginBody({ authType:"siws", pubKey:publicKey.toString(), payload: { input: payload, output: signInOutput, }, });// Initialize the user with Torque using the login bodyawaitinitialize(loginBody); }} > Initialize Torque </button> </div> );}
Initialize after a callback or user interaction
You can also use the autoInit prop to disable automatic connection but still use Torque's default initialization flow. This can be useful if you want to initialize the user after a callback or the user has performed a specific action on your site. For example, you might want to initialize the user after they have completed a form or clicked a button. In this case, you can simply call the initialize function without a login body.