+8
-3
@@ -1,10 +1,15 @@
|
||||
import { createServerFn } from '@tanstack/react-start'
|
||||
import { createServerFn, createServerOnlyFn } from '@tanstack/react-start'
|
||||
import { getRequest } from '@tanstack/react-start/server'
|
||||
|
||||
export async function getStaffSession() {
|
||||
// `staff.index.tsx` and friends import `getCurrentStaffUser` from this module for
|
||||
// their `beforeLoad` checks, which pulls the whole file into the client bundle too.
|
||||
// `createServerOnlyFn` tells the compiler this closure (and the server-only
|
||||
// `getRequest` import it uses) can be stripped from that client bundle instead of
|
||||
// dragging the Postgres driver into the browser.
|
||||
export const getStaffSession = createServerOnlyFn(async function getStaffSession() {
|
||||
const { getAuth } = await import('#/lib/auth-instance')
|
||||
return getAuth().api.getSession({ headers: getRequest().headers })
|
||||
}
|
||||
})
|
||||
|
||||
export async function requireStaffSession() {
|
||||
const session = await getStaffSession()
|
||||
|
||||
Reference in New Issue
Block a user