magento_react_native
magento_react_native copied to clipboard
No such entity with customerId = 2
I did the installation and the application works normally. I registered a user through the application normally.
However, when I try to add a product to the cart, the following message appears: "The consumer isn't authorized to access resource."
When I click on the cart icon, the following message is displayed: "No such entity with customerId = 2"
I'm using Magento 2.4
Hello @irnjunior sorry for replying bit late, but can we discuss about the issue, if it's possible
Hi. It's all right. I would like, if possible. Thanks.
Regarding customer isn't authorized to access the resources, did you follow all the instructions explained here in wiki
especially these two
-
Set available APIs, to All, while setting up integration (Point no 4. in wiki)
-
Set expiry time for customer token very big, as explained here
4. Increase customer session expiry time
By default, customer token generated when user login is valid for 1 hour. You can change these values from Admin by selecting Stores > Settings > Configuration > Services > OAuth > Access Token Expiration.
Set it to 168 hours(7 days)
I followed all the procedures correctly.
I can create and login with the client normally through the application. I add a product to the shopping cart and at that moment the message "Current Customer Does Not Have An Active Cart" is displayed. Then, when you click on the cart icon a red message is displayed "No such entity with customerId = 2"
If I create a client account directly through the browser, these errors will not appear. These errors appear only when I create an account through the app.
Any idea how to fix this?
Ok, I understand, let me test tomorrow with my own local magento setup. Will let you know
hi @irnjunior I tested it with my local magento 2.4 setup, and created new account, at my end, I am able to add products to cart.
See, one you log in, customer cart is fetched, but since, a new user, doesn't have customer cart, an error is thrown, so in app, it is handled to request quote cart, which create a cart for customer, and again customer cart is fetched.
// wroker saga: Add description
function* getCustomerCart() {
try {
yield put({ type: MAGENTO.CUSTOMER_CART_LOADING });
const cart = yield call({
content: magento,
fn: magento.customer.getCustomerCart,
});
yield put({ type: MAGENTO.CUSTOMER_CART_SUCCESS, payload: { cart } });
} catch (error) {
yield put({
type: MAGENTO.CUSTOMER_CART_FAILURE,
payload: { errorMessage: error.message },
});
if (error.message.startsWith('No such entity with')) {
yield put({ type: MAGENTO.CREATE_QUOTE_ID_REQUEST }); // <============== look here
}
}
}
This is like a hack, and possibly the problem is occurring here.
Follow these steps
- Open app in debug mode, you will be able to see logs in developer console of chrome
- Create a new account from app
- It will take you to login screen
- Clear the console of previous log
- Enter login credentials, and hit login button
- In console, you will see
"MAGENTO_CUSTOMER_CART_FAILURE"action, see if""MAGENTO_CREATE_QUOTE_ID_REQUEST"action is dispatched or not
Your console should look something like this, in this order for new account first time login
