Firebase Authentication - Simple Guide
What is Firebase Authentication?
Firebase Authentication is a service provided by Google that allows you to easily manage user
authentication in your app. It supports login using email/password, phone number, and third-party
providers like Google, Facebook, and more.
Why Use Firebase Auth?
- Easy to integrate with Flutter
- Secure and reliable
- Supports many login methods
- Works well with Firebase Firestore and Realtime Database
Steps to Use Firebase Auth in Flutter
1. Create a Firebase project at https://console.firebase.google.com
2. Add your Flutter app to the Firebase project
3. Add Firebase dependencies in your pubspec.yaml:
firebase_core
firebase_auth
4. Initialize Firebase in main.dart
5. Use FirebaseAuth to register, login, and manage users
Sample Code for Email/Password Login
FirebaseAuth auth = FirebaseAuth.instance;
// Sign up
await auth.createUserWithEmailAndPassword(
Page 1
Firebase Authentication - Simple Guide
email: '[email protected]',
password: 'password123'
);
// Login
await auth.signInWithEmailAndPassword(
email: '[email protected]',
password: 'password123'
);
// Sign out
await auth.signOut();
Tips
- Always validate user input before sending to Firebase.
- Use try-catch to handle errors like wrong password or user not found.
- Use StreamBuilder with authStateChanges to handle user sessions.
Page 2