1+ "use server" ;
2+
13import { fetchWithAuth } from "@/shared/api" ;
24import { Information } from "../model/information" ;
5+ import { cookies } from "next/headers" ;
36
47export interface InformationDetailResponse {
58 title : string ;
@@ -84,11 +87,12 @@ export interface InformationUpdateRequest {
8487}
8588
8689export async function getInformation ( informationId : number ) {
90+ const accessToken = ( await cookies ( ) ) . get ( "access_token" ) ;
8791 const response = await fetchWithAuth (
88- `${ process . env . NEXT_PUBLIC_BACKEND_URL } /api/informations/${ informationId } ` ,
92+ `${ process . env . BACKEND_URL } /api/informations/${ informationId } ` ,
8993 {
9094 method : "GET" ,
91- credentials : "include" ,
95+ headers : { Cookie : ` ${ accessToken ?. name } = ${ accessToken ?. value } ` } ,
9296 cache : "no-store" ,
9397 } ,
9498 ) ;
@@ -101,13 +105,16 @@ export async function getInformation(informationId: number) {
101105}
102106
103107export async function createInformation ( data : InformationCreateRequest ) {
108+ const accessToken = ( await cookies ( ) ) . get ( "access_token" ) ;
104109 const response = await fetchWithAuth (
105- `${ process . env . NEXT_PUBLIC_BACKEND_URL } /api/informations` ,
110+ `${ process . env . BACKEND_URL } /api/informations` ,
106111 {
107112 method : "POST" ,
108- headers : { "Content-Type" : "application/json" } ,
113+ headers : {
114+ "Content-Type" : "application/json" ,
115+ Cookie : `${ accessToken ?. name } =${ accessToken ?. value } ` ,
116+ } ,
109117 body : JSON . stringify ( data ) ,
110- credentials : "include" ,
111118 cache : "no-store" ,
112119 } ,
113120 ) ;
@@ -123,13 +130,16 @@ export async function updateInformation(
123130 informationId : number ,
124131 data : InformationUpdateRequest ,
125132) {
133+ const accessToken = ( await cookies ( ) ) . get ( "access_token" ) ;
126134 const response = await fetchWithAuth (
127- `${ process . env . NEXT_PUBLIC_BACKEND_URL } /api/informations/${ informationId } ` ,
135+ `${ process . env . BACKEND_URL } /api/informations/${ informationId } ` ,
128136 {
129137 method : "PUT" ,
130- headers : { "Content-Type" : "application/json" } ,
138+ headers : {
139+ "Content-Type" : "application/json" ,
140+ Cookie : `${ accessToken ?. name } =${ accessToken ?. value } ` ,
141+ } ,
131142 body : JSON . stringify ( data ) ,
132- credentials : "include" ,
133143 cache : "no-store" ,
134144 } ,
135145 ) ;
@@ -140,11 +150,12 @@ export async function updateInformation(
140150}
141151
142152export async function deleteInformation ( informationId : number ) {
153+ const accessToken = ( await cookies ( ) ) . get ( "access_token" ) ;
143154 const response = await fetchWithAuth (
144- `${ process . env . NEXT_PUBLIC_BACKEND_URL } /api/informations/${ informationId } ` ,
155+ `${ process . env . BACKEND_URL } /api/informations/${ informationId } ` ,
145156 {
146157 method : "DELETE" ,
147- credentials : "include" ,
158+ headers : { Cookie : ` ${ accessToken ?. name } = ${ accessToken ?. value } ` } ,
148159 cache : "no-store" ,
149160 } ,
150161 ) ;
0 commit comments