This commit is contained in:
Phuoc Nguyen
2025-10-10 17:36:10 +07:00
parent 04f7042b8d
commit bdaf0b96c5
82 changed files with 4753 additions and 329 deletions

94
QUICK_AUTH_GUIDE.md Normal file
View File

@@ -0,0 +1,94 @@
# 🚀 Quick Authentication Guide
## 1⃣ Start Backend
```bash
cd your-backend
npm run start:dev
```
## 2⃣ Run App
```bash
flutter run
```
## 3⃣ Login
```dart
// In your widget
final success = await ref.read(authProvider.notifier).login(
email: 'user@example.com',
password: 'Password123!',
);
```
## 4⃣ Check Auth Status
```dart
final isAuth = ref.watch(isAuthenticatedProvider);
final user = ref.watch(currentUserProvider);
```
## 5⃣ Use API (Auto-Authenticated!)
```dart
// Token automatically included in headers
final products = await getProducts();
final categories = await getCategories();
```
## 6⃣ Logout
```dart
await ref.read(authProvider.notifier).logout();
```
---
## 🔑 Key Endpoints
| Endpoint | Auth Required | Description |
|----------|---------------|-------------|
| `POST /api/auth/login` | ❌ No | Login user |
| `POST /api/auth/register` | ❌ No | Register user |
| `GET /api/auth/profile` | ✅ Yes | Get profile |
| `GET /api/products` | ❌ No | Get products |
| `GET /api/categories` | ❌ No | Get categories |
---
## 📍 Important Files
- **Login Page:** `lib/features/auth/presentation/pages/login_page.dart`
- **Auth Provider:** `lib/features/auth/presentation/providers/auth_provider.dart`
- **API Config:** `lib/core/constants/api_constants.dart`
- **Full Docs:** `AUTH_READY.md`
---
## ⚡ Bearer Token Flow
```
Login → Token Saved → Token Set in Dio → All API Calls Auto-Authenticated
```
**You never need to manually add tokens!** 🎉
---
## 🎯 Test Credentials
Create in your backend:
```json
{
"email": "test@retailpos.com",
"password": "Test123!",
"name": "Test User"
}
```
---
## ✅ Status
- Errors: **0**
- Build: **SUCCESS**
- Auth: **READY**
- Documentation: **COMPLETE**
**Just run `flutter run` and start using!** 🚀