Flutter – Sign in with Device

Cotter's Passwordless SDK authenticates your user based on their device. It allows a seamless, fast, and secure way for your user to login to your React Native App.

Sign in with Device

In this guide we'll allow users to Sign In with Device using Cotter's SDK.

Add Cotter's SDK to your pubspec.yaml , then run flutter pub get. You may need to restart your flutter for it to run pod install (stop flutter run and re run it).

dependencies:
  cotter:

For Android: Update minSdkVersion to 18 following the installation instructions.

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

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️⃣ Sign Up Function
  void signUp() async {
    try {
      // 🚀 One-line Sign Up
      var user = await cotter.signUpWithDevice(identifier: inputController.text);
    } catch (e) {
      print(e)
    }
  }
  
  // 3️⃣ Login Function
  void login(BuildContext context) async {
    try {
      // 🚀 One-line Login
      var event = await cotter.signInWithDevice(identifier: inputController.text, context: context);
    } catch (e) {
      print(e)
    }
  }
  
  @override
  Widget build(BuildContext context) { ... }
} 

You can create a free account at Cotter to get your API_KEY_ID.

Sign Up: Call cotter.signUpWithDevice and input the user's email, phone, or username. This will create a new user in Cotter and trust the current device to allow logins. This function returns a User object.

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 an Event object.

Make sure you allow Trusted Devices Method in the dashboard.

🎉 That's It!

Simply call the signUp and login functions from your login page, and you can allow your users to Sign In with Device with just 1 tap.

What's Next?

1. Approve login requests from a non-trusted device

2. Getting the Logged-in User

3. Getting Access Token, ID Token, and Refresh Token

Last updated