Files
speckle-server/packages/frontend-2/middleware/requireSsoEnabled.ts
T
andrewwallacespeckle 8fc111cb0a fix(fe2): Small sso bugfuxes (#3571)
* Small bugfuxes

* Await loading
2024-11-28 09:45:37 +00:00

28 lines
963 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 defineNuxtRouteMiddleware(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))
}
})