-
Hi all, tl;dr - swell-js site having problems with cart not being cleared when user is logged out and then being associated with the next user to log in on that browser, plus a new problem where logging out causes the carts in the admin section to lose association with the customer completely. I'm using the swell-js library in our next.js app. I'm utterly lost as to what is going on with session management and really need help. I've asked Swell directly a day ago, and just checked, but there's no reply from the devs yet and I wondered if someone else has had this or knows what is wrong or what I'm doing wrong. Bottom line is when a user logs out (I call swell.account.logout) and then a new user logs in - both me, on a dev machine but with different swell accounts - the cart from the first user becomes attached to the second user. Not just in the frontend, but in the swell admin order section where you can see carts (active/inactive etc). Now, I thought I may have a fix for this - although it doesn't quite make sense why - but another problem means I can't test it. After calling logout, the user object is empty (checked via swell.account.get) - which is correct. But if I call swell.cart.get I still see the cart from the logged out user. So I think the issue is when I log in to a new user, the library is picking that up cart up from the session, and sending it to swell and associating it with the newly logged in user. In fact, another example from yesterday - if I log the user out so the user object is now empty but the cart object is still valid - and I call swell.cart.setItems([]), it wiped the cart that was associated with that customer in the swell admin backend, even though the user was logged out. Which suggests strongly that the cart object is not being cleared in the session when the account is logged out. The potential fix - if I manually clear the swell-session cookie after log out, the cart is now emptied. I'm not sure why I'd need to manually clear it as I didn't manually set it, the library did, and I presumed the call to logout would do that? (I have read some things about the X-session token but that appears to be relevant for people working without the swell-js library which should handle it itself). But... and this is where my problem gets worse. I can't test whether this is the fix or not, because now when I log out a user, the cart in the admin section is no longer associated with that user. It's now got no owner. I'm sure this is new behaviour? I've got some older carts in there that are associated with other test accounts, but any new cart I create after logging in to a user, which then shows up as being linked to that user, loses the association to the user when I call swell.account.logout ... I'm sure that didn't happen yesterday - otherwise how would abandoned carts work if they lose their association with the user account when the users logs out? Also, what would be the point in saving a cart with no account, and why would I have some older carts that are associated with users? Sorry this is long but I'm tearing my hair out here. Maybe I'm doing something wrong, maybe Swell has a bug in the library or the system - frankly at this stage I don't care, I just need it to work and it's gone from one problem to another and this is a completely unexpected delay to our project that is incredibly frustrating! Thanks for reading and if anyone has any ideas, please do let me know. Thanks. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 9 replies
-
After wasting days waiting for support to get back to me, today I wrote a clean test app to make sure everything was working as I thought and the results are worrying and raises privacy issues, usability issues, and lost sales from a broken abandoned cart feautre. swell-js api docs say to use account.login and account.logout. What happens is this: You call account.login and it sets a session cookie in the browser. If the customer adds to their cart, it is saved in that session in the browser and it is also sent to the Swell servers. You can see the carts in the admin section under Orders/Carts. While the user is logged in, you can see that a particular cart in the admin section and who it belongs to. So far, so good. This means you can send abandoned cart emails as well because the Swell database is storing the cart items and the user... But if you call account.logout, a few things happen - but not, I would wager, what you would expect. Calls to user functions no longer work, obviously, because the user is logged out, so that's good. But the swell-session cookie that the login call created is not deleted by the logout call...? The users cart is still in the browser session. And worse than that, any call to a cart function such as setItems([]) - which empties the cart - still works and clears that cart, not only in the browser, but in Swell's database. But... that's not actually a huge problem for the user, because when you call account.logout, the cart stored in Swell's database - the one you saw earlier in Orders/Carts, and the one used for abandoned carts, is disassociated from the user that created it. It's just sat there, a bunch of item data without an owner. How can you send an abandoned cart email to a cart without an owner? The only way for that to be re-associated with the user is if they log in again - on the same device, in the same browser. If a user does that, then the Swell database re-associates that user with the cart in their database. But unless they do that, it's just orphaned and useless. And because of this design, if the user logs in to another device - say their mobile - then the items that they had put in their cart on their other device (say their laptop), are nowhere to be seen. Even though Swell has the data in their database. But because they decided to delete the association with the user, it's meaningless unless the user logs back in on the original device... Oh, and if your partner or someone else who uses the same device as you then logs in in to their account, guess what happens? Yes, any items you left in your cart - that are saved in the browser session but without a user - are now associated with their account! And not just in the frontend, but in the Swell database. That cart that was disassociated from the user when account.logout was called is now owned by someone else. That could cause some awkward discussions at the dinner table or ruin a birthday surprise... The same thing could happen if you use a public computer ie in a library etc (admittedly the chances of someone using the same shop, unless it's a huge one, is slim but it still shouldn't work like this). The solution, which I discovered after a lot of work testing this and trying to find out what on earth was going on, is to log out by deleting the swell cookie directly. Yes, that same swell cookie that was set by the swell-js login call. The one that the swell-js logout call doesn't delete. I've been waiting for days for Swell to confirm what is going on and had to push them again and again and even spend time making the test site to show them exactly what is happening and explain why it shouldn't work this way. Their reply starts "After further review, they can understand your problem with disconnecting the cart from the account. But they won't consider this a bug because other users may expect this kind of logic." Who? Who would expect this kind of logic? Why would calling logout do something different than the opposite of login? Why would it delete the cart ownership in the Swell database? They then go on to say that my solution to delete the cookie directly is the best way to do it but to also call the logout function after that "This step is an optional since it won't do anything currently with empty session, but I recommend keeping it if we would make some improvements in the future." Which I read as "in case we ever fix our API library" because it makes no sense to call a logout function after the session cookie has been deleted. All the logout function needs to do is what it should do and what you'd expect it to do - delete the damn session data - and logout. And not delete any data in the Swell database. That's it. That's what I'll be doing manually now by deleting the cookie. But that's how the function should work. I'm absolutely furious about this. Not only have I lost days of development time trying to work out what "I'm" doing wrong, when actually I'm doing nothing wrong at all. I was doing what their documentation says. The fact is their library works (or doesn't work) in a way that makes no sense. Shops using their documented way of logging out are not only causing their users to lose the ability to continue their order on another device, and not only risking a breach of data (technically unidentifiable but if it's just you and your husband/wife etc then ...), but it also means shops have abandoned carts sat in their system that they can never do anything about. I've really spent all week thinking I must be going mad or making a huge mistake, but today it was confirmed this is how the swell-js API works and Swell say it's not considered a bug... Not only has this been a week where I've lost so much time to this bad design/bad documentation/whatever you want to call it, but not even an apology - just a "not a bug as someone might expect it to work this way"... Really Swell? I'm also frustrated I've now spent a further 25 minutes writing this explanation but I don't want anyone wasting their time trying to answer my question, and hopefully it may help some other people. It's now gone 2pm on Friday afternoon and I'm going to be working all weekend but I'm still not going to make up for the lost time this has caused. As soon as our project goes live - because it's too late to walk away from Swell right now without further financial damage - the project to move to another system starts. What a waste of time. |
Beta Was this translation helpful? Give feedback.
-
I can add that it's impossible to use SSR with the SDK, impossible to handle how cookies are set (we may want to use http only cookies, customize domain, etc...), session check can take seconds (minimum 1s, which is huge in ecommerce), we don't have any view on what is prioritized (because of asana) and contributing seem a pain (I think GitHub repo are not main repo) |
Beta Was this translation helpful? Give feedback.
After wasting days waiting for support to get back to me, today I wrote a clean test app to make sure everything was working as I thought and the results are worrying and raises privacy issues, usability issues, and lost sales from a broken abandoned cart feautre.
swell-js api docs say to use account.login and account.logout.
What happens is this:
You call account.login and it sets a session cookie in the browser.
If the customer adds to their cart, it is saved in that session in the browser and it is also sent to the Swell servers. You can see the carts in the admin section under Orders/Carts.
While the user is logged in, you can see that a particular cart in the admin section and who it…