Skip to content

Suggestion on how to organize users #13

@begedin

Description

@begedin

Endpoints

At the moment, on the API side we have the following endpoints:

  • POST /users - to register/create a User record (on the ember side as CurrentUser)
  • GET /me - to fetch the current user (User record, serialized as CurrentUser, CurrentUser on ember side)
  • POST /users/token - to log in using an email and password. Managed by single login method on ember side, not related to any model adapter, returns an authentication token (for the CurrentUser on ember side)

Models and entities on the API side

  • The User model has id, email, encrypted_password, authentication_token
    • When sent as a reply in any of the 3 endpoints, it's serialized using CurrentUserSerializer which has id, email and authentication_token.

Models on the ember side

  • We have two models, User and CurrentUser. I wrote it that way due to using reissued-ember as an example.
  • User is not really used for anything yet. I assumed it would have an attribute called username and a hasMany relationship with organizations
  • CurrentUser has the properties username, email, authenticationToken, password and passwordConfirmation.
    • username is unused. I assumed we'd use it and forgot to remove it
    • email and authenticationToken are what we need to store in our session in order to authorize requests.
    • password and passwordConfirmation are only needed initially, to register a new user. Once sent, they are never retrieved back from the API

Suggestions

Eliminate GET '/me'

Registration and fetching of the CurrentUser are handled by the CurrentUser adapter. In normal cases, the buildURL method of the adapter handles the endpoint for the entity, and there's usually one primary endpoint, accepting different methods. In our case, we have two methods, one to GET (/me) and one to POST (/users).

It complicates things a bit, so **I would like to eliminate the GET '/me' endpoint and make it GET 'users'.

Reorganize our entities

Having a CurrentUser and User both of which are actually the User entity on the API also makes things a bit confusing. Because of that, I suggest organizing it differently.

  • On the API, we have User and UserProfile
    • User will contain the important properties - email, encrypted_password, authentication_token, maybe organizations
    • UserProfile will contain the properties the user tends to change more often - we don't have any yet, but these would probably be username/display_name, first_name, last_name, photo...
  • On the API, we also have two controllers for these two entitites (remember, the GET '/me' endpoint is gone)
  • I think it makes the API more straightforward and slightly less confusing.
  • On the Ember side, we also have User and UserProfile, with the same purpose
  • User additionally has password and passwordConfirmation for registration/password reset purposes
  • This simplifies our adapters (each handles one waypoint, as is the convention) and it should simplify our session as well as future profile editing
  • There's less "special case" code in general.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions