LLM Notice: This documentation site supports content negotiation for AI agents. Request any page with Accept: text/markdown or Accept: text/plain header to receive Markdown instead of HTML. Alternatively, append ?format=md to any URL. All markdown files are available at /md/ prefix paths. For all content in one file, visit /llms-full.txt
Skip to main content

Authentication

Authentication in Flow Client Library (FCL) is closely tied to the concept of currentUser. In fact, fcl.authenticate and fcl.unauthenticate are simply aliases for fcl.currentUser.authenticate() and fcl.currentUser.unauthenticate(), respectively. So, let’s take a closer look at currentUser.

As an onchain app developer who uses FCL, the primary authentication functionalities revolve around how to:

  • Determine the currentUser and whether they are logged in.
  • Log a user in.
  • Log a user out.

Due to the way FCL works, to log in and sign up are essentially the same process.

Retrieve information about the current user

FCL provides two ways to get information about the current user:

  1. A promise-based method that returns a snapshot of the user’s data.
  2. A subscription-based method that triggers a callback function with the latest user information whenever it changes.

Snapshot of the current user


_10
import * as fcl from '@onflow/fcl';
_10
_10
const currentUser = await fcl.currentUser.snapshot();
_10
console.log('The Current User:', currentUser);

Subscribe to the Current User


_10
import * as fcl from '@onflow/fcl';
_10
_10
// Returns an unsubscribe function
_10
const unsubscribe = fcl.currentUser.subscribe((currentUser) => {
_10
console.log('The Current User:', currentUser);
_10
});

Authenticate and unauthenticate

The TL;DR: Call fcl.authenticate() to log in and fcl.unauthenticate() to log out.

On Flow mainnet, no additional configuration is needed, because your app’s users will go through the authentication process and can use any FCL-compatible wallet provider.

During development, you’ll likely want to configure your app to use @onflow/dev-wallet. The Quick Start guide will walk you through how to set it up.

We also recommend that you use the FCL Discovery Service to help users discover and connect to FCL-compatible wallets.

Whether you're new to building onchain, or an established veteran, we’re here to help. If you run into any issues, reach out to us on Discord — we’re happy to assist!

Rate this page