Reputation: 31
I'm working on a Flutter app and using Supabase for authentication. When I try to sign up a user using email address, I encounter the following error:
'package:gotrue/src/gotrue_client.dart': Failed assertion: line 201 pos 16: '_asyncStorage != null': You need to provide asyncStorage to perform pkce flow.
This my code: supabase_client.dart
import 'package:supabase_flutter/supabase_flutter.dart';
class SupabaseClientService {
final SupabaseClient client;
SupabaseClientService._internal()
client = SupabaseClient(
'http',
'annon-key',
);
static final SupabaseClientService instance = SupabaseClientService._internal();
}
This is the part of my registration.dart where the error is occuring.
part of registration.dart
Future<void> _registerUser() async {
if (_formKey.currentState!.validate()) {
try {
final response = await supabase.auth.signUp(
email: _emailController.text.trim(),
password: _passwordController.text.trim(),
);
if (response.user != null) {
await supabase.from('users').insert({
'id': response.user!.id,
'email': _emailController.text,
'username': _usernameController.text,
});
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(content: Text('Registration successful. Please verify your email.')),
);
Navigator.pushReplacement(
context,
MaterialPageRoute(builder: (context) => const LoginPage()),
);
} else {
ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(content: Text('Registration failed. Please try again.')),
);
}
} on PostgrestException catch (error) {
ScaffoldMessenger.of(context).showSnackBar(SnackBar(content: Text(error.message)));
} catch (error) {
print(error);
ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(content: Text('An unexpected error occurred.')),
);
}
}
}
Specifically this line: final response = await supabase.auth.signUp
.
How can I resolve the error 'package:gotrue/src/gotrue_client.dart': Failed assertion: line 201 pos 16: '_asyncStorage != null': You need to provide asyncStorage to perform pkce flow. when using Supabase Auth in my Flutter app? What am I missing or doing incorrectly in my setup?
Upvotes: 1
Views: 218
Reputation: 524
Changed the options and it worked:
_supabaseClient = SupabaseClient(
supabaseUrl!,
supabaseAnonKey!,
authOptions: const AuthClientOptions(authFlowType: AuthFlowType.implicit),
);
}
Upvotes: -1