1.8 KiB
1.8 KiB
🚀 Quick Authentication Guide
1️⃣ Start Backend
cd your-backend
npm run start:dev
2️⃣ Run App
flutter run
3️⃣ Login
// In your widget
final success = await ref.read(authProvider.notifier).login(
email: 'user@example.com',
password: 'Password123!',
);
4️⃣ Check Auth Status
final isAuth = ref.watch(isAuthenticatedProvider);
final user = ref.watch(currentUserProvider);
5️⃣ Use API (Auto-Authenticated!)
// Token automatically included in headers
final products = await getProducts();
final categories = await getCategories();
6️⃣ Logout
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:
{
"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! 🚀