-
Notifications
You must be signed in to change notification settings - Fork 1
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
Feature/create claim tester account endpoints 420 #440
Feature/create claim tester account endpoints 420 #440
Conversation
…lity in BoxService
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.
Overall looks ok.
Does the claiming mechanism works as this:
- Client makes a request to the /box/identifier endpoint and gets a cookie set to it
- Client makes a request to /box/claim-account and get the account
Things to change:
- Box.service.ts
- [Line 65] The unique identifiers generation logic is not sufficient, because the ip address can be the same (if testers are on the same network) and the user agent is most likely to be chrome and samsung. I would suggest instead of that use the mongo _id generation mechanism, which will ensure the uniqueness of the value and in this case there are no need to hash anything:
const identifier = new ObjectId().toString();
- I have noticed that a lot of methods added to the
BoxService
can be moved to separate class, which handles the account claiming logic. What do you think? - [Line 118], [Line 157], [Line 184] Please instead of returning
: Promise<any>
orany
add some type to it or just remove type definition completely, TS should be able to do it for you.
-
BoxWithPopulatedRefs.type.ts
- Did you forget to rename this file, since it is in folder types and have .type. in file name, but is an interface. You can name it for example
IBoxWithPopulatedRefs
.
- Did you forget to rename this file, since it is in folder types and have .type. in file name, but is an interface. You can name it for example
-
accountClaimed.error.ts:
- May be the 403 error would be better here? At least from the client point of view. What you might want to do here is to throw or return a
ServiceError
from theBoxService
, that have field:password
and reasonNOT_UNIQUE
and on the controller level return or throw the NOT_AUTHORIZEDAPIError
. Or even move the if-statement to the controller.
- May be the 403 error would be better here? At least from the client point of view. What you might want to do here is to throw or return a
-
player.dto.ts:
- Why did you add
extends Document
here? Some tests are failing now due to it
- Why did you add
|
|
…h relevant fields
I made some changes to the logic and to the types and dtos. The controller now only has the claim-account endpoint. The prevention of claiming multiple accounts now works like this. If the request is successful an accountClaimed cookie with 15min maxAge is set. The endpoint checks if the request has the accountClaimed cookie set and returns 403 error if so. The unique identifier no longer exists with this logic so the accountClaimersIds prop in the box schema might be unnecessary. I removed the document extension from the player dto and the boxdto extension interface. I also removed the helper methods for unique identifier creation from service. Added the explicit return types to the service methods. |
Implemented the logic for claiming tester accounts.
The draw.io showed that the device identifier should be saved to box metadata in getDeviceIdentifier endpoint, but my implementation does not do that. The getDeviceIdentifier endpoint creates an identifier from hash values of request user-agent and ip and sets that as a deviceIdentifier cookie. The device identifier is only saved in to the db's accountClaimersIds array when an account it successfully claimed.
The claimAccount finds a box based on the password and checks if the deviceIdentifier has already claimed an account if not then updates the box by adding the deviceIdentifier to the accountClaimersIds and sets a claimed to true on one unclaimed tester. Then it signs an access token and returns the playerData, profile_id, accessToken and password.
Since the basicServices includeRefs has type ModelName I added the refs with
this.refsInModel as string[] as ModelName. That way the options includeRefs type doesn't need to be changed.
Enhancements to
box
module:src/box/box.controller.ts
: Added new endpointsgetDeviceIdentifier
andclaimAccount
with corresponding decorators and request handlers. These endpoints handle device identification and account claiming processes.src/box/box.service.ts
: Introduced methods for setting device identifiers, claiming accounts, and handling related errors. These methods includesetDeviceIdentifier
,createDeviceIdentifier
,getBoxWithTesters
,updateBoxIdentifierAndTesters
,claimAccount
,getTesterPlayerData
, andgetTesterAccount
.Dependency updates:
package.json
: Addedcookie-parser
and its type definitions to the dependencies list. [1] [2]Error handling:
src/box/error/accountClaimed.error.ts
: Added a new error typeaccountClaimedError
to handle cases where an account has already been claimed.Type definitions:
src/box/types/PopulatedRefs.type.ts
: Defined a new interfaceBoxWithPopulatedRefs
to represent a box with populated references to player and profile data.Cookie parsing:
src/main.ts
: Enabled cookie parsing in the main application by using thecookie-parser
middleware.