Back

[SOLVED] Delete anonymous user?

  • 0
  • Flutter
  • Web
  • Databases
  • Accounts
  • Functions
djcali
28 Jul, 2023, 05:59

Hello,

I have a situation where after a user signs up in my Flutter Web App I send them an email with a link to verify it. If they get their email from another device other than the one used to sign up, they won't have a session. So in this case I create an anonymous session which is needed to run the cloud function which verifies the email. Now after testing I have a bunch of anonymous users, is there a way to delete these or am i going about this the totally wrong way. Thanks!

TypeScript

    useMemoized(() async {
      // Don't try to get session if initializing or authenticated
      if (auth == AuthStatus.initializing || auth == AuthStatus.authenticated) {
        return;
      }

      try {
        /// Try to get session, if there is a current session then
        /// verify the email.
        await ref
            .read(appwriteAccountProvider)
            .getSession(sessionId: 'current');

        await _verifyEmail();
      } on AppwriteException catch (e) {
        debugPrint(e.message);

        /// There is no session. Create anon session so we can verify email.
        await ref.read(appwriteAccountProvider).createAnonymousSession();
        await _verifyEmail();
      }
    }, [auth]);```
TL;DR
The user is trying to delete anonymous users created in their Flutter web app after signing up and receiving a verification email. They created an anonymous session to run a cloud function for email verification. However, they now have a bunch of anonymous users and are asking if there is a way to delete them. The user also included code for reference. Solution: The user does not need to create an anonymous session for email verification. They can use the "updateEmailVerification" endpoint without a session. Therefore, they can simply remove the code that creates an anonymous session.
Drake
28 Jul, 2023, 08:04

No, you're not supposed to create an anonymous session. They don't need a session to complete the email verification

Drake
28 Jul, 2023, 08:04

You also don't need a cloud function...

djcali
28 Jul, 2023, 15:30

I didn't explain correctly. I am not using the default way of email verification with appwrite. I am generating a custom email with logos etc. Thats why i had to use a function. When the user fills out the sign up form, I have a function that creates the account, then creates a user data document which will hold some other user info, then adds a verification document with a secret code, and lastly sends out the custom email with a link to verify.

When the user clicks a link something like https://mydomain.com/email-verification/a87d9110-2d02-11ee-ac3d-13674e03685f This will bring them to a page that will first check that the secret and userid is a match in the verifications collection, then I use the updateEmailVerification endpoint to set them as verified.

Where i run into the issue is as i stated above, need a session to be able to run that function from the verifiy email page.

Hope that helps you to understand my logic.

Drake
28 Jul, 2023, 17:25

i see. and you're using an older version of appwrite?

Drake
28 Jul, 2023, 17:25

actually never mind. it doesn't quite matter

Drake
28 Jul, 2023, 17:26

you can set up a function to delete those anonymous users

djcali
28 Jul, 2023, 17:29

Thanks. Maybe run nightly or something like that. What would be your approach?

djcali
28 Jul, 2023, 17:33

I’m on v1.3.4. Is that the latest?

Drake
28 Jul, 2023, 17:43

sure

Drake
28 Jul, 2023, 17:45

no the latest is 1.3.8.

Actually...do you need to create an anonymous user? can't you grant everyone access to the function?

djcali
28 Jul, 2023, 17:47

Oh. I can change to ‘’any’’ and that should work.

djcali
28 Jul, 2023, 17:47

I’ll report back

djcali
29 Jul, 2023, 01:01

That solution worked.

djcali
29 Jul, 2023, 01:02

[SOLVED] Delete anonymous user?

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