-
Notifications
You must be signed in to change notification settings - Fork 268
Cleaning up the auth (user management) code #136
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
Conversation
auth/user_mgt.go
Outdated
} | ||
|
||
func (u *UserToCreate) validatedRequest() (*identitytoolkit.IdentitytoolkitRelyingpartySignupNewUserRequest, error) { | ||
req := u.request() // it is allowed to create a user without any parameters |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tiny nit:
// creating a user without any parameters is allowed
Otherwise, it's ambiguous what "it" means.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
auth/user_mgt.go
Outdated
@@ -107,83 +97,236 @@ type UserIterator struct { | |||
|
|||
// UserToCreate is the parameter struct for the CreateUser function. | |||
type UserToCreate struct { | |||
params map[string]interface{} | |||
_req *identitytoolkit.IdentitytoolkitRelyingpartySignupNewUserRequest |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not familiar with prefixing names with underscore in go. Isn't that a python convention?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wanted to somehow indicate in the code that this field should not be accessed directly. It should always be accessed via request()
or validatedRequest()
functions. This also works well with IDE assist, since typing u.req
auto completes to u.request()
. WDYT?
auth/user_mgt.go
Outdated
@@ -107,83 +97,236 @@ type UserIterator struct { | |||
|
|||
// UserToCreate is the parameter struct for the CreateUser function. | |||
type UserToCreate struct { | |||
params map[string]interface{} | |||
_req *identitytoolkit.IdentitytoolkitRelyingpartySignupNewUserRequest | |||
fields struct { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a reason these are in a custom struct instead of just at the top level of the UserToCreate struct? If so, maybe a comment here explaining why would be helpful.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suppose the level of indirection can be removed without taking a hit on the readability. Removed.
return fmt.Errorf("photo url must be a non-empty string") | ||
} | ||
return nil | ||
} | ||
|
||
func validateEmail(val interface{}) error { | ||
email := val.(string) | ||
func validateEmail(email string) error { | ||
if email == "" { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's just slightly strange that you use len(s) == 0
above but use s == ""
here. I'm not sure which one would be preferred, but it would be nice to be consistent. Also, the actual error string is worded slightly differently.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changed to == ""
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's just slightly odd that "photo url must be a non-empty string", but "email must not be empty". Minor nit, though.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
Made the suggested changes, and left a follow up question for discussion. |
Thanks for the comments. Made the suggested changes as per comments stated here, and offline chat. |
* context signatures * VerifyIDToken context * custom token context * fix context arguments * custom token with claims context * remove TODO * integration_iid_name * propagate ctx * propagate to private functions * snippets and tests ctx * integration test user2 fix * error message * Revert "integration test user2 fix" This reverts commit 57148ce. * add context to AE, fix integration test after merge. * Revert "error message" This reverts commit db7c34a. * Merged with latest dev * Using the 1.6 import for context * Dropping call to WithContext * Cleaning up the auth package (#134) * Cleaning up the auth package * Variable grouping * Removing some punctuation; Changed id to ID in error messages * Adding a minor comment * Cleaning up the auth (user management) code (#136) * Cleaning up the auth (user management) code * Added a few more tests * Removed the fields inner type from UserToCreate and UserToUpdate * Renamed _req variables; More consistent error messages
* Breaking context change (#88) * context signatures * VerifyIDToken context * custom token context * fix context arguments * custom token with claims context * remove TODO * integration_iid_name * propagate ctx * propagate to private functions * snippets and tests ctx * integration test user2 fix * error message * Revert "integration test user2 fix" This reverts commit 57148ce. * add context to AE, fix integration test after merge. * Revert "error message" This reverts commit db7c34a. * Merged with latest dev * Using the 1.6 import for context * Dropping call to WithContext * Cleaning up the auth package (#134) * Cleaning up the auth package * Variable grouping * Removing some punctuation; Changed id to ID in error messages * Adding a minor comment * Cleaning up the auth (user management) code (#136) * Cleaning up the auth (user management) code * Added a few more tests * Removed the fields inner type from UserToCreate and UserToUpdate * Renamed _req variables; More consistent error messages * Removing golint checks from 1.6.x build (#141) * Removing golint checks from 1.6.x build * Minor reformat * Bumped version to 3.0.0 (#142) * Bumped version to 3.0.0 * Updated changelog
* context signatures * VerifyIDToken context * custom token context * fix context arguments * custom token with claims context * remove TODO * integration_iid_name * propagate ctx * propagate to private functions * snippets and tests ctx * integration test user2 fix * error message * Revert "integration test user2 fix" This reverts commit 57148ce. * add context to AE, fix integration test after merge. * Revert "error message" This reverts commit db7c34a. * Merged with latest dev * Using the 1.6 import for context * Dropping call to WithContext * Cleaning up the auth package (#134) * Cleaning up the auth package * Variable grouping * Removing some punctuation; Changed id to ID in error messages * Adding a minor comment * Cleaning up the auth (user management) code (#136) * Cleaning up the auth (user management) code * Added a few more tests * Removed the fields inner type from UserToCreate and UserToUpdate * Renamed _req variables; More consistent error messages
Since we migrated the user management API to use the Google API client (
identitytoolkit
package), this code has become bit of a readability nightmare:identitytoolkit
types (seeUserToCreate
andUserToUpdate
types).This PR addresses the above issues by:
identitytoolkit
types. Intermediate maps are no longer used.