File tree Expand file tree Collapse file tree
apps/app/src/app/(app)/[orgId]/people/[employeeId]/actions Expand file tree Collapse file tree Original file line number Diff line number Diff line change 22
33import { authActionClient } from '@/actions/safe-action' ;
44import { env } from '@/env.mjs' ;
5+ import { headers } from 'next/headers' ;
56import { z } from 'zod' ;
67
78const downloadCertificateSchema = z . object ( {
@@ -32,23 +33,26 @@ export const downloadTrainingCertificate = authActionClient
3233 ) ;
3334 }
3435
35- // Call the API to generate the certificate
3636 const apiUrl =
3737 env . NEXT_PUBLIC_API_URL ||
3838 process . env . API_BASE_URL ||
3939 'http://localhost:3333' ;
4040
41- const internalToken = env . INTERNAL_API_TOKEN ;
42- if ( ! internalToken ) {
43- throw new Error ( 'INTERNAL_API_TOKEN not configured' ) ;
41+ // Forward session cookies for authentication
42+ const headerStore = await headers ( ) ;
43+ const cookieHeader = headerStore . get ( 'cookie' ) ;
44+
45+ const requestHeaders : Record < string , string > = {
46+ 'Content-Type' : 'application/json' ,
47+ } ;
48+
49+ if ( cookieHeader ) {
50+ requestHeaders [ 'Cookie' ] = cookieHeader ;
4451 }
4552
4653 const response = await fetch ( `${ apiUrl } /v1/training/generate-certificate` , {
4754 method : 'POST' ,
48- headers : {
49- 'Content-Type' : 'application/json' ,
50- 'x-internal-token' : internalToken ,
51- } ,
55+ headers : requestHeaders ,
5256 body : JSON . stringify ( {
5357 memberId,
5458 organizationId,
You can’t perform that action at this time.
0 commit comments