Flutter: Email verification and password reset

Levi Matheri
Mar 17 · 3 min read

Email verification

import 'dart:async';
import 'package:firebase_auth/firebase_auth.dart';
import 'package:cloud_firestore/cloud_firestore.dart';
abstract class BaseAuth {
Future<String> signIn(String email, String password);
Future<String> signUp(String username, String email, String password);
Future<void> signOut();
}
class Auth implements BaseAuth {
final FirebaseAuth _firebaseAuth = FirebaseAuth.instance;
@override
Future<String> signUp(String username, String email, String password) async {
FirebaseUser user = await _firebaseAuth.createUserWithEmailAndPassword(email: email, password: password);
try {
await user.sendEmailVerification();
return user.uid;
} catch (e) {
print("An error occured while trying to send email verification");
print(e.message);
}
}
}

noreply@[PROJECT-NAME].firebaseapp.com

@override
Future<String> signIn(String email, String password) async {
FirebaseUser user = await _firebaseAuth.signInWithEmailAndPassword(email: email, password:password);
if (user.isEmailVerified) return user.uid;
return null;
}

Password reset

@override
Future<void> resetPassword(String email) async {
await _firebaseAuth.sendPasswordResetEmail(email: email);
}

Conclusion

Levi Matheri

Written by

Desktop & Mobile Software Engineer and Machine Learning developer

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade