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

Sugar client: fix Panoptes authentication #142

Merged
merged 3 commits into from
May 6, 2021
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions lib/sugar.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,14 @@ if (typeof navigator !== 'undefined') {
var sugarClient = new SugarClient();

auth.listen('change', function() {
Promise.all(auth.checkCurrent(), auth.checkBearerToken())
.then(function([ user, token ]) {
if (user && token) {
auth.checkCurrent()
.then(function(user) {
if (user) {
sugarClient.userId = user.id;
sugarClient.authToken = token;
auth.checkBearerToken()
camallen marked this conversation as resolved.
Show resolved Hide resolved
.then(function (token) {
sugarClient.authToken = token;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe the sugar.connect() (below) needs to be in this promise then block to ensure the connection is after the token is setup

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch. I've fixed that and I'm seeing myself show up under the Active Participants heading on Talk.

})

if (process.env.NODE_ENV !== 'production') {
sugarClient.on('response', function() {
Expand All @@ -41,6 +44,7 @@ if (typeof navigator !== 'undefined') {
}
})
.catch(function(e) {
console.error(e)
throw new Error('Failed to checkCurrent auth from sugar client');
});
});
Expand Down