Cannot use UserRecord.customClaims
I tried writing a script to get custom claims and had some trouble reading the server's response. Some observations:
- According to the Firebase docs, the custom claims are stored as a simple JavaScript Object.
- According to this package's docs,
UserRecord.customClaimsis adynamic. -
UserRecord.customClaims.runtimeTypereturnsJSObject. Note the capital S. This spelling doesn't match any other class I could find. - Trying to cast it to a
JsObjectfromdart:jsthrows:CastError: Instance of 'PlainJavaScriptObject': type 'PlainJavaScriptObject' is not a subtype of type 'JsObject'. Note that here it refers to the same object asPlainJavaScriptObjectwhereasclaims.runtimeTypereturnedJSObject. - Modifying the code outputted by dart2js allows me to use it as a standard JS object.
The last one helped me pin down the issue -- the claims were never converted to a Dart object, so any attempt to use it as such will fail. To fix this I used dartify from the node_interop library:
final Map<String, dynamic> dartClaims = dartify(claims);
That works. I would've submitted a PR with this change, but I'm not quite sure where to put this function call. The UserRecord is a JavaScript binding with only external methods. Does this mean extending UserRecord and changing customClaims to a getter that converts it under the hood? I'm not quite sure what approach would fit in the pattern used in this package.
I came here to open the exact same issue. thanks for the temporary solution