register static method
Register new user - returns user data
Implementation
static Future<Map<String, dynamic>> register({
required String email,
required String password,
String? name,
Map<String, dynamic>? additionalData,
}) async {
final qb = QueryBuilder(table: config.table);
// Check if user exists
final existing = await qb.where(config.emailColumn, '=', email).first();
if (existing != null) {
throw AuthException('User already exists with this email');
}
if (password.length < _config.passwordMinLength) {
throw AuthException(
'Password must be at least ${_config.passwordMinLength} characters long.',
);
}
// Hash password
final hashedPassword = Hashing().hash(password);
// Build data safely - only include columns that exist
final data = await _buildSafeUserData(
email: email,
hashedPassword: hashedPassword,
name: name,
additionalData: additionalData,
);
// Insert user
await QueryBuilder(table: config.table).insert(data);
// Get created user
final user = await QueryBuilder(table: config.table)
.where(config.emailColumn, '=', email)
.first();
if (user == null) {
throw AuthException('User could not be retrieved after registration.');
}
return _sanitizeUserData(user);
}