# User onboarding and authorization

All games that are opened in the metapro wallet app have access to the injected web3 provider. It means that the user's web3 account is already connected to the site.

## How to get info about the injected user?

* [ ] [**Request account**](#account-acquisition) using plugin action (1)
* [ ] Get info on whether the user is [registered](#user-registration-status) (already has an account in our project) (2)
* [ ] If the user is registered move him to the login page to get its rich data (**3A**)
* [ ] If the user is not registered move him to the [Create Account page](#user-login-on-an-unregistered-account) (**3B**)

<figure><img src="/files/zWi6Tkk1eZOUuNMi90UG" alt=""><figcaption></figcaption></figure>

### Account Acquisition

For most actions, the user's wallet address is required. Therefore, the first step is to acquire it by calling the **Request Account** action. This function requests access to the user's Ethereum accounts using the `eth_requestAccounts` method. Once the user grants permission, it retrieves the connected accounts via `eth_accounts`. If an account is available, it sets the account to a local variable and triggers the **On Account Received** condition, signaling the successful acquisition of the user's wallet address. To retrieve the user account from the plugin, use the **Get Account** expression.

### User Registration Status

The **Check If Registered** action is designed to verify whether a user is registered within the project. It sends a request to the authentication service using the user's Ethereum wallet address and the project ID. The response checks if the user has an account and has accepted the required rules. If both conditions are true, the **On Is Registered** condition is triggered, indicating the user is fully registered. If not, the [**On Is Not Registered**](#how-to-log-in-on-an-unregistered-account) condition is triggered. This check helps identify the user's registration status, which is essential for managing user flow in the game, such as enabling certain actions or features only for registered users.

## How to log in as a registered user?

* [ ] [Use login action](#authorization) from the metapro plugin (1)
* [ ] [Save user data from plugin expressions](#getting-user-data-from-expressions) to use it across the application (2)

<figure><img src="/files/mLcuxWs1u47Hd5mX2P68" alt=""><figcaption></figcaption></figure>

## How to log in on an unregistered account

* [ ] You can choose whether you want to use the referral system (referralSettingsId is needed for the [Referral System](/developer-documentation/developer-documentation-for-the-construct-3-plugin/referral-system.md))
* [ ] If you use a referral system you can handle [deep-linking with an already passed referral code](#retrieve-the-referral-code-from-a-deep-linked-invitation) (1) but anyway, it should be fillable input
* [ ] [Use login action](#authorization) from the metapro plugin (2)
* [ ] [Save user data from the plugin expression](#getting-user-data-from-expressions) to use it across the application (2)

<figure><img src="/files/wSmOpBNC0CnRca4FI6nb" alt=""><figcaption></figcaption></figure>

### Retrieve the referral code from a deep-linked invitation

The **Check Referral Code from Deeplink** action extracts the referral code from a provided deep-link by interacting with the DOM. If a referral code exists, it triggers the **On Referral Code from Deeplink Exists** condition. The referral code can then be accessed using the **Get Referral Code from Deeplink** expression => string

## Authorization

The **Login** action is used to log in or register a user within a project. It starts by generating a unique hash for the user's account and prompts the user to sign this hash with their wallet. After verifying the user's registration status, if they are not yet registered, it includes optional referral settings and code for registration. The login process retrieves an access token, and user information like username and avatar, and completes the session initialization. Once the user is successfully logged in, the **On User Logged** In condition is triggered.

## Getting user data from expressions

Additionally, the following user data can be retrieved from the plugin using various expressions:

* **Get Account:** Retrieve the currently logged-in Ethereum account => string
* **Get Avatar:** Retrieve the user's avatar image URL => string
* **Get User ID:** Retrieve the user's unique ID => string
* **Get Username:** Retrieve the user's username => string
* **Get Access Token:** Retrieve the user's authentication token => string


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.metaproprotocol.com/developer-documentation/developer-documentation-for-the-construct-3-plugin/user-onboarding-and-authorization.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
