Sign-Up Error: "Database error saving new user"
Hi everyone,
I’m new to Supabase and currently building a Flutter app with a sign-up feature. I’ve run into an issue and could really use some help.
When I try to sign up a new user, I get this error:
Here’s the part of my code where the sign-up happens:
final supabase = Supabase.instance.client;
Future<void> _signUp() async {
if (!_formKey.currentState!.validate()) return;
setState(() {
_isLoading = true;
_errorMessage = null;
});
try {
final email = _emailController.text.trim();
final password = _passwordController.text.trim();
final authResponse = await supabase.auth.signUp(
email: email,
password: password,
);
if (authResponse.user != null) {
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(content: Text('Welcome ${authResponse.user!.email!}')),
);
Navigator.of(context).pushReplacementNamed('/choice');
} else if (authResponse.error != null) {
setState(() {
_errorMessage = authResponse.error.message;
});
}
} catch (e) {
setState(() {
_errorMessage = 'An error occurred: $e';
});
print('Error during sign-up: $e');
} finally {
setState(() {
_isLoading = false;
});
}
}
I’ve been stuck on this and can’t figure out what’s causing the "unexpected_failure" error 🥲. Has anyone else experienced this or know how to fix it? Any tips or advice would be really appreciated!
Thanks in advance!
3 Replies
You should look at the Auth and Postgres logs in the dashboard. This is almost always you have a trigger function on auth.users that is not working.
GitHub
Database error saving new user · supabase · Discussion #13043
You generally get this error when trying to invite a new user from the dashboard or when trying to insert a user into a table using the table editor in the Supabase dashboard. This error is normall...
Thanks a lot @garyaustin . Checking the logs did the trick and it was the trigger function on auth.users. All good now