Skip to content

Possible conversion error when setting roles during register. #14

@legiampaoli

Description

@legiampaoli

Hello!
First of all, thanks for the great work! I am using fusionauth-typescript-client from NestJs. Works great!

I noticed that you specified attribute roles?: Set<string> for interface UserRegistration located at FusionAuthClient.d.ts. I wonder, why not use: roles?: Array<string> ?

When I try to register a given user to an application using, for example, the following code snippet:

let finalRoles = new Set<string>(registration.roles); //registration.roles is just an array of strings.

const request: RegistrationRequest = {
                generateAuthenticationToken: false,
                registration: {
                    applicationId: finalOrgId,
                    roles: finalRoles, //USED HERE TO SEND START ROLES
                    verified: true
                },
                sendSetPasswordEmail: false,
                skipRegistrationVerification: true,
            }

        return this.aarmApClient.register(aarmAPSpecificAccId, request)        
        .catch(err=>{
            throw this.genError(err, 'AARMAccount', aarmAPSpecificAccId);
        })

FusionAuth Server returns:

{"statusCode":400,"exception":{"fieldErrors":{"registration.roles":[{"code":"[invalidJSON]","message":"Invalid JSON in the request body. The property was [registration.roles]. The error was [Possible conversion error]. The detailed exception was [Cannot deserialize instance of `java.util.TreeSet<java.lang.Object>` out of START_OBJECT token\n at [Source: (org.apache.catalina.connector.CoyoteInputStream); line: 1, column: 117] (through reference chain: io.fusionauth.domain.api.user.RegistrationRequest[\"registration\"]->io.fusionauth.domain.UserRegistration[\"roles\"])]."}]}}}

To test an alternative, I tried to alter FusionAuthClient.d.ts interface UserRegistration to

roles?: Array<string>;

and the used registration.roles array directly:

registration: {
                    applicationId: finalOrgId,
                    roles: registration.roles, <-- Array of strings now!
                    verified: true
                } 

Then it just works! I wonder why not simply declare the roles type as an Array of Strings instead of a Set<string>?

Regards,
Luiz Eduardo Giampaoli

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions