Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

auto login from saved session data #29

Closed
wants to merge 3 commits into from
Closed

auto login from saved session data #29

wants to merge 3 commits into from

Conversation

gabriel-tandil
Copy link
Contributor

save and read session data for login in a json file

increasing the waiting timeout for login because in some places with sad
connection speeds may be scarce
save and read session data for login in a json file
empty lines
@gabriel-tandil
Copy link
Contributor Author

you have a beautiful project here, a very small contribution.

@pedroslopez
Copy link
Owner

Thanks for the contribution!

Personally, I think I would prefer the library not write these things to disk and opt for whoever is using it to take care of that instead. In my eyes, there are a couple of things that may cause it to not work as intended, so I would leave it up to the user to decide what is best for what they're trying to do.

@pedroslopez
Copy link
Owner

pedroslopez commented Feb 1, 2020

@gabriel-tandil Looking at this again, I think we can do it. For whatever reason when I first reviewed this I assumed it was going into the library, but upon checking again I see that this is merely a contribution to the example. In this case, I think it's ok we provide something as a base for other people to build upon. Regardless, this whole example.js thing is less than ideal and I'd like to have a proper guide up at some point.

If you want, you can reopen this and we can get it merged. My only comments would be to rename config.json to maybe session.json as well as keeping that filename in a constant since it's used a couple times, and try to avoid the use of var, instead opting for const whenever possible and let where it's not.

pedroslopez added a commit that referenced this pull request Feb 9, 2020
This is as suggested in #29. Mainly implemeted to ease work while developing, but also serves as an example.
@iamshouvikmitra
Copy link

I want to auto generate new session if the session details found in ./session.json is old. How is that possible?

@pedroslopez
Copy link
Owner

@iamshouvikmitra An "auth_failure" event is emitted when a session restore is not possible. You can use this to detect it and delete the existing session.

@iamshouvikmitra
Copy link

Yeah, @pedroslopez would you mind sharing a snippet of the same implementation. I am a little confused about killing the previous session. And defining a new client.

Ex -

let client = new Client({session : cfg})


client.on('auth_failure', () => {
    client = new Client ()
})

doesn't seems to be an working solution.

Belfio pushed a commit to Belfio/whatsapp-web.js that referenced this pull request Jan 9, 2024
This is as suggested in pedroslopez#29. Mainly implemeted to ease work while developing, but also serves as an example.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants