Authenticating Users

In Flutter, Hyphen Authentication functionalities are provided by the authenticate module of the SDK. This module enables users to perform various authentication tasks such as signing in, creating an account, and retrieving the user's key and account information.

Integrate Hyphen Authenticate

The HyphenAuthenticate class provides functionalities for authentication using the Hyphen SDK.

  • getAccount: Retrieves the user's account information.

  • authenticate: Initiates the authentication process with the provided webClientId.

try {
  // Retrieve user's account information
  await HyphenAuthenticate.getAccount();

  // Authenticate user with webClientId
  await HyphenAuthenticate.authenticate("your_web_client_id");
} catch (e) {
  // Handle errors
  print("Error: $e");
}

Authenticate with Google Account

Currently, Hyphen SDK only supports authentication via Google Account.

You must use the Web Client ID on the Google Cloud Platform for Google Authentication. See also Get your Google API client ID.

HyphenAuthenticate.authenticate(
    webClientId = "<YOUR-WEB-CLIENT-ID>" // ex. 201778913659-dn4bo82q6hce3kfp7vstp04b22nh5hbi.apps.googleusercontent.com
)

Once authenticated successfully, you can get your HyphenAccount and retrieve information such as the account address.

final HyphenAccount hyphenAccount = await HyphenAuthenticate.getAccount();
if (hyphenAccount != null) {
  // Access the first address
  final String firstAddress = hyphenAccount.addresses.first.address;
  print("Address: $firstAddress"); // Print the first address
} 

Last updated

Was this helpful?