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

Add loading status, fix spinner, fix back-button issue #39

Merged
merged 2 commits into from
Feb 23, 2018
Merged
Show file tree
Hide file tree
Changes from all 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
1 change: 1 addition & 0 deletions src/html/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
<div id="loading" class="loading" data-screen>
<p class="visually-hidden ">Loading…</p>
<img src="../images/loading.svg" class="loading__spinner" inline />
<p role="alert" id="loading__status"></p>
</div>
<div id="initial" data-screen data-hidden inert>
<p>Log in with email or third-party</p>
Expand Down
42 changes: 27 additions & 15 deletions src/js/decorators/filter-connections.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ var fireGAEvent = require( 'helpers/fireGAEvent' );
module.exports = function( element ) {
var form = element.form;
var url = 'https://auth-dev.mozilla.auth0.com/public/api/' + form.webAuthConfig.clientID + '/connections';
var visualStatusReport = document.getElementById( 'loading__status' );
var willRedirect = false;

ui.setLockState( element, 'loading' );

fetch( url ).then( function( response ) {
return response.json();
Expand All @@ -19,28 +23,36 @@ module.exports = function( element ) {

RPfunctionalities.forEach( function( functionality ) {
var functionalityName = functionality.getAttribute( 'data-optional-rp' );
var lastUsedConnection;
var locationString;
var silentAuthEnabled;
var newLocation;

if ( allowedRPs.indexOf( functionalityName ) === -1 ) {
ui.hide( functionality );
fireGAEvent( 'Hiding', 'Hiding login method that isn\'t supported for this RP' );
}
});

if ( window.location.hostname !== 'localhost' && window.localStorage ) {
var lastUsedConnection = window.localStorage.getItem( 'nlx-last-used-connection' );
var w = window.location.toString();
var silentAuthEnabled = w.indexOf('tried_silent_auth=true') === -1;

if ( silentAuthEnabled && lastUsedConnection && allowedRPs.indexOf( lastUsedConnection ) >= 0 ) {
window.location = w.replace('/login?', '/authorize?').replace('?client=', '?client_id=') + '&sso=true&connection=' + lastUsedConnection + '&tried_silent_auth=true'
fireGAEvent( 'Authorisation', 'Performing auto-login' );

return
if ( window.location.hostname !== 'localhost' && window.localStorage ) {
lastUsedConnection = window.localStorage.getItem( 'nlx-last-used-connection' );
locationString = window.location.toString();
silentAuthEnabled = locationString.indexOf('tried_silent_auth=true') === -1;

if ( silentAuthEnabled && lastUsedConnection && allowedRPs.indexOf( lastUsedConnection ) >= 0 ) {
willRedirect = true;
visualStatusReport.textContent = 'Autologging in with ' + lastUsedConnection;

var redirectTimeout = setTimeout(function() {
newLocation = locationString.replace('/login?', '/authorize?').replace('?client=', '?client_id=') + '&sso=true&connection=' + lastUsedConnection + '&tried_silent_auth=true';
window.location.replace( newLocation );
fireGAEvent( 'Authorisation', 'Performing auto-login with ' +lastUsedConnection );
}, 1000 );
}
}
}
});

ui.setLockState( element, 'initial' );
}, function(){
ui.setLockState( element, 'initial' );
if ( !willRedirect ) {
ui.setLockState( element, 'initial' );
}
});
};
5 changes: 5 additions & 0 deletions src/scss/components/_loading.scss
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,9 @@
margin: 3em auto;
width: 2em;
}

&__status {
text-indent: center;
margin: 1em 0;
}
}