# Getting the Logged-in User

When the user authenticates successfully, Cotter's SDK will automatically store the logged-in user in the device's secure storage.

To get the user information, call `cotter.getUser()` :

```dart
Cotter cotter = new Cotter(apiKeyID: API_KEY_ID);
void getLoggedInUser() async {
  try {
    var user = await cotter.getUser();
    print(user);
  } catch (e) {
    print(e);
  }
}
```

This function returns the [User object](/api-reference/user-api/user-object.md).

If the user's `id_token` is expired, this function will automatically attempt to refresh the token, resulting in refreshing the user's session, and return the User object if successful. Otherwise, this function will throw an error if the session is expired.

{% hint style="warning" %}
Please use the identifier (email/phone number) as your main way to identify users, **Cotter's User ID is deprecated.**
{% endhint %}


---

# 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.cotter.app/sdk-reference/flutter/getting-the-logged-in-user.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.
