Skip to content

Commit

Permalink
Merge pull request #10181 from google/fix/10015-one-tap-redirect
Browse files Browse the repository at this point in the history
Fix one-tap re-appearing issue.
  • Loading branch information
tofumatt authored Feb 6, 2025
2 parents 8c97d5e + a622acc commit ca7f2db
Showing 1 changed file with 16 additions and 8 deletions.
24 changes: 16 additions & 8 deletions includes/Modules/Sign_In_With_Google.php
Original file line number Diff line number Diff line change
Expand Up @@ -363,8 +363,9 @@ private function render_signinwithgoogle() {
$render_buttons = $is_wp_login || $is_woocommerce_login;
$render_one_tap = ! empty( $settings['oneTapEnabled'] ) && ( $is_wp_login || ! is_user_logged_in() );

if ( empty( $redirect_to ) && ! $render_buttons && $render_one_tap && isset( $_SERVER['REQUEST_URI'] ) ) {
$redirect_to = wp_strip_all_tags( wp_unslash( $_SERVER['REQUEST_URI'] ) );
// If we aren't rendering buttons or One-tap, return early.
if ( ! $render_buttons && ! $render_one_tap ) {
return;
}

// Set the cookie time to live to 5 minutes. If the redirect_to is empty,
Expand All @@ -389,9 +390,14 @@ private function render_signinwithgoogle() {
headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
body: new URLSearchParams( response )
} );
if ( res.ok && res.redirected ) {
location.assign( res.url );
}

<?php if ( empty( $redirect_to ) && ! $render_buttons && $render_one_tap ) : // phpcs:ignore Generic.WhiteSpace.ScopeIndent.Incorrect ?>
location.reload();
<?php else : // phpcs:ignore Generic.WhiteSpace.ScopeIndent.Incorrect ?>
if ( res.ok && res.redirected ) {
location.assign( res.url );
}
<?php endif; // phpcs:ignore Generic.WhiteSpace.ScopeIndent.Incorrect ?>
} catch( error ) {
console.error( error );
}
Expand Down Expand Up @@ -425,9 +431,11 @@ private function render_signinwithgoogle() {
google.accounts.id.prompt();
<?php endif; // phpcs:ignore Generic.WhiteSpace.ScopeIndent.Incorrect ?>

const expires = new Date();
expires.setTime( expires.getTime() + <?php echo esc_js( $cookie_expire_time ); ?> );
document.cookie = "<?php echo esc_js( Authenticator::COOKIE_REDIRECT_TO ); ?>=<?php echo esc_js( $redirect_to ); ?>;expires=" + expires.toUTCString() + ";path=<?php echo esc_js( Authenticator::get_cookie_path() ); ?>";
<?php if ( ! empty( $redirect_to ) ) : // phpcs:ignore Generic.WhiteSpace.ScopeIndent.Incorrect ?>
const expires = new Date();
expires.setTime( expires.getTime() + <?php echo esc_js( $cookie_expire_time ); ?> );
document.cookie = "<?php echo esc_js( Authenticator::COOKIE_REDIRECT_TO ); ?>=<?php echo esc_js( $redirect_to ); ?>;expires=" + expires.toUTCString() + ";path=<?php echo esc_js( Authenticator::get_cookie_path() ); ?>";
<?php endif; // phpcs:ignore Generic.WhiteSpace.ScopeIndent.Incorrect ?>
} )();
<?php

Expand Down

0 comments on commit ca7f2db

Please sign in to comment.