95 lines
1.8 KiB
Markdown
95 lines
1.8 KiB
Markdown
# 🚀 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!** 🚀
|