fix: refactor scopes for service token
This commit is contained in:
+14
-26
@@ -125,29 +125,17 @@ export const safeProtectedProcedure = t.procedure.use(async function (opts) {
|
||||
})
|
||||
})
|
||||
|
||||
function createServiceProcedure(serviceName: ServiceTokenScope) {
|
||||
return t.procedure.use(async (opts) => {
|
||||
const { access_token } = await fetchServiceToken([serviceName])
|
||||
if (!access_token) {
|
||||
throw internalServerError(`Failed to obtain ${serviceName} service token`)
|
||||
}
|
||||
return opts.next({
|
||||
ctx: {
|
||||
serviceToken: access_token,
|
||||
},
|
||||
})
|
||||
export const serviceProcedure = t.procedure.use(async (opts) => {
|
||||
const { access_token } = await fetchServiceToken()
|
||||
if (!access_token) {
|
||||
throw internalServerError(`Failed to obtain service token`)
|
||||
}
|
||||
return opts.next({
|
||||
ctx: {
|
||||
serviceToken: access_token,
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
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({
|
||||
@@ -178,11 +166,11 @@ export const protectedServerActionProcedure = serverActionProcedure.use(
|
||||
|
||||
// NOTE: This is actually save to use, just the implementation could change
|
||||
// in minor version bumps. Please read: https://trpc.io/docs/faq#unstable
|
||||
export const contentStackUidWithHotelServiceProcedure =
|
||||
contentstackExtendedProcedureUID.unstable_concat(hotelServiceProcedure)
|
||||
export const contentStackUidWithServiceProcedure =
|
||||
contentstackExtendedProcedureUID.unstable_concat(serviceProcedure)
|
||||
|
||||
export const contentStackBaseWithProfileServiceProcedure =
|
||||
contentstackBaseProcedure.unstable_concat(profileServiceProcedure)
|
||||
export const contentStackBaseWithServiceProcedure =
|
||||
contentstackBaseProcedure.unstable_concat(serviceProcedure)
|
||||
|
||||
export const contentStackBaseWithProtectedProcedure =
|
||||
contentstackBaseProcedure.unstable_concat(protectedProcedure)
|
||||
|
||||
Reference in New Issue
Block a user