Skip to content
Source
Sign inSign up
TanStack/router
Open History to see the last commit

getGlobalStartContext.ts

18 lines714 Bytes

1import { getStartContext } from '@tanstack/start-storage-context'
2import { createIsomorphicFn } from '@tanstack/start-fn-stubs'
3import type { AssignAllServerRequestContext } from './createMiddleware'
4import type { Expand, Register } from '@tanstack/router-core'
5​
6export const getGlobalStartContext: () =>
7 | Expand<AssignAllServerRequestContext<Register, []>>
8 | undefined = createIsomorphicFn()
9 .client(() => undefined)
10 .server(() => {
11 const context = getStartContext().contextAfterGlobalMiddlewares
12 if (!context) {
13 throw new Error(
14 `Global context not set yet, you are calling getGlobalStartContext() before the global middlewares are applied.`,
15 )
16 }
17 return context
18 })