Back

Anonymous user session is not attached to new account creation

  • 1
  • Flutter
  • Accounts
Drake
20 Mar, 2023, 15:38

I looked back at Appwrite 0.12 and I didn't find anything in the API about creating an account converting an anonymous user 🧐

TL;DR
I'm having an issue where anonymous user tokens are lost when they sign up and create a new account. The Appwrite version I'm using is 8.3.0. I'm running on localhost and my endpoint is `http://10.0.2.2/v1`. I'm not sure if this is the issue or if there's something wrong with my code. I've provided a minimum reproducible code for testing. It seems that updating email or password on an anonymous session is also not working. I'm getting a `general_unauthorized_scope, User (role: guests) missing scope (account) (401)`
VincentGe
20 Mar, 2023, 15:49

👀 It is supposed to be automatic.... maybe that was the plan but we never implemented it...

PoojaBhaumik
23 Mar, 2023, 21:03

@Steven Did something change in the last few days? The updateEmail is not working anymore on an anonymous session. Get this error: AppwriteException: general_unauthorized_scope, User (role: guests) missing scope (account) (401)

Drake
23 Mar, 2023, 21:05

You're seeing this error because you don't have a valid (anonymous) session.

PoojaBhaumik
24 Mar, 2023, 04:57

But the dashboard shows a valid session. I created an anon session, and then immediately after tried to update the email. (By this time, dashboard has been updated with the new anon entry)

Drake
24 Mar, 2023, 05:36

You may not be using the session in the update email API call. Or maybe not waiting until the session is created before executing the update email API call.

What's your code?

safwan
24 Mar, 2023, 05:59

To make sure that you're attaching an email/passsword to an anonymouse session, you need to make sure that the user is IN the anonymous session.

If you could show some code, we'd have much more clarity on what could be the issue.

PoojaBhaumik
24 Mar, 2023, 08:03

This is the session object I got after I created the anonymous session. (attachment below)

TypeScript
Future<void> createAnonSession() async {
    try {
      models.Session user = await account.createAnonymousSession();
      print(user.userId);
    } catch (e) {
      throw Exception('Failed to create anon session $e');
    }
  }```

And to update user details: 

models.Account accountData = await account.updateEmail( email: email, password: password, );

TypeScript

These are separate callback calls from different buttons, which i'm triggering separately, so its not async sync issue for sure.
PoojaBhaumik
24 Mar, 2023, 09:11

Similar issue with phone auth. Logged in with phone number and OTP, all successful, got the session object as a result. In the dashboard, you see the session is created too, but getting the error general_unauthorized_scope, User (role: guests) missing scope (account) (401)

Drake
24 Mar, 2023, 13:43

How are account and Client instantiated and used?

Drake
24 Mar, 2023, 13:44

Same problem. role: guests indicates you don't have a session

PoojaBhaumik
24 Mar, 2023, 16:17

It's a simple object creation: authRepo = AppwriteAuthRepo(Account(client));

and repo class:

TypeScript
class AppwriteAuthRepo implements AuthRepo {
final Account account;
AppwriteAuthRepo(this.account); }```

client object creation is exactly like the demos/docs. 

The same account object is used in the OAuth or email-password methods and session is created then, but not working in phone now, and updating Anon details. This was working before I'm guessing.
Drake
24 Mar, 2023, 16:32

same Client and Account instance used between the session creation and updating email?

PoojaBhaumik
25 Mar, 2023, 15:46

So I created this minimum reproducible code for you to try it at your end, I was able to get the same error in this code as well. Please check the code and possibly also run it and you should get an error when you tap the update button. And if there is something wrong in my code, let me know, thanks!

https://gist.github.com/PoojaB26/8b0221e823e3749c86e4afdeecb149fc

Drake
25 Mar, 2023, 15:48

Thanks! I'll try to find some time today to test this

Drake
25 Mar, 2023, 16:05

are you using HTTPS for your endpoint?

Drake
25 Mar, 2023, 16:11
Drake
25 Mar, 2023, 16:11
Drake
25 Mar, 2023, 16:17

and i have appwrite: ^8.3.0 btw

PoojaBhaumik
29 Mar, 2023, 07:33

Sorry, I was away for sometime.

Anyway, I'm running on my localhost, is that the issue? The API endpoint given in the dashboard is this, I dont see anyway to change it. Are you running on a custom domain? But anyway it should still work on localhost as well, right?

safwan
29 Mar, 2023, 07:58

Hi @PoojaBhaumik Can you show the client init in your code?

PoojaBhaumik
29 Mar, 2023, 07:58
Drake
29 Mar, 2023, 17:38

Shouldn't be...I also tested again with http://10.0.2.2/v1 and https://10.0.2.2/v1 as my endpoints and they both worked.

What version of Appwrite do you have?

Also, the endpoint you see is always the URL you accessed Appwrite at. So if you browse to https://localhost/ (and accept the self signed warning) the endpoint will show https://localhost/v1

0xb4d1dea
31 Mar, 2023, 15:39

+1 I’m making a new flutter app where users need a session to earn and buy tokens. So they need a session, mostly they first try the app without sign up (anon session) my surprise is when users sign up enter their email/password, another user is created and lost their “anonymous” tokens (because their have a new userId)

0xb4d1dea
31 Mar, 2023, 15:44

My b, updatePassword and updateEmail should be works, I’ll try tomorrow 🐥

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