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.customClaims is a dynamic.
UserRecord.customClaims.runtimeType returns JSObject. Note the capital S. This spelling doesn't match any other class I could find.
- Trying to cast it to a
JsObject from dart:js throws: CastError: Instance of 'PlainJavaScriptObject': type 'PlainJavaScriptObject' is not a subtype of type 'JsObject'. Note that here it refers to the same object as PlainJavaScriptObject whereas claims.runtimeType returned JSObject.
- 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 tried writing a script to get custom claims and had some trouble reading the server's response. Some observations:
UserRecord.customClaimsis adynamic.UserRecord.customClaims.runtimeTypereturnsJSObject. Note the capital S. This spelling doesn't match any other class I could find.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.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
dartifyfrom thenode_interoplibrary:That works. I would've submitted a PR with this change, but I'm not quite sure where to put this function call. The
UserRecordis a JavaScript binding with only external methods. Does this mean extendingUserRecordand changingcustomClaimsto a getter that converts it under the hood? I'm not quite sure what approach would fit in the pattern used in this package.