How can I wait until a element is displayed/app is ready?

In my app the login process has to do quite a bit of to and fro before the app is ready. I know when it is ready because I have a .accessibilityIdentifier attached to the text message that apears.

How can I wait on that being available?

I have tried:

        console.log("Checking if login process is finished ")
        if(await driver.elementByAccessibilityId("LoggedInTextMessage")){
        await sleep(100)

Which even if it worked would be a bit tasteless. But it does not work

I have found a way, I believe. The following code will wait for one second for the element with accessibility ID “LoggedInTextMessage” to appear. If it does not the exception gets caught.

    await driver.setImplicitWaitTimeout(1000);
    console.log("Look for LoggedInMessage")
    try {
        await driver.elementByAccessibilityId("LoggedInTextMessage")
        console.log("Got exception: " + e)