Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RegistrationRequest.User omitempty ineffective #77

Open
andrius4669 opened this issue Aug 30, 2023 · 1 comment
Open

RegistrationRequest.User omitempty ineffective #77

andrius4669 opened this issue Aug 30, 2023 · 1 comment

Comments

@andrius4669
Copy link

andrius4669 commented Aug 30, 2023

hello.
when i use RegisterWithContext func for the purpose of https://fusionauth.io/docs/v1/tech/apis/registrations#create-a-user-registration-for-an-existing-user such as

	res, errs, err := faClient.RegisterWithContext(
		ctx, userID, fusionauth.RegistrationRequest{
			GenerateAuthenticationToken: true,
			Registration: fusionauth.UserRegistration{
				ApplicationId: applicationID,
				Id:            rID,
				Username:      uname,
			},
			SkipRegistrationVerification: true,
		})

it always fails with errs.FieldErrors of map[user.email:[{Code:[blank]user.email Data:map[] Message:You must specify either the [user.email] or [user.username] property. If you are emailing the user you must specify the [user.email].}] user.password:[{Code:[blank]user.password Data:map[] Message:You must specify the [user.password] property.}] user.username:[{Code:[blank]user.username Data:map[] Message:You must specify either the [user.email] or [user.username] property. If you are emailing the user you must specify the [user.email].}] userId:[{Code:[duplicate]userId Data:map[] Message:A User with Id [2bc3b58e-762a-40f8-b4cf-6dcc99ec09c8] already exists.}]]
which basically means that it simultaneously complains about user.email/user.password/user.username being empty and userId already existing (not a surprise, I didn't intend to create a new user).
however, when I do:

type faReg struct {
	DisableDomainBlock           bool                        `json:"disableDomainBlock"`
	GenerateAuthenticationToken  bool                        `json:"generateAuthenticationToken"`
	Registration                 fusionauth.UserRegistration `json:"registration,omitempty"`
	SendSetPasswordEmail         bool                        `json:"sendSetPasswordEmail"`
	SkipRegistrationVerification bool                        `json:"skipRegistrationVerification"`
	SkipVerification             bool                        `json:"skipVerification"`
}

func faDoReg(faClient *fusionauth.FusionAuthClient, ctx context.Context, userId string, request faReg) (*fusionauth.RegistrationResponse, *fusionauth.Errors, error) {
	var resp fusionauth.RegistrationResponse
	var errors fusionauth.Errors

	restClient := faClient.Start(&resp, &errors)
	err := restClient.WithUri("/api/user/registration").
		WithUriSegment(userId).
		WithJSONBody(request).
		WithMethod(http.MethodPost).
		Do(ctx)
	if restClient.ErrorRef == nil {
		return &resp, nil, err
	}
	return &resp, &errors, err
}

//...
	res, errs, err := faDoReg(
		faClient, ctx, userID, faReg{
			GenerateAuthenticationToken: true,
			Registration: fusionauth.UserRegistration{
				ApplicationId: applicationID,
				Id:            rID,
				Username:      uname,
			},
			SkipRegistrationVerification: true,
		})
//...

it works without issues, because User field was not included.

please consider making fusionauth.RegistrationRequest User field a pointer type so that omitempty works, as it is ineffective for structs, and the existence of omitempty here means that it was intended to be omittable.

@mooreds
Copy link
Contributor

mooreds commented Aug 30, 2023

Thanks. I think we have a pull request open here: #61 which does a similar thing. It's been open for a while :( but we haven't had a chance to fully test the change, so haven't incorporated it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants