Skip to content

Commit

Permalink
fix(ras-acc): move my account url logic
Browse files Browse the repository at this point in the history
  • Loading branch information
chickenn00dle committed Jul 24, 2024
1 parent 234949e commit d167e83
Showing 1 changed file with 17 additions and 9 deletions.
26 changes: 17 additions & 9 deletions assets/reader-activation-auth/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,24 +43,27 @@ window.newspackRAS.push( readerActivation => {
*/
function handleAccountLinkClick( ev ) {
ev.preventDefault();
const el = ev.target.closest( 'a' );
let callback, redirect;
if ( ev.target.getAttribute( 'data-redirect' ) ) {
redirect = el.getAttribute( 'data-redirect' );
redirect = ev.target.getAttribute( 'data-redirect' );
} else {
redirect = el.getAttribute( 'href' );
redirect = ev.target.getAttribute( 'href' );
}
if ( ! redirect ) {
const closestEl = ev.target.closest( 'a' );
if ( closestEl ) {
if ( closestEl.getAttribute( 'data-redirect' ) ) {
redirect = closestEl.getAttribute( 'data-redirect' );
} else {
redirect = closestEl.getAttribute( 'href' );
}
}
}
if ( redirect && redirect !== '#' ) {
callback = () => {
window.location.href = redirect;
};
} else {
callback = () => {
// Set account URL after logging in.
el.href = newspack_ras_config.account_url;
};
}

openAuthModal( { callback } );
}

Expand Down Expand Up @@ -91,6 +94,11 @@ window.newspackRAS.push( readerActivation => {
const labelEl = link.querySelector( '.newspack-reader__account-link__label' );
if ( labelEl ) {
labelEl.textContent = reader?.authenticated ? labels.signedin : labels.signedout;

// Set my account link href if the reader is authenticated.
if ( reader?.authenticated ) {
link.setAttribute( 'href', newspack_ras_config.account_url );
}
}
} );
}
Expand Down

0 comments on commit d167e83

Please sign in to comment.