Skip to content

Commit

Permalink
Support partitioned cookies.
Browse files Browse the repository at this point in the history
  • Loading branch information
vedanshujain committed Nov 9, 2024
1 parent 6980ef6 commit 9a33f94
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
3 changes: 2 additions & 1 deletion app/src/index-functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ function init_client(): void {

$site_info = SiteInfo::from_array( json_decode( $site_info_json, true ) );

session_set_cookie_params( 0, '/', $_SERVER['HTTP_HOST'], true, true );
session_set_cookie_params( 0, '/; Partitioned; Secure; SameSite=None', $_SERVER['HTTP_HOST'], true, true );
if ( session_status() === PHP_SESSION_NONE ) {
session_start();
}
Expand Down Expand Up @@ -69,6 +69,7 @@ function init_client(): void {
header( 'Access-Control-Allow-Credentials: true' );
header( 'Access-Control-Allow-Headers: Content-Type, X-CSRF-Token' );
header( 'Access-Control-Allow-Methods: GET, POST, PUT, DELETE, OPTIONS' );

}
}
}
Expand Down
5 changes: 3 additions & 2 deletions docs/js/serverless-api.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,15 @@ class ServerlessWooAPI {
DELETE_ITEM: '/store/v1/cart/delete-item',
CLEAR: '/store/v1/cart/clear'
}
};
};

constructor() {
this.baseUrl = 'https://gh-demo-woo.app.serverlesswoo.com';
this.csrfToken = null;
}

async _fetch(endpoint, options = {}) {
options.credentials = 'include';
// Add CSRF token to headers if available
if (this.csrfToken) {
options.headers = {
Expand All @@ -26,7 +27,7 @@ class ServerlessWooAPI {
}

const response = await fetch(`${this.baseUrl}${endpoint}`, options);

// Extract and store CSRF token from response headers
const newToken = response.headers.get('X-CSRF-Token');
if (newToken) {
Expand Down

0 comments on commit 9a33f94

Please sign in to comment.