feat(SW-3610): Get basic user from api * feat(SW-3610): Get basic user from api * . * Optional profileid Approved-by: Anton Gunnarsson
52 lines
1.5 KiB
TypeScript
52 lines
1.5 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 { getBasicUser } from "./routers/user/utils/getBasicUser"
|
|
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 ScandicBasicUser = Awaited<ReturnType<typeof getBasicUser>>
|
|
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>
|
|
getScandicBasicUser: () => Promise<ScandicBasicUser | 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,
|
|
getScandicBasicUser: opts.getScandicBasicUser,
|
|
}
|
|
}
|
|
|
|
export type Context = Awaited<ReturnType<typeof createContext>>
|