### **Flutter Firebase Authentication | Email & Password Auth | Flutter & Firebase **

**Description:**
Looking to add **Email & Password Authentication** to your **Flutter app** using **Firebase**? In this tutorial, I’ll guide you **step-by-step** on how to integrate **Firebase Authentication** into your **Flutter app** so users can **Sign Up, Log In, and Log Out securely**.

By the end of this video, you'll have a **fully functional authentication system** using **FirebaseAuth** in Flutter!

---

## ** What You’ll Learn in This Video:**
How to **set up Firebase Authentication** in a Flutter app
How to **create a user (Sign Up) using email & password**
How to **log in and log out users**
How to **handle authentication states**
How to **fix common Firebase Authentication issues**

---

## **1⃣ Prerequisites for Firebase Authentication in Flutter**

**Flutter Installed** - [Download Flutter](https://flutter.dev/docs/get-started/install)
**Android Studio or VS Code** (for Flutter development)
**A Firebase account** - [Create an account](https://firebase.google.com/)
**A Flutter Project** (`flutter create my_app` if you don’t have one)
**FlutterFire CLI Installed**

---

## **2⃣ Set Up Firebase in Your Flutter App**

### **Step 1: Create a Firebase Project**
1. Go to [Firebase Console](https://console.firebase.google.com/)
2. Click **"Create a Project"**, enter your project name, and continue
3. Enable **Google Analytics** (optional) and click **Create Project**

---

## **3⃣ Add Firebase Authentication to Your Flutter App**

### **Step 1: Enable Email & Password Sign-In**
1. In the Firebase Console, go to **Authentication**
2. Click on the **Sign-in Method** tab
3. Enable **Email/Password Authentication**

---

## **4⃣ Configure Firebase in Flutter**

### **Step 1: Install Firebase Dependencies**
Run the following command in your Flutter project:
```bash
flutter pub add firebase_core firebase_auth
```
Then, update dependencies:
```bash
flutter pub get
```

### **Step 2: Initialize Firebase in Your App**

Open `main.dart` and initialize Firebase:

```dart
import 'package:flutter/material.dart';
import 'package:firebase_core/firebase_core.dart';
import 'firebase_options.dart';

void main() async {
WidgetsFlutterBinding.ensureInitialized();
await Firebase.initializeApp(
options: DefaultFirebaseOptions.currentPlatform,
);
runApp(MyApp());
}

class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
home: AuthScreen(),
);
}
}
```

---

## **5⃣ Implement Authentication Functions**

### **Sign Up (Register a User)**

```dart
import 'package:firebase_auth/firebase_auth.dart';

Futurevoid signUp(String email, String password) async {
try {
UserCredential userCredential = await FirebaseAuth.instance.createUserWithEmailAndPassword(
email: email,
password: password,
);
print("User registered: ${userCredential.user!.email}");
} catch (e) {
print("Error: $e");
}
}
```

---

### **Log In (Authenticate User)**

```dart
Futurevoid signIn(String email, String password) async {
try {
UserCredential userCredential = await FirebaseAuth.instance.signInWithEmailAndPassword(
email: email,
password: password,
);
print("User logged in: ${userCredential.user!.email}");
} catch (e) {
print("Error: $e");
}
}
```

---

### **Log Out (Sign Out User)**

```dart
Futurevoid signOut() async {
await FirebaseAuth.instance.signOut();
print("User signed out");
}
```

---

## **6⃣ Create a Simple UI for Authentication**

## **7⃣ Run Your App**

## ** Useful Links:**
Firebase Console: [https://console.firebase.google.com/](https://console.firebase.google.com/)
FlutterFire Docs: [https://firebase.flutter.dev/](https://firebase.flutter.dev/)
Firebase Authentication Docs: [https://firebase.google.com/docs/auth](https://firebase.google.com/docs/auth)

**Hashtags:**
#Flutter #Firebase #FirebaseAuth #FlutterFirebase #EmailAuthentication #GoogleFirebase #FlutterLogin #SignUp #FlutterTutorial #Dart #MobileAppDevelopment