Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- export const getGuestCart = () => {
- if (readCookie('cart_token')) {
- const cart_token = readCookie('cart_token')
- return fetch(`${baseUrl}/api/cart/user_cart/`, {
- method: 'GET',
- credentials: "include",
- headers: {
- 'Content-Type': 'application/json',
- 'cart_token': `123`,
- 'Cookie': `cart_token=${cart_token}`,
- },
- })
- .then(res => res.json())
- .catch(error => {
- console.error('Error fetching guest cart:', error);
- throw error;
- });
- } else {
- return fetch(`${baseUrl}/api/cart/user_cart/`, {
- method: 'GET',
- headers: {
- 'Content-Type': 'application/json',
- },
- })
- .then(res => {
- return res.json();
- })
- .then(data => {
- if (data['token']) {
- document.cookie = `cart_token=${data['token']}; path=/`;
- }
- })
- .catch(error => {
- console.error('Error fetching guest cart:', error);
- throw error;
- });
- }
- };
Advertisement
Add Comment
Please, Sign In to add comment