feat: add Google One Tap response handler - #1126
Conversation
There was a problem hiding this comment.
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. |
| if (isIframeVisible) { | ||
| // In debug mode, delay removal to allow inspection | ||
| iframe.style.border = '2px solid green'; // Change border color to indicate success | ||
| setTimeout(() => { |
There was a problem hiding this comment.
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.
aa6815f to
8087b48
Compare
Deploying logto-docs-tutorials with
|
| 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 |
Deploying logto-docs with
|
| 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 |
2b9f070 to
1d52165
Compare
6b0e102 to
344e1f9
Compare
35d5879 to
8da27fd
Compare
cea2bd3 to
2f1ff0e
Compare
8da27fd to
4c407b1
Compare
b08dd86 to
49fdcbb
Compare
49fdcbb to
1a3e917
Compare
* 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
| // Build Logto sign-in URL with credential | ||
| const signInUrl = buildSignInUrl(response); | ||
|
|
||
| localStorage.setItem(isGoogleOneTapTriggeredKey, '1'); |
There was a problem hiding this comment.
Should we set local storage after the signInUrl check?
| } else { | ||
| debugLogger.error('Failed to build sign-in URL'); | ||
| } | ||
| } catch (error) { | ||
| debugLogger.error('Failed to open sign-in URL:', error); | ||
| } |
There was a problem hiding this comment.
I think these two error handling is unnecessary, as the error log should've been already logged if the buildSignInUrl fails.
| return useMemo(() => createDebugLogger(isDebugMode), [isDebugMode]); | ||
| } | ||
|
|
||
| export function useApiBaseUrl(siteConfig: SiteConfig): { |
There was a problem hiding this comment.
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.
| siteConfig.customFields?.logtoApiBaseUrl, | ||
| siteConfig.customFields?.isDevFeatureEnabled, | ||
| siteConfig.customFields?.logtoAdminConsoleUrl, |
There was a problem hiding this comment.
nit: Use destructure instead of repeating the prefix siteConfig.customFields.
| export function useGoogleOneTapConfig( | ||
| siteConfig: SiteConfig, | ||
| debugLogger: DebugLogger | ||
| ): { config: Optional<GoogleOneTapConfig> } { |
There was a problem hiding this comment.
Same here, you can call other hooks in your hook, instead of passing the results through properties.
| const parsedConfig = googleOneTapConfigSchema.safeParse( | ||
| // eslint-disable-next-line no-restricted-syntax | ||
| trySafe(() => JSON.parse(rawConfig) as unknown) | ||
| ); |
There was a problem hiding this comment.
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.
8fc8c53 to
c833d2b
Compare
|
Merge this to its parent PR for easier review. |
f22a447
into
yemq-add-local-google-one-tap
* 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
* 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
Summary
Use Google One Tap JS API instead of HTML API and add Google One Tap response handler, resolves LOG-11509