@@ -19,7 +19,11 @@ import type { SalesChannel } from './types/SalesChannel'
19
19
import type { MasterDataResponse } from './types/Newsletter'
20
20
import type { Address , AddressInput } from './types/Address'
21
21
import type { DeliveryMode , SelectedAddress } from './types/ShippingData'
22
- import { getStoreCookie , getWithCookie } from '../../utils/cookies'
22
+ import {
23
+ getCookieFromRequestHeaders ,
24
+ getStoreCookie ,
25
+ getWithCookie ,
26
+ } from '../../utils/cookies'
23
27
import type { ProductRating } from './types/ProductRating'
24
28
import type {
25
29
CreateProductReviewInput ,
@@ -28,6 +32,7 @@ import type {
28
32
} from './types/ProductReview'
29
33
import { adaptObject } from '../../utils/adaptObject'
30
34
import { camelToSnakeCase } from '../../utils/camelToSnakeCase'
35
+ import { NotAuthorizedError } from '../../../errors'
31
36
32
37
type ValueOf < T > = T extends Record < string , infer K > ? K : never
33
38
@@ -383,10 +388,22 @@ export const VtexCommerce = (
383
388
} ,
384
389
reviews : {
385
390
create : ( input : CreateProductReviewInput ) : Promise < string > => {
391
+ const authCookieKey : string = `VtexIdclientAutCookie_${ account } `
392
+
393
+ const authCookie = getCookieFromRequestHeaders ( ctx , authCookieKey ) ?? ''
394
+
395
+ if ( ! authCookie ) {
396
+ throw new NotAuthorizedError ( 'Missing auth cookie' )
397
+ }
398
+
386
399
return fetchAPI (
387
400
`${ base } /${ REVIEWS_AND_RATINGS_API_PATH } /review` ,
388
401
{
389
402
...BASE_INIT ,
403
+ headers : {
404
+ ...BASE_INIT . headers ,
405
+ VtexIdclientAutCookie : authCookie ,
406
+ } ,
390
407
body : JSON . stringify ( input ) ,
391
408
method : 'POST' ,
392
409
} ,
0 commit comments