Skip to content

feat: add Google One Tap response handler - #1126

Merged
darcyYe merged 15 commits into
yemq-add-local-google-one-tapfrom
yemq-add-auth-status-check
Jul 22, 2025
Merged

feat: add Google One Tap response handler#1126
darcyYe merged 15 commits into
yemq-add-local-google-one-tapfrom
yemq-add-auth-status-check

Conversation

@darcyYe

@darcyYe darcyYe commented May 29, 2025

Copy link
Copy Markdown
Contributor

Summary

Use Google One Tap JS API instead of HTML API and add Google One Tap response handler, resolves LOG-11509

@darcyYe
darcyYe requested review from a team and Copilot May 29, 2025 04:04

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR introduces a cross-domain authentication status check that verifies admin token validity using an iframe-based approach and integrates it into the Docusaurus layout. Key changes include:

  • Adding new types and enum definitions for auth status checking in src/theme/Layout/types.ts.
  • Implementing the auth status check mechanism, including debug logging, polling, and global exposure of auth state in src/theme/Layout/index.tsx.
  • Updating the Docusaurus configuration to support the new auth status check feature via new customFields.

Reviewed Changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
src/theme/Layout/types.ts Added types and enums to define the cross-domain auth status check functionality.
src/theme/Layout/index.tsx Integrated auth status checking into the layout with appropriate debug logging and polling.
docusaurus.config.ts Updated customFields to include new environment variables for the auth status check feature.

Comment thread src/theme/Layout/index.tsx Outdated
if (isIframeVisible) {
// In debug mode, delay removal to allow inspection
iframe.style.border = '2px solid green'; // Change border color to indicate success
setTimeout(() => {

Copilot AI May 29, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider extracting the various timeout durations (e.g., 5000ms and 10000ms) into named constants for better maintainability and consistency across the auth status check implementation.

Copilot uses AI. Check for mistakes.
@darcyYe
darcyYe force-pushed the yemq-add-auth-status-check branch from aa6815f to 8087b48 Compare May 29, 2025 04:05
@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented May 29, 2025

Copy link
Copy Markdown

Deploying logto-docs-tutorials with  Cloudflare Pages  Cloudflare Pages

Latest commit: c833d2b
Status: ✅  Deploy successful!
Preview URL: https://b826e951.logto-docs-tutorials.pages.dev
Branch Preview URL: https://yemq-add-auth-status-check.logto-docs-tutorials.pages.dev

View logs

@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented May 29, 2025

Copy link
Copy Markdown

Deploying logto-docs with  Cloudflare Pages  Cloudflare Pages

Latest commit: c833d2b
Status: ✅  Deploy successful!
Preview URL: https://41344087.logto-docs.pages.dev
Branch Preview URL: https://yemq-add-auth-status-check.logto-docs.pages.dev

View logs

Comment thread src/theme/Layout/index.tsx Outdated
Comment thread docusaurus.config.ts Outdated
Comment thread src/theme/Layout/index.tsx Outdated
@darcyYe
darcyYe force-pushed the yemq-add-local-google-one-tap branch from 2b9f070 to 1d52165 Compare June 23, 2025 08:43
@darcyYe
darcyYe force-pushed the yemq-add-auth-status-check branch 4 times, most recently from 6b0e102 to 344e1f9 Compare June 30, 2025 03:42
@darcyYe
darcyYe force-pushed the yemq-add-auth-status-check branch 2 times, most recently from 35d5879 to 8da27fd Compare June 30, 2025 13:48
@darcyYe
darcyYe force-pushed the yemq-add-local-google-one-tap branch from cea2bd3 to 2f1ff0e Compare June 30, 2025 14:00
@darcyYe
darcyYe force-pushed the yemq-add-auth-status-check branch from 8da27fd to 4c407b1 Compare June 30, 2025 14:04
@darcyYe
darcyYe force-pushed the yemq-add-auth-status-check branch from b08dd86 to 49fdcbb Compare July 1, 2025 04:41
@darcyYe
darcyYe force-pushed the yemq-add-auth-status-check branch from 49fdcbb to 1a3e917 Compare July 1, 2025 05:21
Darcy Ye added 3 commits July 21, 2025 14:54
* feat: add GOT callback handler

* fix: fix CSP, refactor GOT credential verifier

* chore: test GET verify API

* chore: use otp landing page

* chore: add frame-ancestor config

* chore: pop up fallback mechanism

* chore: redirect in-place and try POST

* chore: test without CSP headers for CF

* chore: test experience google credential

* chore: add debug log and check/grant storage access

* chore: update console landing page
@darcyYe darcyYe changed the title feat: check auth status on cloud console feat: add Google One Tap response handler Jul 21, 2025
// Build Logto sign-in URL with credential
const signInUrl = buildSignInUrl(response);

localStorage.setItem(isGoogleOneTapTriggeredKey, '1');

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we set local storage after the signInUrl check?

Comment on lines +62 to +67
} else {
debugLogger.error('Failed to build sign-in URL');
}
} catch (error) {
debugLogger.error('Failed to open sign-in URL:', error);
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think these two error handling is unnecessary, as the error log should've been already logged if the buildSignInUrl fails.

Comment thread src/theme/Layout/hooks.ts Outdated
return useMemo(() => createDebugLogger(isDebugMode), [isDebugMode]);
}

export function useApiBaseUrl(siteConfig: SiteConfig): {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can call

const { siteConfig } = useDocusaurusContext();

in this hook, instead of passing the siteConfig through the properties. This makes the hook easier to call at component level, as it has less dependencies of other hooks.

Comment thread src/theme/Layout/hooks.ts Outdated
Comment on lines +36 to +38
siteConfig.customFields?.logtoApiBaseUrl,
siteConfig.customFields?.isDevFeatureEnabled,
siteConfig.customFields?.logtoAdminConsoleUrl,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Use destructure instead of repeating the prefix siteConfig.customFields.

Comment thread src/theme/Layout/hooks.ts Outdated
Comment on lines +42 to +45
export function useGoogleOneTapConfig(
siteConfig: SiteConfig,
debugLogger: DebugLogger
): { config: Optional<GoogleOneTapConfig> } {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here, you can call other hooks in your hook, instead of passing the results through properties.

Comment thread src/theme/Layout/hooks.ts Outdated
Comment on lines +55 to +58
const parsedConfig = googleOneTapConfigSchema.safeParse(
// eslint-disable-next-line no-restricted-syntax
trySafe(() => JSON.parse(rawConfig) as unknown)
);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Would it be easier if we just use parse without safeParse or trySafe? Let them throw the errors since you have a try-catch block outside.

@darcyYe
darcyYe force-pushed the yemq-add-auth-status-check branch from 8fc8c53 to c833d2b Compare July 21, 2025 14:19
@darcyYe

darcyYe commented Jul 22, 2025

Copy link
Copy Markdown
Contributor Author

Merge this to its parent PR for easier review.

@darcyYe
darcyYe merged commit f22a447 into yemq-add-local-google-one-tap Jul 22, 2025
12 of 13 checks passed
@darcyYe
darcyYe deleted the yemq-add-auth-status-check branch July 22, 2025 06:10
darcyYe pushed a commit that referenced this pull request Jul 22, 2025
* feat: check auth status on cloud console

* refactor: refactor code

* fix: fix page

* chore: fix content not render bug

* chore: resume least changes

* refactor: apply try-retry instead of polling

* refactor: use google API instead of HTML component

* revert: restore pnpm-lock.yaml to base branch version

* refactor: apply browser only to GOT and add referrer policy header

* refactor: apply thorough CSP

* feat: add GOT callback handler (#1166)

* feat: add GOT callback handler

* fix: fix CSP, refactor GOT credential verifier

* chore: test GET verify API

* chore: use otp landing page

* chore: add frame-ancestor config

* chore: pop up fallback mechanism

* chore: redirect in-place and try POST

* chore: test without CSP headers for CF

* chore: test experience google credential

* chore: add debug log and check/grant storage access

* chore: update console landing page

* refactor: remove unnecessary code

* feat: only trigger GOT once

* chore: remove unused code

* refactor: refactor code
darcyYe pushed a commit that referenced this pull request Jul 28, 2025
* feat: check auth status on cloud console

* refactor: refactor code

* fix: fix page

* chore: fix content not render bug

* chore: resume least changes

* refactor: apply try-retry instead of polling

* refactor: use google API instead of HTML component

* revert: restore pnpm-lock.yaml to base branch version

* refactor: apply browser only to GOT and add referrer policy header

* refactor: apply thorough CSP

* feat: add GOT callback handler (#1166)

* feat: add GOT callback handler

* fix: fix CSP, refactor GOT credential verifier

* chore: test GET verify API

* chore: use otp landing page

* chore: add frame-ancestor config

* chore: pop up fallback mechanism

* chore: redirect in-place and try POST

* chore: test without CSP headers for CF

* chore: test experience google credential

* chore: add debug log and check/grant storage access

* chore: update console landing page

* refactor: remove unnecessary code

* feat: only trigger GOT once

* chore: remove unused code

* refactor: refactor code
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

3 participants