Skip to content
This repository has been archived by the owner. It is now read-only.

feat(client): notify other tabs of successful sign in/out #3144

Closed
wants to merge 1 commit into from

Conversation

@philbooth
Copy link
Contributor

@philbooth philbooth commented Oct 7, 2015

Fixes #3024, redirecting to sign-in/settings across multiple tabs.

Deliberately does not address OAuth sign-in because of potential unintended consequences from redirecting to a relier URL more than once. Maybe that is something that can be opted in to per-relier in the future. There's also no attempt to cover successful sign-up here either.

Because InterTabChannelMixin is now a dependency of the sign-in and settings views, there was a little bit of collateral damage (force_auth::initialize, the router tests) where the new dependency also needed to be met.

The change makes use of the broker capabilities, which weren't comprehensively covered by the unit tests before. So I added a bunch of assertions for their default capabilities as part of this change, since some of the new tests assumed that the capabilities would be correct.

There is no new functional test for OAuth sign-in, because I couldn't work out how to reliably test that a thing doesn't happen with Selenium. If I simply findById('fxa-signin-header'), it succeeds immediately instead of waiting for navigation. I could sleep(), but I've been bitten by those before; if you have better suggestions, I'll be happy to implement them. The OAuth behaviour is covered in the unit tests though, by stubbing hasCapability to return false and asserting that the sign-in activity does not occur.

'views/base',
'views/form',
'stache!templates/sign_in',

This comment has been minimized.

@philbooth

philbooth Oct 7, 2015
Author Contributor

I did this under the impression that we were trying to move towards alphabetical order everywhere; this list was a bit of a mess and it wasn't clear where the correct insertion point for the new dependency ('views/mixins/inter-tab-channel-mixin') was otherwise. Hope that's okay.

This comment has been minimized.

@philbooth philbooth force-pushed the phil/issue-3024 branch 2 times, most recently from 6ce5bd3 to 4aca072 Oct 7, 2015
@shane-tomlinson
Copy link
Member

@shane-tomlinson shane-tomlinson commented Oct 9, 2015

Is this ready for review @philbooth?

@philbooth
Copy link
Contributor Author

@philbooth philbooth commented Oct 9, 2015

@philbooth philbooth force-pushed the phil/issue-3024 branch from 4aca072 to da0bfd7 Oct 9, 2015
this, options);

this.unsetCapability('interTabSignIn');

This comment has been minimized.

@vladikoff

vladikoff Oct 9, 2015
Contributor

should this override this in the same way as it is done here instead of using unset: https://github.com/mozilla/fxa-content-server/blob/master/app/scripts/models/auth_brokers/fx-fennec-v1.js#L27 ? Also why is OAuth not using interTabSignIn, could we add a comment?

self.navigate('signin', {
success: t('Signed out successfully')
});
};

This comment has been minimized.

@vladikoff

vladikoff Oct 9, 2015
Contributor

nit: initialize looks overloaded, anyway to move this diff out? cc @shane-tomlinson

This comment has been minimized.

@philbooth

philbooth Oct 10, 2015
Author Contributor

Do you mean move the body of the function out or move the assignment itself out?

@philbooth philbooth force-pushed the phil/issue-3024 branch 2 times, most recently from 99de93a to c3bc19c Oct 10, 2015
@philbooth
Copy link
Contributor Author

@philbooth philbooth commented Oct 10, 2015

Have pushed fixes for your comments @vladikoff, thanks for the feedback. I assumed the second one objected to the function body rather than the assignment, but let me know if I misunderstood.

DEFAULT_XHR_TIMEOUT_MS: 2500
DEFAULT_XHR_TIMEOUT_MS: 2500,

SIGNIN_SUCCESS: 'signin.success',

This comment has been minimized.

@shane-tomlinson

shane-tomlinson Oct 12, 2015
Member

Since these are both messages can you add a prefix or suffix saying so? I wonder if there is a better place for these, closer to where they are used so some local context exists. I sometimes wonder if constants.js was a mistake.

assert.isTrue(broker.hasCapability('interTabSignIn'));
});

it('returns `true` for `emailVerificationMarketingSnippet` by default', function () {

This comment has been minimized.

@shane-tomlinson

shane-tomlinson Oct 12, 2015
Member

Thanks, I completely forgot to add these.

defaultCapabilities: _.extend({}, proto.defaultCapabilities, {
// Disable inter-tab sign-in for OAuth due to the potential for unintended
// consequences from redirecting to a relier URL more than once.
interTabSignIn: false

This comment has been minimized.

@shane-tomlinson

shane-tomlinson Oct 12, 2015
Member

Just to understand, interTabSignIn only affects the sign in message, all environments support the signout message by default?

This comment has been minimized.

@philbooth

philbooth Oct 12, 2015
Author Contributor

Yep.

function interTabSignInHandler (event) {
if (this.broker.hasCapability('interTabSignIn')) {
this.user.setSignedInAccount(event.data)
.then(this.navigate.bind(this, 'settings'));

This comment has been minimized.

@shane-tomlinson

shane-tomlinson Oct 12, 2015
Member

settings seems reasonable here, though if all brokers redirect to the /settings page, the capability check might not be necessary. In the comment here, you mention that OAuth users should not redirect to the relier as the reason for the capability. If the user is always redirected to settings, they are never redirected to the relier AFAICT.

This comment has been minimized.

@philbooth

philbooth Oct 12, 2015
Author Contributor

Wouldn't the OAuth redirect URL be the more logical place to redirect them to though? An OAuth user may not know or care what Firefox Accounts is, so finding a background tab has been redirected to our settings page might seem weird to them.

@@ -310,4 +325,11 @@ function (Cocktail, p, BaseView, FormView, SignInTemplate, Session,
);

return View;

function interTabSignInHandler (event) {

This comment has been minimized.

@shane-tomlinson

shane-tomlinson Oct 12, 2015
Member

Do you think it makes sense to take this functionality, add it to a mixin, and hook it up to /signup and /reset_password too? I'm unsure about how the /confirm_* screens should act.

This comment has been minimized.

@shane-tomlinson

shane-tomlinson Oct 12, 2015
Member

Another edge case is tab 1 is at /signin, in tab 2, the user signs up & verifies, tab 1 just sits there. Am I too bothered? Not really.

@philbooth philbooth force-pushed the phil/issue-3024 branch 3 times, most recently from f58bdcf to 8dcec33 Oct 13, 2015
@shane-tomlinson
Copy link
Member

@shane-tomlinson shane-tomlinson commented Oct 14, 2015

@philbooth - I just came across PR #2994 that sends an fxaccounts:logout message using the notifications abstraction. This is very similar to what you have here, and could probably be used in up here. I can see the DELETE message is used, but not the LOGOUT message. Potential for consolidation?

@shane-tomlinson
Copy link
Member

@shane-tomlinson shane-tomlinson commented Oct 14, 2015

FWIW, I'm not sure if I would have used loggedOut and accountDeleted functions in notifications, seems a bit like a premature abstraction.

@philbooth philbooth force-pushed the phil/issue-3024 branch 3 times, most recently from caaaf14 to dccec19 Oct 14, 2015
@philbooth philbooth force-pushed the phil/issue-3024 branch from dccec19 to 202e446 Oct 14, 2015
@shane-tomlinson shane-tomlinson added this to the FxA-0: quality milestone Oct 15, 2015
@shane-tomlinson
Copy link
Member

@shane-tomlinson shane-tomlinson commented Oct 16, 2015

@philbooth - you'll need to rebase this!

@philbooth
Copy link
Contributor Author

@philbooth philbooth commented Oct 16, 2015

you'll need to rebase this!

Yep, I'm still working on it though, not ready to be reviewed yet! :)

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

3 participants