⚙️
Comet SDK Docs
  • Welcome to the Comet SDK!
  • Getting Started
  • Project Guides
    • Launch and mint your first NFT collection
  • Reference
    • Comet SDK Reference
      • Comet REST API
        • Collections
        • Airdrops
        • Gallery
        • Usage
      • Comet React SDK
        • Getting started
        • Components
        • Hooks
          • useAccount
          • useMint
          • useSignMessage
          • useSignTransaction
          • useGetSharedSecret
Powered by GitBook
On this page
  • API
  • Example
  1. Reference
  2. Comet SDK Reference
  3. Comet React SDK
  4. Hooks

useAccount

Get the current logged-in user's account.

You can use Comet's login system across your entire app with the useAccount hook. This hook will tell you if a user is logged in to Comet or not. If they are logged in, it will return that user's account information.

API

const account = useAccount();

The account object contains the following fields:

  • id - the Comet User ID of the logged-in user.

  • username - the username of the logged-in user.

  • address - the Solana address of the logged-in user.

If no user is logged in, account will be null.

Example

App.js
import { LoginButton, useAccount } from '@comet-labs/react';

function App() {
  const account = useAccount();
  
  return (
    <div className="App">
      <LoginButton />
      <br />
      {
        account && `Successfully logged in! Welcome, @${account.username}!`
      }
    </div>
  );
}
PreviousHooksNextuseMint

Last updated 2 years ago