Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/chilly-guests-design.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@cobaltcore-dev/aurora": patch
---

Expose the `res` (FastifyReply) object in `AuroraPortalContext` to allow consumer tRPC procedures to set response headers and cookies.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { describe, it, expect, vi, beforeEach } from "vitest"
import type { FastifyRequest } from "fastify"
import type { FastifyRequest, FastifyReply } from "fastify"
import { flavorRouter } from "./flavorRouter"
import { Flavor } from "../types/flavor"
import { TRPCError } from "@trpc/server"
Expand All @@ -21,6 +21,7 @@ vi.mock("../helpers/flavorHelpers", () => ({

const createMockContext = (shouldFailAuth = false, shouldFailRescope = false, shouldFailCompute = false) => ({
req: { headers: {} } as FastifyRequest,
res: { setCookie: vi.fn() } as unknown as FastifyReply,
signal: new AbortController().signal,
validateSession: vi.fn().mockReturnValue(!shouldFailAuth),
identityEndpoint: "http://identity.example.com/",
Expand Down
5 changes: 4 additions & 1 deletion packages/aurora/src/server/context.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { CreateFastifyContextOptions } from "@trpc/server/adapters/fastify"
import type { FastifyRequest } from "fastify"
import type { FastifyRequest, FastifyReply } from "fastify"
import { SignalOpenstackSession, SignalOpenstackSessionType } from "@cobaltcore-dev/signal-openstack"
import { SessionCookie } from "./sessionCookie"
import { AuthConfig } from "./Authentication/types/models"
Expand Down Expand Up @@ -57,6 +57,8 @@ export interface FormFieldData {

export interface AuroraPortalContext extends AuroraContext {
req: FastifyRequest
/** Fastify reply object for setting response headers/cookies */
res: FastifyReply
/** Normalised identity endpoint (always ends with /) */
Comment thread
ArtieReus marked this conversation as resolved.
identityEndpoint: string
/** Ceph/S3 region from consumer config */
Expand Down Expand Up @@ -417,6 +419,7 @@ export async function createContext(

return {
req: opts.req,
res: opts.res,
signal: abortController.signal,
identityEndpoint: normalizedEndpoint,
cephRegion: config.cephRegion,
Expand Down
Loading