23 lines
622 B
TypeScript
23 lines
622 B
TypeScript
import { createServerFn } from '@tanstack/react-start'
|
|
import { getRequest } from '@tanstack/react-start/server'
|
|
|
|
export 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()
|
|
|
|
if (!session) {
|
|
throw new Error('Not signed in')
|
|
}
|
|
|
|
return session
|
|
}
|
|
|
|
export const getCurrentStaffUser = createServerFn({ method: 'GET' }).handler(async () => {
|
|
const session = await getStaffSession()
|
|
return session?.user ?? null
|
|
})
|