Back

[SOLVED] 400 Invalid Email: Value must be a valid email address

  • 0
  • Users
  • Accounts
  • Flutter
Monzim
20 May, 2023, 07:39

For some device when creating new account it showing this error for some device. Even though the email is valid.

TypeScript
400 Invalid Email: Value must be a valid email address
TL;DR
Users are experiencing a 400 Invalid Email error when creating a new account on some devices. The issue seems to be related to the `textEditingController` listener. The code appears to be correct, and the email is valid. Waiting for a developer to comment and suggest a solution. Solution: No solution provided yet.
safwan
20 May, 2023, 10:16

Could you share the code where you're creating the new account?

Monzim
20 May, 2023, 11:27
TypeScript
class AuthenticationHelper implements AuthenticationBase {
  final logger = Logger('AuthenticationHelper');

  final Account account;
  AuthenticationHelper(this.account);

  @override
  Future<AuthenticationResponse> createAccount({
    required String email,
    required String password,
    required String? userName,
  }) async {
    try {
      final user = await account.create(
        userId: UuidHelper.userID(),
        email: email,
        password: password,
        name: userName,
      );

      // return AuthenticationResponse.success(user: user);
      return await login(email: user.email, password: password);
    } on AppwriteException catch (e) {
      return AuthenticationResponse.failure(exception: e);
    }
  }

  @override
  Future<AuthenticationResponse> login(
      {required String email, required String password}) async {
    try {
      final session =
          await account.createEmailSession(email: email, password: password);
      final user = await account.get();

      return AuthenticationResponse.success(
        user: user,
        message:
            'Logged in as ${user.name} successfully. Session: ${session.ip}',
      );
    } on AppwriteException catch (e) {
      return AuthenticationResponse.failure(exception: e);
    }
  }
}
safwan
20 May, 2023, 11:37

okay this seems fine. do you mind sharing the code where you call the login/signup functions?

Monzim
20 May, 2023, 11:46
TypeScript
      onPressed: loading
          ? null
          : () {
              final valid = formKey.currentState?.validate();

              final emailExtention = ref.read(emailExtentionProvider);
              final department = ref.read(whatDepartmentProvider);
              final email = this.email.trim() + emailExtention;

              if (valid ?? false) {
                ref.read(authenticationServiceProvider.notifier).createAccount(
                      email: email,
                      password: password,
                      userName:
                          '${department?.value.substring(0, 1)}$studentId',
                    );
              }
            },
safwan
20 May, 2023, 12:16

Weird. I cannot find any mistake in your code.

safwan
20 May, 2023, 12:16

Have you tried checking DevTools to see what happens when you call the functions?

Monzim
20 May, 2023, 12:18

I manually check the code multiple times but could not figure it out. This problem happing for some devices. Today I open the app for beta testing and 30 to 40% users facing this problem. Even though the code looks right.

Monzim
20 May, 2023, 12:18

Yes But not issue found for my end. Working well on my simulator and my real device

safwan
20 May, 2023, 12:21

are you using appwrite cloud? or a self-hosted instance?

Monzim
20 May, 2023, 12:32

self hosting.

safwan
20 May, 2023, 12:33

I'm honestly not sure what might be causing this. I suggest waiting for a developer to comment.

Monzim
20 May, 2023, 12:45

Okay

D5
20 May, 2023, 14:20

Why you're login after registration?

D5
20 May, 2023, 14:20

That's not needed

D5
20 May, 2023, 14:20

Try deleting that

D5
20 May, 2023, 14:21

Also try doing print(email) just after the function that supposedly is giving an error to see what does the email field contains

D5
20 May, 2023, 14:21

Send here what's de email field result

Monzim
20 May, 2023, 15:55

Okay. I got the problem. It was for the textEditingController listener problem. Thanks

Monzim
20 May, 2023, 15:55

[SOLVED] 400 Invalid Email: Value must be a valid email address

Reply

Reply to this thread by joining our Discord

Reply on Discord

Need support?

Join our Discord

Get community support by joining our Discord server.

Join Discord

Get premium support

Join Appwrite Pro and get email support from our team.

Learn more