# Sign In with Device

> **Concepts:** Learn about how [**Sign in with Device**](/features/passwordless-login.md) works.

{% hint style="warning" %}
There are major updates planned for this feature. [Contact us in Slack](https://join.slack.com/t/askcotter/shared_invite/zt-dxzf311g-5Mp3~odZNB2DwYaxIJ1dJA) so we can help you prepare for it.
{% endhint %}

### What you're building

![Sign In with Device using Cotter's Flutter SDK](/files/-M9arn7Qne8dqUy2XJOi)

### Import Cotter as a dependency

Add Cotter to your `pubspec.yaml` , then run `flutter pub get`.

```yaml
dependencies:
  cotter:
```

Check the latest releases in [pub.dev](https://pub.dev/packages/cotter#-installing-tab-). You may need to restart your flutter for it to run pod install (stop flutter run and re run it).

**For Android**: Update `minSdkVersion` to `18` [following the installation instructions](/sdk-reference/flutter.md).

### Step 1: Import and Initialize Cotter

Import Cotter in your `lib/main.dart`, then initialize it inside `HomePageState`.

```dart
import 'package:cotter/cotter.dart'; // Import Cotter

class HomePageState extends State {
  ...

  // 1️⃣ Initialize Cotter
  Cotter cotter = new Cotter(apiKeyID: API_KEY_ID); // 👈 Specify your API KEY ID here

  // 2️⃣ TODO: Make Sign Up Function
  // 3️⃣ TODO: Make Login Function
  
  @override
  Widget build(BuildContext context) { ... }
}
```

You can [create a free account at Cotter](https://dev.cotter.app) to get your `API_KEY_ID`.

{% hint style="info" %}
**Make sure you allow Trusted Devices Method in the** [**dashboard**](https://dev.cotter.app)**.**
{% endhint %}

### Step 2: Make a Sign Up Function

To sign up, call `cotter.signUpWithDevice` and input the user's email. This will create a new user in Cotter and trust the current device to allow logins. This function returns the [User object](/api-reference/user-api/user-object.md).

```dart
  // 2️⃣  Make Sign Up Function
  void signUp(BuildContext context) async {
    try {
      // 🚀 One-line Sign Up
      // Create a new user in Cotter and trust the current device
      var user = await cotter.signUpWithDevice(identifier: inputController.text);
      print(user);
    } catch (e) {
      print(e);
    }
  }
```

#### (Optional) You can also verify the user's email or phone number at this step

To verify the user's email or phone number, follow this guide **after you've finished this one**.

{% content-ref url="/pages/-MAYBXzMAs8ZfSEUGux-" %}
[Add Email/Phone Verification](/sdk-reference/flutter/sign-in-with-device/add-email-phone-verification.md)
{% endcontent-ref %}

### Step 3: Make a Login Function

To sign in, call `cotter.signInWithDevice` . If the user is logging-in from a device that they trust, they'll automatically be approved. This function returns the [Event object](/api-reference/event-object.md).

```dart
  // 3️⃣  Make Login Function
  void login(BuildContext context) async {
    try {
      // 🚀 One-line Login
      var event = await cotter.signInWithDevice(identifier: inputController.text, context: context);
      print(event);
    } catch (e) {
      print(e);
    }
  }
```

#### To get the Logged-in User Info and Access Token, follow this section:

{% content-ref url="/pages/-M9axG8HPu6f\_at6wCcT" %}
[Getting OAuth Tokens](/sdk-reference/flutter/getting-oauth-tokens.md)
{% endcontent-ref %}

{% content-ref url="/pages/-M9awQf5uqyq2X9ZO4JM" %}
[Getting the Logged-in User](/sdk-reference/flutter/getting-the-logged-in-user.md)
{% endcontent-ref %}

#### Logging-in From a Trusted Device

If the user logged-in from a trusted device, their login request will automatically be approved.

#### Logging-in From a Non-Trusted Device

If the user logged-in from a different device that is not trusted, they will be presented with a prompt asking them to approve the login from their trusted phone inside your app. We'll cover this in the next guide.

## Validating Cotter's Access Token&#x20;

Checkout how to verify the OAuth Tokens from Cotter here:

{% content-ref url="/pages/-M4HZPVawEx2QN3qLmnv" %}
[Verifying JWT Tokens](/getting-access-token/verifying-jwt-tokens.md)
{% endcontent-ref %}

## 🎉 You're done! <a href="#youre-done" id="youre-done"></a>

### Add Email/Phone Verification

You can also verify your user's email or phone number during the sign up process.

{% content-ref url="/pages/-MAYBXzMAs8ZfSEUGux-" %}
[Add Email/Phone Verification](/sdk-reference/flutter/sign-in-with-device/add-email-phone-verification.md)
{% endcontent-ref %}

### Getting the Logged-in User

Cotter's SDK automatically saves the logged-in user in your device's secure storage. Check out how to get the user information:

{% content-ref url="/pages/-M9awQf5uqyq2X9ZO4JM" %}
[Getting the Logged-in User](/sdk-reference/flutter/getting-the-logged-in-user.md)
{% endcontent-ref %}

### Getting OAuth Tokens

Cotter also automatically generates an `access_token`, `id_token` , and `refresh_token` that is securely stored in the device's secure storage. Check how to get these tokens:

{% content-ref url="/pages/-M9axG8HPu6f\_at6wCcT" %}
[Getting OAuth Tokens](/sdk-reference/flutter/getting-oauth-tokens.md)
{% endcontent-ref %}


---

# 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/sign-in-with-device.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.
