1- import { until } from " @vueuse/core" ;
2- import { storeToRefs } from " pinia" ;
1+ import { until } from ' @vueuse/core'
2+ import { storeToRefs } from ' pinia'
33import {
44 createRouter ,
55 createWebHashHistory ,
6- createWebHistory ,
7- } from " vue-router" ;
8- import type { RouteLocationNormalized } from " vue-router" ;
6+ createWebHistory
7+ } from ' vue-router'
8+ import type { RouteLocationNormalized } from ' vue-router'
99
10- import { useFeatureFlags } from " @/composables/useFeatureFlags" ;
11- import { isCloud , isDesktop } from " @/platform/distribution/types" ;
12- import { useTelemetry } from " @/platform/telemetry" ;
13- import { useDialogService } from " @/services/dialogService" ;
14- import { useAuthStore } from " @/stores/authStore" ;
15- import { useUserStore } from " @/stores/userStore" ;
16- import LayoutDefault from " @/views/layouts/LayoutDefault.vue" ;
10+ import { useFeatureFlags } from ' @/composables/useFeatureFlags'
11+ import { isCloud , isDesktop } from ' @/platform/distribution/types'
12+ import { useTelemetry } from ' @/platform/telemetry'
13+ import { useDialogService } from ' @/services/dialogService'
14+ import { useAuthStore } from ' @/stores/authStore'
15+ import { useUserStore } from ' @/stores/userStore'
16+ import LayoutDefault from ' @/views/layouts/LayoutDefault.vue'
1717
18- import { captureOAuthRequestId } from " @/platform/cloud/oauth/oauthState" ;
19- import { installDesktopLoginRedemption } from " @/platform/cloud/onboarding/desktopLoginRedemption" ;
20- import { installPreservedQueryTracker } from " @/platform/navigation/preservedQueryTracker" ;
21- import { PRESERVED_QUERY_NAMESPACES } from " @/platform/navigation/preservedQueryNamespaces" ;
22- import { preserveLoggedOutShareAuthAttribution } from " @/platform/workflow/sharing/utils/shareAuthAttribution" ;
18+ import { captureOAuthRequestId } from ' @/platform/cloud/oauth/oauthState'
19+ import { installDesktopLoginRedemption } from ' @/platform/cloud/onboarding/desktopLoginRedemption'
20+ import { installPreservedQueryTracker } from ' @/platform/navigation/preservedQueryTracker'
21+ import { PRESERVED_QUERY_NAMESPACES } from ' @/platform/navigation/preservedQueryNamespaces'
22+ import { preserveLoggedOutShareAuthAttribution } from ' @/platform/workflow/sharing/utils/shareAuthAttribution'
2323
2424const cloudOnboardingRoutes = isCloud
25- ? ( await import ( " ./platform/cloud/onboarding/onboardingCloudRoutes" ) )
25+ ? ( await import ( ' ./platform/cloud/onboarding/onboardingCloudRoutes' ) )
2626 . cloudOnboardingRoutes
27- : [ ] ;
27+ : [ ]
2828
29- const isFileProtocol = window . location . protocol === " file:" ;
29+ const isFileProtocol = window . location . protocol === ' file:'
3030
3131/**
3232 * Determine base path for the router.
@@ -36,17 +36,17 @@ const isFileProtocol = window.location.protocol === "file:";
3636 * to support deployments like http://mysite.com/ComfyUI/
3737 */
3838function getBasePath ( ) : string {
39- if ( isDesktop ) return "/" ;
40- if ( isCloud ) return import . meta. env ?. BASE_URL || "/" ;
41- return window . location . pathname ;
39+ if ( isDesktop ) return '/'
40+ if ( isCloud ) return import . meta. env ?. BASE_URL || '/'
41+ return window . location . pathname
4242}
4343
44- const basePath = getBasePath ( ) ;
44+ const basePath = getBasePath ( )
4545
4646function trackPageView ( ) : void {
4747 useTelemetry ( ) ?. trackPageView ( document . title , {
48- path : window . location . href ,
49- } ) ;
48+ path : window . location . href
49+ } )
5050}
5151
5252const router = createRouter ( {
@@ -59,213 +59,213 @@ const router = createRouter({
5959 routes : [
6060 ...( isCloud ? cloudOnboardingRoutes : [ ] ) ,
6161 {
62- path : "/" ,
62+ path : '/' ,
6363 component : LayoutDefault ,
6464 children : [
6565 {
66- path : "" ,
67- name : " GraphView" ,
68- component : ( ) => import ( " @/views/GraphView.vue" ) ,
66+ path : '' ,
67+ name : ' GraphView' ,
68+ component : ( ) => import ( ' @/views/GraphView.vue' ) ,
6969 beforeEnter : async ( _to , _from , next ) => {
7070 // Then check user store
71- const userStore = useUserStore ( ) ;
72- await userStore . initialize ( ) ;
71+ const userStore = useUserStore ( )
72+ await userStore . initialize ( )
7373 if ( userStore . needsLogin ) {
74- next ( " /user-select" ) ;
74+ next ( ' /user-select' )
7575 } else {
76- next ( ) ;
76+ next ( )
7777 }
78- } ,
78+ }
7979 } ,
8080 {
81- path : " user-select" ,
82- name : " UserSelectView" ,
83- component : ( ) => import ( " @/views/UserSelectView.vue" ) ,
84- } ,
85- ] ,
81+ path : ' user-select' ,
82+ name : ' UserSelectView' ,
83+ component : ( ) => import ( ' @/views/UserSelectView.vue' )
84+ }
85+ ]
8686 } ,
8787 // Catch-all: unknown paths redirect to root rather than hanging on the
8888 // splash screen with no route match. The global auth guard then routes
8989 // unauthenticated users to /cloud/login as normal.
90- { path : " /:pathMatch(.*)*" , redirect : "/" } ,
90+ { path : ' /:pathMatch(.*)*' , redirect : '/' }
9191 ] ,
9292
9393 scrollBehavior ( _to , _from , savedPosition ) {
9494 if ( savedPosition ) {
95- return savedPosition ;
95+ return savedPosition
9696 } else {
97- return { top : 0 } ;
97+ return { top : 0 }
9898 }
99- } ,
100- } ) ;
99+ }
100+ } )
101101
102102installPreservedQueryTracker ( router , [
103103 {
104104 namespace : PRESERVED_QUERY_NAMESPACES . TEMPLATE ,
105- keys : [ " template" , " source" , " mode" ] ,
105+ keys : [ ' template' , ' source' , ' mode' ]
106106 } ,
107107 {
108108 namespace : PRESERVED_QUERY_NAMESPACES . SHARE ,
109- keys : [ " share" ] ,
109+ keys : [ ' share' ]
110110 } ,
111111 {
112112 namespace : PRESERVED_QUERY_NAMESPACES . INVITE ,
113- keys : [ " invite" ] ,
113+ keys : [ ' invite' ]
114114 } ,
115115 {
116116 namespace : PRESERVED_QUERY_NAMESPACES . CREATE_WORKSPACE ,
117- keys : [ " create_workspace" ] ,
117+ keys : [ ' create_workspace' ]
118118 } ,
119119 {
120120 namespace : PRESERVED_QUERY_NAMESPACES . OAUTH ,
121- keys : [ " oauth_request_id" ] ,
121+ keys : [ ' oauth_request_id' ]
122122 } ,
123123 {
124124 namespace : PRESERVED_QUERY_NAMESPACES . PRICING ,
125- keys : [ " pricing" , " stop" , " cycle" ] ,
126- requiredKey : " pricing" ,
125+ keys : [ ' pricing' , ' stop' , ' cycle' ] ,
126+ requiredKey : ' pricing'
127127 } ,
128128 {
129129 namespace : PRESERVED_QUERY_NAMESPACES . TOPUP ,
130- keys : [ " topup" ] ,
130+ keys : [ ' topup' ]
131131 } ,
132132 {
133133 namespace : PRESERVED_QUERY_NAMESPACES . DESKTOP_LOGIN ,
134- keys : [ " desktop_login_code" ] ,
135- stripAfterCapture : true ,
136- } ,
137- ] ) ;
134+ keys : [ ' desktop_login_code' ] ,
135+ stripAfterCapture : true
136+ }
137+ ] )
138138
139139router . beforeEach ( ( to , _from , next ) => {
140- captureOAuthRequestId ( to . query ) ;
141- next ( ) ;
142- } ) ;
140+ captureOAuthRequestId ( to . query )
141+ next ( )
142+ } )
143143
144144router . afterEach ( ( ) => {
145- trackPageView ( ) ;
146- } ) ;
145+ trackPageView ( )
146+ } )
147147
148148if ( isCloud ) {
149- const { flags } = useFeatureFlags ( ) ;
149+ const { flags } = useFeatureFlags ( )
150150 const PUBLIC_ROUTE_NAMES = new Set ( [
151- " cloud-login" ,
152- " cloud-signup" ,
153- " cloud-forgot-password" ,
154- " cloud-oauth-consent" ,
155- " cloud-sorry-contact-support" ,
156- ] ) ;
151+ ' cloud-login' ,
152+ ' cloud-signup' ,
153+ ' cloud-forgot-password' ,
154+ ' cloud-oauth-consent' ,
155+ ' cloud-sorry-contact-support'
156+ ] )
157157 const PUBLIC_ROUTE_PATHS = new Set ( [
158- " /cloud/login" ,
159- " /cloud/signup" ,
160- " /cloud/forgot-password" ,
161- " /oauth/consent" ,
162- " /cloud/sorry-contact-support" ,
163- ] ) ;
158+ ' /cloud/login' ,
159+ ' /cloud/signup' ,
160+ ' /cloud/forgot-password' ,
161+ ' /oauth/consent' ,
162+ ' /cloud/sorry-contact-support'
163+ ] )
164164
165165 function isPublicRoute ( to : RouteLocationNormalized ) {
166- const name = String ( to . name ) ;
167- if ( PUBLIC_ROUTE_NAMES . has ( name ) ) return true ;
168- const path = to . path ;
169- return PUBLIC_ROUTE_PATHS . has ( path ) ;
166+ const name = String ( to . name )
167+ if ( PUBLIC_ROUTE_NAMES . has ( name ) ) return true
168+ const path = to . path
169+ return PUBLIC_ROUTE_PATHS . has ( path )
170170 }
171171 // Global authentication guard
172172 router . beforeEach ( async ( to , _from , next ) => {
173- const authStore = useAuthStore ( ) ;
173+ const authStore = useAuthStore ( )
174174
175175 // Wait for Firebase auth to initialize
176176 // Timeout after 16 seconds
177177 if ( ! authStore . isInitialized ) {
178178 try {
179- const { isInitialized } = storeToRefs ( authStore ) ;
180- await until ( isInitialized ) . toBe ( true , { timeout : 16_000 } ) ;
179+ const { isInitialized } = storeToRefs ( authStore )
180+ await until ( isInitialized ) . toBe ( true , { timeout : 16_000 } )
181181 } catch ( error ) {
182- console . error ( " Auth initialization failed:" , error ) ;
183- return next ( { name : " cloud-auth-timeout" } ) ;
182+ console . error ( ' Auth initialization failed:' , error )
183+ return next ( { name : ' cloud-auth-timeout' } )
184184 }
185185 }
186186
187187 // Pass authenticated users
188- const authHeader = await authStore . getAuthHeader ( ) ;
189- const isLoggedIn = ! ! authHeader ;
190- preserveLoggedOutShareAuthAttribution ( to . query , isLoggedIn ) ;
188+ const authHeader = await authStore . getAuthHeader ( )
189+ const isLoggedIn = ! ! authHeader
190+ preserveLoggedOutShareAuthAttribution ( to . query , isLoggedIn )
191191
192192 // Allow public routes
193193 if ( isPublicRoute ( to ) ) {
194- return next ( ) ;
194+ return next ( )
195195 }
196196
197197 // Special handling for user-check
198198 // These routes need auth but handle their own routing logic
199- if ( to . name === " cloud-user-check" ) {
199+ if ( to . name === ' cloud-user-check' ) {
200200 if ( to . meta . requiresAuth && ! isLoggedIn ) {
201- return next ( { name : " cloud-login" } ) ;
201+ return next ( { name : ' cloud-login' } )
202202 }
203- return next ( ) ;
203+ return next ( )
204204 }
205205
206206 // Prevent redirect loop when coming from user-check
207- if ( _from . name === " cloud-user-check" && to . path === "/" ) {
208- return next ( ) ;
207+ if ( _from . name === ' cloud-user-check' && to . path === '/' ) {
208+ return next ( )
209209 }
210210
211211 const query =
212- to . fullPath === "/"
212+ to . fullPath === '/'
213213 ? undefined
214- : { previousFullPath : encodeURIComponent ( to . fullPath ) } ;
214+ : { previousFullPath : encodeURIComponent ( to . fullPath ) }
215215
216216 // Check if route requires authentication
217217 if ( to . meta . requiresAuth && ! isLoggedIn ) {
218218 return next ( {
219- name : " cloud-login" ,
220- query,
221- } ) ;
219+ name : ' cloud-login' ,
220+ query
221+ } )
222222 }
223223
224224 // Handle other protected routes
225225 if ( ! isLoggedIn ) {
226226 // For Electron, use dialog
227227 if ( isDesktop ) {
228- const dialogService = useDialogService ( ) ;
229- const loginSuccess = await dialogService . showSignInDialog ( ) ;
230- return loginSuccess ? next ( ) : next ( false ) ;
228+ const dialogService = useDialogService ( )
229+ const loginSuccess = await dialogService . showSignInDialog ( )
230+ return loginSuccess ? next ( ) : next ( false )
231231 }
232232
233233 // For web, redirect to login
234234 return next ( {
235- name : " cloud-login" ,
236- query,
237- } ) ;
235+ name : ' cloud-login' ,
236+ query
237+ } )
238238 }
239239
240240 // User is logged in - check if they need onboarding (when enabled)
241241 // For root path, check actual user status to handle waitlisted users
242- if ( ! isDesktop && isLoggedIn && to . path === "/" ) {
242+ if ( ! isDesktop && isLoggedIn && to . path === '/' ) {
243243 if ( ! flags . onboardingSurveyEnabled ) {
244- return next ( ) ;
244+ return next ( )
245245 }
246246 // Import auth functions dynamically to avoid circular dependency
247247 const { getSurveyCompletedStatus } =
248- await import ( " @/platform/cloud/onboarding/auth" ) ;
248+ await import ( ' @/platform/cloud/onboarding/auth' )
249249 try {
250250 // Check user's actual status
251- const surveyCompleted = await getSurveyCompletedStatus ( ) ;
251+ const surveyCompleted = await getSurveyCompletedStatus ( )
252252
253253 // Survey is required for all users (when feature flag enabled)
254254 if ( ! surveyCompleted ) {
255- return next ( { name : " cloud-survey" } ) ;
255+ return next ( { name : ' cloud-survey' } )
256256 }
257257 } catch ( error ) {
258- console . error ( " Failed to check user status:" , error ) ;
258+ console . error ( ' Failed to check user status:' , error )
259259 // On error, redirect to user-check as fallback
260- return next ( { name : " cloud-user-check" } ) ;
260+ return next ( { name : ' cloud-user-check' } )
261261 }
262262 }
263263
264264 // User is logged in and accessing protected route
265- return next ( ) ;
266- } ) ;
265+ return next ( )
266+ } )
267267
268- installDesktopLoginRedemption ( router ) ;
268+ installDesktopLoginRedemption ( router )
269269}
270270
271- export default router ;
271+ export default router
0 commit comments