Commit 07297576 authored by Ilham Maulana's avatar Ilham Maulana 💻

fix: handle error message on sign up form

parent 1e317d45
...@@ -146,12 +146,15 @@ class AuthProvider with ChangeNotifier { ...@@ -146,12 +146,15 @@ class AuthProvider with ChangeNotifier {
String token = Token.fromJson(data)!.key; String token = Token.fromJson(data)!.key;
storeAccessToken(token); storeAccessToken(token);
isAuthenticated = true; isAuthenticated = true;
message = null;
if (context.mounted) { if (context.mounted) {
context.go("/"); context.go("/");
} }
debugPrint("Signup successful $token"); debugPrint("Signup successful $token");
} else { } else {
final data = jsonDecode(response.body);
message = data["message"];
debugPrint( debugPrint(
"Error: sign up failed, ${response.statusCode}: ${response.body}"); "Error: sign up failed, ${response.statusCode}: ${response.body}");
} }
......
...@@ -40,6 +40,8 @@ class _SignUpForm extends State<SignUpForm> { ...@@ -40,6 +40,8 @@ class _SignUpForm extends State<SignUpForm> {
const String formText = "Sign In to get started"; const String formText = "Sign In to get started";
return Consumer<AuthProvider>(builder: (context, authProvider, child) { return Consumer<AuthProvider>(builder: (context, authProvider, child) {
final message = authProvider.message;
return Column( return Column(
children: [ children: [
Padding( Padding(
...@@ -120,8 +122,10 @@ class _SignUpForm extends State<SignUpForm> { ...@@ -120,8 +122,10 @@ class _SignUpForm extends State<SignUpForm> {
}, },
keyboardType: TextInputType.visiblePassword, keyboardType: TextInputType.visiblePassword,
), ),
const SizedBox( Padding(
height: 20.0, padding: const EdgeInsets.symmetric(vertical: 20.0),
child: Text(message ?? "",
style: const TextStyle(color: Colors.red)),
), ),
Column( Column(
children: [ children: [
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment