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

change Connection behavior into promise based to resolve async auth issue #7

Merged
merged 13 commits into from Sep 12, 2018

Conversation

ianwang
Copy link
Contributor

@ianwang ianwang commented Sep 12, 2018

Problem

If the client makes db connection before auth success, the current implementation will not be able to subscribe successfully, and failed without any error messages.
The problem is that the auth behavior is async, so need a way to let client connect to realtime database after it passes auth checks

Major change

Before

const channel = subscribe('/my-test-path');
// at this point, client might be still checking auth data
channel.on('child_added', function(val) { 
  console.log('on child added', val);
})

After

subscribe('/my-test-path').then((channel) => {
  // here we can make sure user has already logged in!
  channel.on('child_added', function(val) {
    console.log('on child added', val);
  })
})

Patches

  • use standard to lint file
  • use babel to transpile for output instead of webpack
  • use babel-preset-env instead of babel-preset-es2015

@ianwang ianwang changed the title Fix/async auth change Connection behavior into promise based to resolve async auth issue Sep 12, 2018
@ianwang ianwang requested a review from mz026 September 12, 2018 08:00
@ianwang ianwang merged commit 969f245 into master Sep 12, 2018
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.

None yet

2 participants