Files
retail/docs/QUICK_AUTH_GUIDE.md
2025-10-10 21:49:17 +07:00

95 lines
1.8 KiB
Markdown
Raw Permalink Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# 🚀 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!** 🚀