Files
speckle-server/packages/frontend-2/middleware/requireSsoEnabled.ts
T
Kristaps Fabians Geikins 843606775c feat(fe2): parallel middlewares (#5314)
* parallel middlewares foundation + hydration mismatch

* moved to fully parallel middlewares

* a bit less hacky

* some more cleanup

* improved nuxt 4 error formatting

* make parallel middlewares toggleable
2025-08-27 12:38:04 +03:00

28 lines
975 B
TypeScript

import { until } from '@vueuse/core'
import { workspaceRoute } from '~/lib/common/helpers/route'
import { useWorkspacePublicSsoCheck } from '~/lib/workspaces/composables/sso'
/**
* Used to validate that the workspace has SSO enabled, redirects to workspace page if not
*/
export default defineParallelizedNuxtRouteMiddleware(async (to) => {
// Skip middleware when handling SSO callback with access code.
// This page serves as both the SSO login page and OAuth callback URL.
// We need to let the callback through to process the access code before any redirects.
if (to.query.access_code) {
return
}
const workspaceSlug = computed(() => to.params.slug as string)
if (!workspaceSlug.value) return
const { workspace, loading } = useWorkspacePublicSsoCheck(workspaceSlug)
// Wait for loading to complete
await until(loading).toBe(false)
if (!workspace.value?.ssoProviderName) {
return navigateTo(workspaceRoute(workspaceSlug.value))
}
})