Files
web/packages/trpc/lib/context.ts
Anton Gunnarsson 0b569e28ce Merged in fix/add-missing-partner-data (pull request #3116)
fix: Add param to getScandicUser for extended data

* Add param to getScandicUser for extended data


Approved-by: Linus Flood
2025-11-10 15:23:07 +00:00

48 lines
1.3 KiB
TypeScript

import type { Lang } from "@scandic-hotels/common/constants/language"
import type { User } from "next-auth"
import type { JWT } from "next-auth/jwt"
import type { getVerifiedUser } from "./routers/user/utils/getVerifiedUser"
type Session = {
token: JWT
expires: string
user?: User
error?: "RefreshAccessTokenError"
}
type ScandicUser = Awaited<ReturnType<typeof getVerifiedUser>>
type CreateContextOptions = {
auth: () => Promise<Session | null>
lang: Lang
pathname: string
uid?: string | null
url: string
webToken?: string
contentType?: string
app: "scandic-web" | "partner-sas"
getScandicUserToken: () => Promise<string | null>
getUserPointsBalance: () => Promise<number | null>
getScandicUser: (input?: {
withExtendedPartnerData: boolean
}) => Promise<ScandicUser | null>
}
export function createContext(opts: CreateContextOptions) {
return {
auth: opts.auth,
lang: opts.lang,
pathname: opts.pathname,
uid: opts.uid,
url: opts.url,
webToken: opts.webToken,
contentType: opts.contentType,
app: opts.app,
getScandicUserToken: opts.getScandicUserToken,
getUserPointsBalance: opts.getUserPointsBalance,
getScandicUser: opts.getScandicUser,
}
}
export type Context = Awaited<ReturnType<typeof createContext>>