首页 > 解决方案 > 使用 api rest 验证现有电子邮件

问题描述

我的应用程序中有一个注册屏幕。我还使用 api rest 连接到数据库(mongodb)。我在nodejs中制作这个api。在这个 api 中,电子邮件被设置为唯一的。

如果用户使用数据库中的现有电子邮件输入该电子邮件已经存在,我如何使颤振显示给用户?

先感谢您 ;)

标签: mongodbrestapiflutterdart

解决方案


type this code in your onPressed method:    

 

    http.Response response = await http.post(
                                  '//type your server-url here',
                                  headers: <String, String>{
                                    'Content-Type': 'application/json; charset=UTF-8',
                                  },
                                  body: jsonEncode(<String, String>{
                                    'name': name,
                                    'email': email,
                                    'password': password,
                                  }),
                                );
        
                                if (response.body == 'email already exists') {

//the message "email already exists" comes from your backend.
//It may differ from this message depending on your backend

                                  Scaffold.of(context).showSnackBar(
                                      SnackBar(content: Text('Email already exists')));
                                } else {
                                  Scaffold.of(context).showSnackBar(
                                      SnackBar(content: Text('Processing Data')));
                                }

推荐阅读