autoLogin plugin not working like described

In documentation for autoLogin plugin it states:

  1. restore method is executed. It should open a page and set credentials.
  2. check method is executed. It should reload a page (so cookies are applied) and check that this page belongs to logged in user.
  3. If restore and check were not successful, login is executed
  4. login should fill in login form
  5. After successful login, fetch is executed to save cookies into memory or file.

but the code just checks if there is a cookie in store and then proceeds to login method.

const cookies = store[`${name}_session`];
if (!cookies) return loginAndSave();

Is there are reason why documentation is different than implementation or it is a bug/improvement for the future?

Also, there is not support for asynchronous operations happening inside those methods, but when I use methods of I object, I have to use async/await to follow order if I want to use some other non-CodeceptJS stuff (e.g. I want to read specific file and check if there is a token/cookie there and then decide whether to go to login page or no).

Is this too much to ask to provide synchronous flow when using other methods of CodeceptJS or should I follow the order mentioned above and wait for it to be established again?

possibly this PR (https://github.com/Codeception/CodeceptJS/pull/1597) fixed your issue

1 Like

I think the best answer to your question would be looking into the code

as you there is restore, then check, then trying to login on failure…

Thank you, @peterngtr. This is what I was looking for. :wink:

Also, thank you @davert for code snippet. I guess I should wait for the next release to get this, right?

yes, I’m working on it right now

1 Like