users
User profile management package. Implements the UserService interface from the auth package.
Features
- Implements auth.UserService for automatic profile creation on registration
- Separate user profiles from authentication credentials
- First/last name parsing from OAuth provider data
- Profile picture media ID (integrates with media package)
- HTTP handlers for profile retrieval and update
- PostgreSQL and SQLite support
Installation
dependencies:
users: ^1.0.0Usage
Setup
import 'package:users/users.dart';
final userService = UserServiceImpl(
PostgresUserRepository(pool),
);
// Pass to AuthService for automatic profile creation
final authService = AuthService(
accountRepository: accountRepository,
userService: userService,
// ...
);Profile Management
// Find user by account ID
final user = await userService.findByAccountId(accountId);
print(user?.fullName); // "John Doe"
// Update profile
final updated = await userService.updateUser(
user.copyWith(firstName: 'Jane'),
);
// Delete user profile
await userService.deleteByAccountId(accountId);HTTP Handlers
import 'package:users/users.dart';
// Create a router with GET /me and PATCH /me
final router = userRouter(userService);
// Or use handlers individually:
final getProfile = getUserProfileHandler(userService);
final updateProfile = updateUserProfileHandler(userService);Request Extensions
Response handleRequest(Request request) {
final user = request.authUser; // nullable
final user = request.requireAuthUser; // throws if missing
return Response.ok(jsonEncode(user.toJson()));
}