#I'm developing a CLI application using Node.js

6 messages · Page 1 of 1 (latest)

pale wolf
#
createAccount();
login();
getAccount();

here since the calls are not awaited, before login() function is executed the getAccount() function begins,

which then leads to this error meaning the user hasn't logged in and doesnt have "scope" to account in account.get()

#

@signal vine hope that helps

#

can you try encapsulating all the 3 calls in one async function and await them all?

i believe account isnt created because its not awaited and the login function is returning an error

#
import { Client, Account, ID } from 'node-appwrite';

const client = new Client()
    .setProject('runner')

const account = new Account(client);

async function createAccount() {
    const data = await account.create(ID.unique(), '[email protected]', '123456789', 'John Doe');
    console.log('Account created:', data);
}
async function getAccount() {
    const data = await account.get();
    console.log('Account:', data);
}

async function login() {
    const data = await account.createEmailPasswordSession('[email protected]', '123456789');
    console.log('Session created:', data);
}

async function main(){
  await createAccount();
  await login();
  await getAccount();
}

main();
#

are you running this script via node index.js?

#

how are you running it