-
Notifications
You must be signed in to change notification settings - Fork 0
Open
Description
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 asCurrentUser)GET /me- to fetch the current user (Userrecord, serialized asCurrentUser,CurrentUseron 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 theCurrentUseron ember side)
Models and entities on the API side
- The
Usermodel hasid,email,encrypted_password,authentication_token- When sent as a reply in any of the 3 endpoints, it's serialized using
CurrentUserSerializerwhich hasid,emailandauthentication_token.
- When sent as a reply in any of the 3 endpoints, it's serialized using
Models on the ember side
- We have two models,
UserandCurrentUser. I wrote it that way due to usingreissued-emberas an example. Useris not really used for anything yet. I assumed it would have an attribute calledusernameand ahasManyrelationship withorganizationsCurrentUserhas the propertiesusername,email,authenticationToken,passwordandpasswordConfirmation.usernameis unused. I assumed we'd use it and forgot to remove itemailandauthenticationTokenare what we need to store in our session in order to authorize requests.passwordandpasswordConfirmationare 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
UserandUserProfileUserwill contain the important properties -email, encrypted_password, authentication_token, maybeorganizationsUserProfilewill contain the properties the user tends to change more often - we don't have any yet, but these would probably beusername/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
UserandUserProfile, with the same purpose Useradditionally haspasswordandpasswordConfirmationfor 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
Labels
No labels