Skip to content

Commit

Permalink
fix(google-auth): catch and display errors (#1871)
Browse files Browse the repository at this point in the history
  • Loading branch information
miguelpeixe authored and dkoo committed Aug 10, 2022
1 parent 923f8f3 commit e7ff9c3
Showing 1 changed file with 19 additions and 6 deletions.
25 changes: 19 additions & 6 deletions assets/reader-activation/auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -328,13 +328,26 @@ const convertFormDataToObject = ( formData, includedFields = [] ) =>
const checkLoginStatus = metadata => {
fetch(
`/wp-json/newspack/v1/login/google/register?metadata=${ JSON.stringify( metadata ) }`
).then( res => {
res.json().then( ( { message, data } ) => {
if ( googleLoginForm.endLoginFlow ) {
googleLoginForm.endLoginFlow( message, res.status, data );
)
.then( res => {
res
.json()
.then( ( { message, data } ) => {
if ( googleLoginForm?.endLoginFlow ) {
googleLoginForm.endLoginFlow( message, res.status, data );
}
} )
.catch( error => {
if ( googleLoginForm?.endLoginFlow ) {
googleLoginForm.endLoginFlow( error?.message );
}
} );
} )
.catch( error => {
if ( googleLoginForm?.endLoginFlow ) {
googleLoginForm.endLoginFlow( error?.message );
}
} );
} );
};

googleLoginElement.addEventListener( 'click', () => {
Expand Down Expand Up @@ -375,7 +388,7 @@ const convertFormDataToObject = ( formData, includedFields = [] ) =>
} )
.catch( error => {
if ( googleLoginForm?.endLoginFlow ) {
googleLoginForm.endLoginFlow( error.message );
googleLoginForm.endLoginFlow( error?.message );
}
if ( authWindow ) {
authWindow.close();
Expand Down

0 comments on commit e7ff9c3

Please sign in to comment.