Back

User UUID does not persist when registering Anonymous user via OAuth

  • 1
  • Accounts
neutrino
27 Jun, 2023, 20:47

On my application, I give users the ability to browse as an anonymous user via createAnonymousSession. I see that a new Anonymous user is created, with unique random UUID associated with it. However, when I let users register via the OAuth2 flow, they get succesfully registered as a user with a different user UUID. Based on the docs, I would not have expected this:"to allow the new user to convert an anonymous account to a normal account, you need to update its email and password or create an OAuth2 session." Is there a way to persist the uuid that's being assigned at the anonymous session to the registered user? What might I be doing wrong? CC @JurgenForster

TL;DR
User is experiencing an issue where the UUID of an anonymous user does not persist when registering via OAuth. The user tried testing the flow and it worked, but is unsure if any updates were made to the Appwrite software. The user asks if server side rendering is being used and what platform they are on. The user explains their current setup and how the shopping cart data is not linked to the newly created user after OAuth registration. They ask if this is intended behavior and if there is a workaround. Another user suggests using the update email API. Another user mentions that according to the code, a new ID is always generated. The original user mentions
Binyamin
27 Jun, 2023, 22:28

I know it did mentioned this in the docs, But, from what I've seen in the code it looks like a new ID will always get generate https://github.com/appwrite/appwrite/blob/master/app/controllers/api/account.php#L514

Drake
28 Jun, 2023, 00:39

You can also call the update email api

neutrino
2 Jul, 2023, 11:19

Thanks both! @Steven could you elaborate how this would work? In analogy to a shopping website, I'm currently letting anonymous users already browse my website, add items to a cart, etc. Then when I want them to submit their order, I ask them to signup. I want to enable this via OAuth. If the UUID of the user then changes, their data is not coupled to the UUID of the new user. Can I use the update email api in conjunction with OAuth for this?

Drake
2 Jul, 2023, 13:28

Have you already tried creating an oauth2 session after already having an anonymous session? What uuid are you talking about?

neutrino
9 Jul, 2023, 13:14

hi @Steven , yes I have. As per the following:

  • When user first browses to the site, an anonymous session is created. This session is also visible in the cloud interface, on the Auth tab. I write down the userid, let's refer to it as X.
  • User can use the site, do some activities like adding some items to a shopping cart. This shopping cart information is send via an Appwrite function to a custom API that stores this data, with X as the primary key. (For reasons that go beyond the scope of this explanaition, I need to rely on this custom API for now)
  • At a certain point, the user wants to signup, using the OAuth flow
  • OAuth flow completes correctly, and new user is created. This user becomes visible in the Auth tab of the cloud interface as well. However, the userid for this new user is not the same as X, but is a newly generated userid Y.
  • As a result, the shopping cart data is not linked anymore to the newly created user.

If the above is intended behavior, then I'll have to workaround this myself. However, from the docs I get the impression that anonymous users should get converted by the OAuth flow with user data being persisted within appwrite. If this is designed to be the case for everything except the userid, please let me know!

neutrino
9 Jul, 2023, 13:14

Thanks!!

Drake
9 Jul, 2023, 19:10

What platform are you on?

neutrino
16 Jul, 2023, 13:03

@Steven WebSDK (vue)

Drake
16 Jul, 2023, 15:36

Do you have any server side rendering?

neutrino
16 Jul, 2023, 17:34

Nope

neutrino
16 Jul, 2023, 17:34

but!

neutrino
16 Jul, 2023, 17:37

When testing out the flow as described above, somehow it now worked, and user_uuid of the Anonymouse WAS persisted after succesful authentication with OAuth. So the problem seems to have been solved. Was anything updated on the cloud Appwrite software side of things? I'm flabbergasted tbh

Drake
16 Jul, 2023, 17:42

No updates

Reply

Reply to this thread by joining our Discord

Reply on Discord

Need support?

Join our Discord

Get community support by joining our Discord server.

Join Discord

Get premium support

Join Appwrite Pro and get email support from our team.

Learn more