fix: handle cache tags for service tokens

This commit is contained in:
Christel Westerberg
2024-10-01 14:48:28 +02:00
committed by Pontus Dreij
parent e5f85e0499
commit 3c548923ff
4 changed files with 75 additions and 25 deletions

View File

@@ -17,6 +17,10 @@ import { langInput } from "./utils"
import type { Session } from "next-auth"
import {
ServiceTokenScope,
ServiceTokenScopeEnum,
} from "@/types/enums/serviceToken"
import type { Meta } from "@/types/trpc/meta"
const t = initTRPC
@@ -121,7 +125,7 @@ export const safeProtectedProcedure = t.procedure.use(async function (opts) {
})
})
function createServiceProcedure(serviceName: string) {
function createServiceProcedure(serviceName: ServiceTokenScope) {
return t.procedure.use(async (opts) => {
const { access_token } = await fetchServiceToken([serviceName])
if (!access_token) {
@@ -135,9 +139,15 @@ function createServiceProcedure(serviceName: string) {
})
}
export const bookingServiceProcedure = createServiceProcedure("booking")
export const hotelServiceProcedure = createServiceProcedure("hotel")
export const profileServiceProcedure = createServiceProcedure("profile")
export const bookingServiceProcedure = createServiceProcedure(
ServiceTokenScopeEnum.booking
)
export const hotelServiceProcedure = createServiceProcedure(
ServiceTokenScopeEnum.hotel
)
export const profileServiceProcedure = createServiceProcedure(
ServiceTokenScopeEnum.profile
)
export const serverActionProcedure = t.procedure.experimental_caller(
experimental_nextAppDirCaller({