Back

[SOLVED] User (role: guests) missing scope (account)

  • 0
  • Accounts
  • Web
parakoopa
22 Feb, 2023, 01:26

While checking the logs for appwrite-worker-mails I see

TypeScript
** docker compose logs -f appwrite-worker-mails 
appwrite-worker-mails  | Appwrite mails worker v1 has started
appwrite-worker-mails  | 
appwrite-worker-mails  | [notice] Starting worker b5e0cc0d5cc8:8:v1-mails       
**

I have updated the required env variables and made sure they being picked up. However my it doesn't seem like any messages are firing off when I use createEmailVerification. Is there anything else I should be looking for?

TL;DR
User is missing the 'account' scope. The solution is to make sure the user has the necessary scope assigned. Additionally, the user wants to create an account and send a verification email without creating a session. The solution is to use the 'createVerification' function instead of 'createEmailSession'.
Drake
22 Feb, 2023, 01:30

are you sure the createEmailVerification api call is executing successfully?

parakoopa
22 Feb, 2023, 01:30

Appears to be, I'm not seeing any errors.

Drake
22 Feb, 2023, 01:31

what's your code and what's the response?

parakoopa
22 Feb, 2023, 01:31
TypeScript
  function sendVerificationEmail() {
    const promise = account.createVerification("/account");
    promise.then(
      response => console.log(response)
    ).catch(err => console.log(err))
    console.log("ALL DONE WITH SENDING");
  }

  function signIn(email, password) {
    const promise = account.createEmailSession(email, password);
    promise.then(
      function (response) {
        setUser(response); // Success, this is the SESSION object tho?
      },
      function (error) {
        console.log(error);
        setUser(null); // Failure
      }
    );
  }
parakoopa
22 Feb, 2023, 01:31
parakoopa
22 Feb, 2023, 01:32

ahhhhh now I have an error hmm

TypeScript
AppwriteException: User (role: guests) missing scope (account)
    at Client.eval
Drake
22 Feb, 2023, 01:36

You're using then in these functions. Because of that. Your signIn function will finish executing and return before the API call actually finishes. perhaps you're calling sendVerificationEmail() before you're actually logged in

parakoopa
22 Feb, 2023, 01:37

Whoops, I sent you signIn

parakoopa
22 Feb, 2023, 01:37

I meant to send you signUp

parakoopa
22 Feb, 2023, 01:37
TypeScript
  function signUp(email, password) {
    const promise = account.create(ID.unique(), email, password);

    promise.then(function (response) {
        console.log(response); // Success
        sendVerificationEmail();
    }, function (error) {
        console.log(error); // Failure
        setUser(null)
    });
  }
Drake
22 Feb, 2023, 01:37

creating an accoun't doesn't create a session

parakoopa
22 Feb, 2023, 01:37

right, I don't want it to. I want to create an account, say "Hey go check your email" and not let them do anything until they verify.

parakoopa
22 Feb, 2023, 01:38

ohhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh

parakoopa
22 Feb, 2023, 01:38

but your saying you have to have a session to send a verification email

Drake
22 Feb, 2023, 01:38

and btw, i suggest using async, await, try, catch over then whenver possible. all these nested then's can get really confusing down the line

parakoopa
22 Feb, 2023, 01:38

sure I can migrate to that, was just copy pasting from the docs

Drake
22 Feb, 2023, 01:38

yes, correct

parakoopa
22 Feb, 2023, 01:38

hmmm

parakoopa
22 Feb, 2023, 01:39

is there a property to check if the user is verified? I didn't see any on the account object in the docs.

Drake
22 Feb, 2023, 01:41

Ya it's emailVerification

See https://appwrite.io/docs/models/account

parakoopa
22 Feb, 2023, 01:41

this guy appwrites

parakoopa
22 Feb, 2023, 01:41

thank you!

Drake
22 Feb, 2023, 01:42

[SOLVED] User (role: guests) missing scope (account)

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