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

Show Sign in with Google button when previewing page/post content, even when signed in #10301

Open
2 tasks
tofumatt opened this issue Mar 3, 2025 · 2 comments
Open
2 tasks
Assignees
Labels
Module: Sign in with Google Sign in with Google (SiwG) related issues. P2 Low priority PHP Team S Issues for Squad 1

Comments

@tofumatt
Copy link
Collaborator

tofumatt commented Mar 3, 2025

Bug Description

Currently, the Sign in with Google button Gutenberg block does not appear for users who are already signed in to their WordPress site.

But if you're previewing content, say from an edit page/post screen and then preview the draft content, the Sign in with Google button should appear, so you can preview how it would work in production.

Steps to reproduce

  1. Enable the Sign in with Google module
  2. Add a "Sign in with Google" block to a page/post
  3. Preview the post
  4. Notice the block does not appear in preview mode

Do not alter or remove anything below. The following sections will be managed by moderators only.

Acceptance criteria

  • The Sign in with Google block should appear when previewing page/post content, but should not be loaded with a real client ID to prevent sign in from happening from preview mode.

Implementation Brief

  • Update the following line to render the block if is_preview() even if the user is logged in, this will display the button on preview pages:

  • Update the includes/Modules/Sign_In_With_Google.php:

    • Update the following line to render the button if is_preview():
    • Wrap the body of the handleCredentialResponse function in a PHP if statement that only outputs the function body if is_preview() is false to ensure the button does nothing on the preview page if clicked.
      • <?php if ( $is_woocommerce && ! $is_wp_login ) : // phpcs:ignore Generic.WhiteSpace.ScopeIndent.Incorrect ?>
        response.integration = 'woocommerce';
        <?php endif; // phpcs:ignore Generic.WhiteSpace.ScopeIndent.Incorrect ?>
        try {
        const res = await fetch( '<?php echo esc_js( $login_uri ); ?>', {
        method: 'POST',
        headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
        body: new URLSearchParams( response )
        } );
        <?php if ( empty( $redirect_to ) && ! $is_login_page && $should_show_one_tap_prompt ) : // 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 );
        }
    • Update the following line to not output one tap code if is_preview() is true.

Test Coverage

  • Update the SiwG tests to confirm the button renders when is_preview() returns true and confirm there are no regressions where the button is rendered in other contexts.

QA Brief

Changelog entry

@tofumatt tofumatt added P2 Low priority Module: Sign in with Google Sign in with Google (SiwG) related issues. Team S Issues for Squad 1 labels Mar 3, 2025
@benbowler benbowler assigned benbowler and unassigned benbowler Mar 4, 2025
@eugene-manuilov eugene-manuilov self-assigned this Mar 5, 2025
@eugene-manuilov
Copy link
Collaborator

@benbowler, this part from AC ...but should not be loaded with a real client ID to prevent sign in from happening from preview mode. is missing.

Update the can_render_signinwithgoogle method in includes/Modules/Sign_In_With_Google.php to return true if is_preview() is true.

I don't think we need to change the can_render_signinwithgoogle method at all because it will affect all places where we use this method. What we need to do is to update the render_signinwithgoogle method only to render the part of the script that renders the button. This also means that we should not activate the One-Tap feature in the preview mode even if it enabled. Plus, the callback function should not do anything in the preview mode.

@benbowler
Copy link
Collaborator

Sounds good @eugene-manuilov, updated to avoid changing can_render_signinwithgoogle and I added an addition line to skip writing the handleCredentialResponse body on the preview to make the button non-functional plus I skip the oneTap code when on the preview page.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Module: Sign in with Google Sign in with Google (SiwG) related issues. P2 Low priority PHP Team S Issues for Squad 1
Projects
None yet
Development

No branches or pull requests

3 participants