supabase / supabase-flutter

Flutter integration for Supabase. This package makes it simple for developers to build secure and scalable products.
https://supabase.com/
MIT License
663 stars 155 forks source link

`OtpType.invite` can't be used with `GoTrueClient.resend` method #958

Open Pieter-JanRobrechtCronos opened 3 days ago

Pieter-JanRobrechtCronos commented 3 days ago

Describe the bug Passing OtpType.invite as type on the GoTrueClient.resend method throws an assertion method

dart:core                                          _AssertionError._throwNew
package:gotrue/src/gotrue_client.dart 564:14       GoTrueClient.resend
test/src/supabase/supabase_client_test.dart 29:25  main.<fn>

'package:gotrue/src/gotrue_client.dart': Failed assertion: line 564 pos 14: '[OtpType.signup, OtpType.emailChange].contains(type)': email must be provided for type invite

To Reproduce Steps to reproduce:

  1. Start a local Supabase instance with the CLI
  2. Run the following Dart unit test
Dart unit test ```dart import 'package:flutter_test/flutter_test.dart'; import 'package:supabase_flutter/supabase_flutter.dart'; void main({ String supabaseUrl = 'http://localhost:54321', String supabaseServiceRoleKey = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZS1kZW1vIiwicm' '9sZSI6InNlcnZpY2Vfcm9sZSIsImV4cCI6MTk4MzgxMjk5Nn0.EGIM96RAZx35lJzdJ' 'syH-qQwv8Hdp7fsn3W0YpN81IU', }) { late SupabaseClient supabase; setUp(() async { supabase = SupabaseClient( supabaseUrl, supabaseServiceRoleKey, authOptions: AuthClientOptions( pkceAsyncStorage: FakeStorageClient(), ), ); }); test('Resend invite OTP should work', () async { await supabase.auth.admin.inviteUserByEmail('fake.user@mail.com'); // Waiting a bit to not trigger the rate limit. await Future.delayed(const Duration(seconds: 1)); await supabase.auth.resend( type: OtpType.invite, email: 'fake.user@mail.com', ); }); tearDownAll(() async { await supabase.dispose(); }); } class FakeStorageClient extends GotrueAsyncStorage { FakeStorageClient({Map? storage}) : _storage = storage ?? {}; final Map _storage; @override Future getItem({required String key}) async { return _storage[key]; } @override Future removeItem({required String key}) async { _storage.remove(key); } @override Future setItem({required String key, required String value}) async { _storage[key] = value; } } ```

Expected behavior Calling the method should complete successfully and a new OTP should be sent out.

Version: On Linux/macOS ├── supabase_flutter 2.2.0 │ ├── supabase 2.0.4 │ │ ├── functions_client 2.0.0 │ │ ├── gotrue 2.3.0 │ │ ├── postgrest 2.1.0 │ │ ├── realtime_client 2.0.0 │ │ ├── storage_client 2.0.0

Supabase CLI 1.157.2

Vinzent03 commented 2 days ago

The auth-js package doesn't support that otp type as well. From what I see from this pr https://github.com/supabase/auth-js/pull/631 I think you just have to call the inviteUserByEmail method again.