Repository navigation
fix: bound auth wait in startStoreBootstrap + catch-all for unknown routes (IR-105) #15063
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
Changes from all commits
c7700c1
774dcfa
d8bdaf9
500e6ad
a05663d
a8fe3b9
18e5384
03c256a
a79c861
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,5 @@ | ||
| import { datadogRum } from '@datadog/browser-rum' | ||
| import { captureException } from '@sentry/vue' | ||
| import { until, useAsyncState } from '@vueuse/core' | ||
| import axios from 'axios' | ||
| import { defineStore, storeToRefs } from 'pinia' | ||
|
|
@@ -23,6 +25,62 @@ async function fetchCustomNodesI18n(): Promise<CustomNodesI18n | undefined> { | |
| } | ||
| } | ||
|
|
||
| // Matches the Firebase-auth-wait timeout used elsewhere (router.ts, | ||
| // WorkspaceAuthGate.vue) so a broken/stale session fails this bounded wait | ||
| // on the same schedule those already fail theirs. | ||
| const AUTH_WAIT_TIMEOUT_MS = 16_000 | ||
| const AUTH_WAIT_RETRY_DELAY_MS = 3_000 | ||
|
|
||
| /** | ||
| * Waits for Firebase auth initialization to complete, bounded so a stale | ||
| * token or a broken auth response can never hang bootstrap forever. | ||
| * | ||
| * Only isInitialized is awaited — onAuthStateChanged fires with null for | ||
| * signed-out users, which sets isInitialized but not isAuthenticated. | ||
| * Awaiting isAuthenticated here would make every signed-out page load wait | ||
| * 35s and fire a false Sentry timeout. The router guard handles the | ||
| * login redirect for unauthenticated users separately. | ||
| * | ||
| * Retries once after a short delay; if auth is still unresolved, reports it | ||
| * to Sentry and lets bootstrap continue rather than leaving the caller stuck. | ||
| */ | ||
| async function waitForCloudAuth(): Promise<void> { | ||
| const { isInitialized } = storeToRefs(useAuthStore()) | ||
| const waitForResolution = () => | ||
| until(isInitialized).toBe(true, { | ||
| timeout: AUTH_WAIT_TIMEOUT_MS, | ||
| throwOnTimeout: true | ||
| }) | ||
|
|
||
| try { | ||
| await waitForResolution() | ||
| } catch (error) { | ||
| console.warn( | ||
| '[bootstrapStore] Auth did not resolve in time, retrying once', | ||
| error | ||
| ) | ||
| await new Promise((resolve) => | ||
| setTimeout(resolve, AUTH_WAIT_RETRY_DELAY_MS) | ||
| ) | ||
| try { | ||
| await waitForResolution() | ||
| } catch (retryError) { | ||
| console.error( | ||
| '[bootstrapStore] Auth still unresolved after retry; continuing bootstrap without confirmed auth', | ||
| retryError | ||
| ) | ||
| const err = | ||
| retryError instanceof Error ? retryError : new Error(String(retryError)) | ||
| // Report to both Datadog RUM and Sentry so the error surfaces in | ||
| // whichever observability platform is being monitored. | ||
| datadogRum.addError(err, { error_type: 'bootstrap_auth_wait_timeout' }) | ||
| captureException(err, { | ||
|
Comment on lines
+76
to
+77
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. should we encapsulate these calls into a helper so we don't leak datadog RUM calls thoughout the codebase?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hm I actually did ask for a single helper that encapsulates all loggers but evidently it was not implemented. Good catch |
||
| tags: { error_type: 'bootstrap_auth_wait_timeout' } | ||
| }) | ||
| } | ||
| } | ||
| } | ||
|
|
||
| export const useBootstrapStore = defineStore('bootstrap', () => { | ||
| const settingStore = useSettingStore() | ||
| const workflowStore = useWorkflowStore() | ||
|
|
@@ -52,9 +110,7 @@ export const useBootstrapStore = defineStore('bootstrap', () => { | |
|
|
||
| async function startStoreBootstrap() { | ||
| if (isCloud) { | ||
| const { isInitialized, isAuthenticated } = storeToRefs(useAuthStore()) | ||
| await until(isInitialized).toBe(true) | ||
| await until(isAuthenticated).toBe(true) | ||
| await waitForCloudAuth() | ||
| } | ||
|
|
||
| const userStore = useUserStore() | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about emitting a Datadog warning for unmatched routes? We can monitor for spikes in unmatched routes.