fix(auth): update getRecallerId to cast ID to int
#15
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Background
Users reported being unable to redeem rewards using points, receiving this error:
After tracing the execution flow inside
OrderStoreAction, the issue originates from this invariant check:Why does this comparison fail?
getOrdererId()and$orderer->getId()should represent the same authenticated user ID — but:getOrdererId()→ string"283"$orderer->getId()→ integer283Because the comparison uses strict (
!==), the mismatch throwsORDER.INVALID_ORDERER.Root Cause
getOrdererId()gets its value fromAuth::id().And
Auth::id()pulls the ID fromIlluminate/Auth/Guard::id()in two ways:Meaning:
$idcomes from the sessiongetRecallerId()getRecallerId()extracts the user ID from the “remember me” cookie:This function returns the head as a string, so
Auth::id()becomes a string whenever the user is authenticated via the "remember me" cookie.This creates the strict-comparison mismatch in
Order::setOrderer().Changes Introduced
getRecallerId()return value tointEnsures consistent data type for user IDs returned by
Auth::id(), regardless of session state.Auth::id()always returns an integerThis prevents regressions and ensures type consistency across the authentication layer.
Impact
Detailed documentation: https://www.notion.so/dicoding/Root-Cause-Analysis-Auth-id-Returning-string-2bd92c6a7b91804cb18dc435f77fdc58