Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 27 additions & 17 deletions dogfooding/lib/screens/login_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ class LoginScreen extends StatefulWidget {

class _LoginScreenState extends State<LoginScreen> {
final _appPreferences = locator<AppPreferences>();
final _emailController = TextEditingController();
final _userNameController = TextEditingController();
var _userNameHasError = false;

Future<void> _loginWithGoogle() async {
final googleService = locator<GoogleSignIn>();
Expand Down Expand Up @@ -62,14 +63,24 @@ class _LoginScreenState extends State<LoginScreen> {
return _login(User(info: userInfo), _appPreferences.environment);
}

Future<void> _loginWithEmail() async {
final email = _emailController.text;
if (email.isEmpty) return debugPrint('Email is empty');
Future<void> _loginWithName() async {
final userName = _userNameController.text;
if (userName.isEmpty) {
setState(() {
_userNameHasError = true;
});
return debugPrint('User name is empty');
}
Comment on lines +66 to +73

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

Whitespace-only name bypasses validation.

userName.isEmpty doesn't trim, so a name of only spaces passes validation but yields an all-underscore id (via createValidId) and a blank-looking display name.

🐛 Proposed fix
   Future<void> _loginWithName() async {
-    final userName = _userNameController.text;
+    final userName = _userNameController.text.trim();
     if (userName.isEmpty) {
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
Future<void> _loginWithName() async {
final userName = _userNameController.text;
if (userName.isEmpty) {
setState(() {
_userNameHasError = true;
});
return debugPrint('User name is empty');
}
Future<void> _loginWithName() async {
final userName = _userNameController.text.trim();
if (userName.isEmpty) {
setState(() {
_userNameHasError = true;
});
return debugPrint('User name is empty');
}
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@dogfooding/lib/screens/login_screen.dart` around lines 66 - 73, The
_loginWithName validation in login_screen.dart only checks
_userNameController.text with isEmpty, so whitespace-only input still passes and
later creates a blank-looking name/id via createValidId. Update _loginWithName
to trim the entered user name before validating and use the trimmed value
consistently for the error check and subsequent login flow. Keep the fix
localized around _loginWithName, _userNameController, and createValidId so names
containing only spaces are rejected.

if (_userNameHasError) {
setState(() {
_userNameHasError = false;
});
}

final userInfo = UserInfo(
role: 'admin',
id: createValidId(email),
name: email,
id: createValidId(userName),
name: userName,
);

return _login(User(info: userInfo), _appPreferences.environment);
Expand Down Expand Up @@ -114,7 +125,7 @@ class _LoginScreenState extends State<LoginScreen> {

@override
void dispose() {
_emailController.dispose();
_userNameController.dispose();
super.dispose();
}

Expand Down Expand Up @@ -162,27 +173,26 @@ class _LoginScreenState extends State<LoginScreen> {
Padding(
padding: const EdgeInsets.symmetric(horizontal: 16),
child: TextField(
controller: _emailController,
controller: _userNameController,
style: theme.textTheme.bodyMedium?.apply(
color: Colors.white,
),
decoration: const InputDecoration(
labelText: 'Enter Email',
decoration: InputDecoration(
labelText: 'Choose display name',
isDense: true,
border: OutlineInputBorder(),
border: const OutlineInputBorder(),
errorText: _userNameHasError
? 'Please enter a name'
: null,
),
),
),
const SizedBox(height: 16),
Padding(
padding: const EdgeInsets.symmetric(horizontal: 16),
child: StreamButton.active(
label: 'Sign up with email',
icon: const Icon(
Icons.email_outlined,
color: Colors.white,
),
onPressed: _loginWithEmail,
label: 'Continue',
onPressed: _loginWithName,
),
),
const SizedBox(height: 16),
Expand Down
Loading