fix(portal): add X-Impersonation-Session-Id headers to fix 404s (GRO-286)

Add missing X-Impersonation-Session-Id header to portal API calls in
AccountSettings, ReportCards, and Appointments components. Also add
sessionId prop to ReportCards since it was missing.

Co-Authored-By: Paperclip <noreply@paperclip.ing>
This commit is contained in:
Lint Roller
2026-03-30 11:33:44 +00:00
parent b2ebec1fdc
commit a33ccf75f0
4 changed files with 29 additions and 14 deletions
+1 -1
View File
@@ -133,7 +133,7 @@ export function CustomerPortal() {
case "pets": case "pets":
return <PetProfiles readOnly={!!isReadOnly} sessionId={sessionId} />; return <PetProfiles readOnly={!!isReadOnly} sessionId={sessionId} />;
case "reports": case "reports":
return <ReportCards />; return <ReportCards sessionId={sessionId} />;
case "billing": case "billing":
return <BillingPayments readOnly={!!isReadOnly} sessionId={sessionId} />; return <BillingPayments readOnly={!!isReadOnly} sessionId={sessionId} />;
case "messages": case "messages":
@@ -72,7 +72,9 @@ function PersonalInfo({ sessionId, readOnly }: { sessionId: string | null; readO
const fetchPersonalInfo = async () => { const fetchPersonalInfo = async () => {
try { try {
setLoading(true); setLoading(true);
const response = await fetch("/api/portal/me"); const response = await fetch("/api/portal/me", {
headers: { "X-Impersonation-Session-Id": sessionId },
});
if (response.ok) { if (response.ok) {
const data: PersonalInfoData = await response.json(); const data: PersonalInfoData = await response.json();
setForm({ setForm({
@@ -252,7 +254,9 @@ function ManagePets({ sessionId, readOnly }: { sessionId: string | null; readOnl
const fetchPets = async () => { const fetchPets = async () => {
try { try {
setLoading(true); setLoading(true);
const response = await fetch("/api/portal/pets"); const response = await fetch("/api/portal/pets", {
headers: { "X-Impersonation-Session-Id": sessionId },
});
if (response.ok) { if (response.ok) {
const data = await response.json(); const data = await response.json();
setPets(Array.isArray(data) ? data : []); setPets(Array.isArray(data) ? data : []);
@@ -118,7 +118,7 @@ export const AppointmentsSection: React.FC<AppointmentsSectionProps> = ({ sessio
try { try {
const response = await fetch('/api/portal/appointments', { const response = await fetch('/api/portal/appointments', {
headers: { Authorization: `Bearer ${sessionId}` }, headers: { "X-Impersonation-Session-Id": sessionId ?? "" },
}); });
if (response.ok) { if (response.ok) {
@@ -379,7 +379,7 @@ export function ConfirmationSection({
try { try {
const headers: Record<string, string> = {}; const headers: Record<string, string> = {};
if (sessionId) { if (sessionId) {
headers['Authorization'] = `Bearer ${sessionId}`; headers['X-Impersonation-Session-Id'] = sessionId;
} }
const res = await fetch(`/api/portal/appointments/${appt.id}/confirm`, { const res = await fetch(`/api/portal/appointments/${appt.id}/confirm`, {
method: 'POST', method: 'POST',
@@ -455,7 +455,7 @@ function CancelAppointmentButton({
try { try {
const headers: Record<string, string> = {}; const headers: Record<string, string> = {};
if (sessionId) { if (sessionId) {
headers['Authorization'] = `Bearer ${sessionId}`; headers['X-Impersonation-Session-Id'] = sessionId;
} }
const res = await fetch(`/api/portal/appointments/${appt.id}/cancel`, { const res = await fetch(`/api/portal/appointments/${appt.id}/cancel`, {
method: 'POST', method: 'POST',
@@ -507,7 +507,7 @@ export function CustomerNotesSection({
try { try {
const headers: Record<string, string> = { 'Content-Type': 'application/json' }; const headers: Record<string, string> = { 'Content-Type': 'application/json' };
if (sessionId) { if (sessionId) {
headers['Authorization'] = `Bearer ${sessionId}`; headers['X-Impersonation-Session-Id'] = sessionId;
} }
const res = await fetch(`/api/portal/appointments/${appt.id}/notes`, { const res = await fetch(`/api/portal/appointments/${appt.id}/notes`, {
method: 'PATCH', method: 'PATCH',
@@ -600,7 +600,7 @@ export function RescheduleFlow({
setError(null); setError(null);
try { try {
const headers: Record<string, string> = { 'Content-Type': 'application/json' }; const headers: Record<string, string> = { 'Content-Type': 'application/json' };
if (sessionId) headers['Authorization'] = `Bearer ${sessionId}`; if (sessionId) headers['X-Impersonation-Session-Id'] = sessionId;
const res = await fetch(`/api/portal/appointments/${appt.id}/reschedule`, { const res = await fetch(`/api/portal/appointments/${appt.id}/reschedule`, {
method: 'POST', method: 'POST',
headers, headers,
@@ -744,10 +744,10 @@ function BookingFlow({ onClose, sessionId }: BookingFlowProps) {
try { try {
const [petsRes, servicesRes] = await Promise.all([ const [petsRes, servicesRes] = await Promise.all([
fetch('/api/portal/pets', { fetch('/api/portal/pets', {
headers: { Authorization: `Bearer ${sessionId}` }, headers: { "X-Impersonation-Session-Id": sessionId ?? "" },
}), }),
fetch('/api/portal/services', { fetch('/api/portal/services', {
headers: { Authorization: `Bearer ${sessionId}` }, headers: { "X-Impersonation-Session-Id": sessionId ?? "" },
}), }),
]); ]);
@@ -784,7 +784,7 @@ function BookingFlow({ onClose, sessionId }: BookingFlowProps) {
method: 'POST', method: 'POST',
headers: { headers: {
'Content-Type': 'application/json', 'Content-Type': 'application/json',
Authorization: `Bearer ${sessionId}`, "X-Impersonation-Session-Id": sessionId ?? "",
}, },
body: JSON.stringify({ body: JSON.stringify({
petId: selectedPet.id, petId: selectedPet.id,
+14 -3
View File
@@ -24,17 +24,28 @@ interface Appointment {
reportCardId?: string; reportCardId?: string;
} }
export function ReportCards() { interface ReportCardsProps {
sessionId: string | null;
}
export function ReportCards({ sessionId }: ReportCardsProps) {
const [appointments, setAppointments] = useState<Appointment[]>([]); const [appointments, setAppointments] = useState<Appointment[]>([]);
const [isLoading, setIsLoading] = useState(true); const [isLoading, setIsLoading] = useState(true);
const [error, setError] = useState<string | null>(null); const [error, setError] = useState<string | null>(null);
const [selectedCard, setSelectedCard] = useState<Appointment | null>(null); const [selectedCard, setSelectedCard] = useState<Appointment | null>(null);
const loadReportCards = async () => { const loadReportCards = async () => {
if (!sessionId) {
setAppointments([]);
setIsLoading(false);
return;
}
try { try {
setError(null); setError(null);
setIsLoading(true); setIsLoading(true);
const response = await fetch("/api/portal/appointments"); const response = await fetch("/api/portal/appointments", {
headers: { "X-Impersonation-Session-Id": sessionId },
});
if (response.ok) { if (response.ok) {
const data = await response.json(); const data = await response.json();
@@ -55,7 +66,7 @@ export function ReportCards() {
useEffect(() => { useEffect(() => {
loadReportCards(); loadReportCards();
}, []); }, [sessionId]);
if (isLoading) { if (isLoading) {
return ( return (