useSignIn

Call Signature

function useSignIn(uiWalletAccount): (input?) => Promise<Output>;

Use the 'Sign In With Solana' feature of a UiWallet or UiWalletAccount.

Parameters

ParameterType
uiWalletAccountUiWalletAccount

Returns

A function that you can call to sign in with the particular wallet and address specified by the supplied UiWalletAccount

(input?): Promise<Output>;

Parameters

ParameterType
input?Omit<SolanaSignInInput, "address">

Returns

Promise<Output>

Example

import { useSignIn } from '@solana/react';
 
function SignInButton({ wallet }) {
    const csrfToken = useCsrfToken();
    const signIn = useSignIn(wallet);
    return (
        <button
            onClick={async () => {
                try {
                    const { account, signedMessage, signature } = await signIn({
                        requestId: csrfToken,
                    });
                    // Authenticate the user, typically on the server, by verifying that
                    // `signedMessage` was signed by the person who holds the private key for
                    // `account.publicKey`.
                    //
                    // Authorize the user, also on the server, by decoding `signedMessage` as the
                    // text of a Sign In With Solana message, verifying that it was not modified
                    // from the values your application expects, and that its content is sufficient
                    // to grant them access.
                    window.alert(`You are now signed in with the address ${account.address}`);
                } catch (e) {
                    console.error('Failed to sign in', e);
                }
            }}
        >
            Sign In
        </button>
    );
}

Call Signature

function useSignIn(uiWallet): (input?) => Promise<Output>;

Parameters

ParameterType
uiWalletUiWallet

Returns

A function that you can call to sign in with the supplied UiWallet

(input?): Promise<Output>;

Parameters

ParameterType
input?SolanaSignInInput

Returns

Promise<Output>

On this page