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.
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:
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) { ... }
}
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.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.
Passwordless Login with Flutter using Cotter's SDK
1. Approve login requests from a non-trusted device
Last modified 3yr ago