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
708 stars 167 forks source link

getAuthenticatorAssuranceLevel() throws Unhandled Exception: Bad state: No element #966

Closed benjaminledet closed 2 months ago

benjaminledet commented 2 months ago

Describe the bug The getAuthenticatorAssuranceLevel()method throws an Unhandled Exception: Bad state: No element

E/flutter (11692): [ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: Bad state: No element
E/flutter (11692): #0      ListBase.firstWhere (dart:collection/list.dart:132:5)
E/flutter (11692): #1      new AMREntry.fromJson (package:gotrue/src/types/mfa.dart:280:32)
E/flutter (11692): #2      GoTrueMFAApi.getAuthenticatorAssuranceLevel.<anonymous closure> (package:gotrue/src/gotrue_mfa_api.dart:184:30)
E/flutter (11692): #3      MappedListIterable.elementAt (dart:_internal/iterable.dart:425:31)
E/flutter (11692): #4      ListIterator.moveNext (dart:_internal/iterable.dart:354:26)
E/flutter (11692): #5      new _GrowableList._ofEfficientLengthIterable (dart:core-patch/growable_array.dart:189:27)
E/flutter (11692): #6      new _GrowableList.of (dart:core-patch/growable_array.dart:150:28)
E/flutter (11692): #7      new List.of (dart:core-patch/array_patch.dart:39:18)
E/flutter (11692): #8      ListIterable.toList (dart:_internal/iterable.dart:224:7)
E/flutter (11692): #9      GoTrueMFAApi.getAuthenticatorAssuranceLevel (package:gotrue/src/gotrue_mfa_api.dart:185:10)

To Reproduce Steps to reproduce the behavior:

  1. sign in with magic link
  2. call the method supabase.auth.mfa.getAuthenticatorAssuranceLevel()

Expected behavior The method returns the assurance level.

Version (please complete the following information):

─ supabase_flutter 2.5.7
│   ├── supabase 2.2.3
│   │   ├── functions_client 2.2.0
│   │   ├── gotrue 2.8.2
│   │   ├── postgrest 2.1.2
│   │   ├── realtime_client 2.1.0
│   │   ├── storage_client 2.0.2

Additional context The toList()of the piece of code throws the exception:

  final amr = (payload['amr'] as List)
        .map((e) => AMREntry.fromJson(Map.from(e)))
        .toList();

My amr payload is :

{
  "amr": [
    {
      "method": "magiclink",
      "timestamp": 1720269381
    }
  ]
}
charles0122 commented 2 weeks ago

same issue but my payload is:


"amr": [
    {
      "method": "email/signup",
      "timestamp": 1725530782
    }
Vinzent03 commented 2 weeks ago

@dshukertjr Could you ask the auth team what possible values the method can be? Here's a long list, but I'm unsure if all of those can appear on the client.

dshukertjr commented 2 weeks ago

@Vinzent03 Auth tema confirmed that this list is all the possible values for AMRMethod. If you would like to create a PR to add all the missing ones, that would be awesome!