From 6e9bb0c91c16114cf47ed0c2d8a4efe4baca0167 Mon Sep 17 00:00:00 2001 From: Samil Abud Date: Wed, 6 Mar 2024 22:34:10 -0400 Subject: [PATCH] Fixed stripe issue with cors, also removing unnecesaries comments and variables --- .gitignore | 2 ++ .../stripe-button/stripe-button-component.jsx | 5 ++--- client/src/redux/user/user.saga.js | 1 - client/src/utils/stripe/stripe.utils.js | 2 +- package-lock.json | 2 +- package.json | 2 +- server.js | 12 ++++-------- 7 files changed, 11 insertions(+), 15 deletions(-) diff --git a/.gitignore b/.gitignore index dcbbc3f..fd4c9a8 100644 --- a/.gitignore +++ b/.gitignore @@ -36,3 +36,5 @@ yarn-error.log* npm-debug.log* yarn-debug.log* yarn-error.log* + +.env \ No newline at end of file diff --git a/client/src/components/stripe-button/stripe-button-component.jsx b/client/src/components/stripe-button/stripe-button-component.jsx index 6348f33..2d2bcce 100644 --- a/client/src/components/stripe-button/stripe-button-component.jsx +++ b/client/src/components/stripe-button/stripe-button-component.jsx @@ -3,10 +3,9 @@ import StripeCheckout from 'react-stripe-checkout'; import axios from 'axios'; const StripeCheckoutButton = ({price}) => { - const backendURL = process.env.BACKEND_URL ? process.env.BACKEND_URL : ''; + const backendURL = process.env.REACT_APP_BACKEND_URL ? process.env.REACT_APP_BACKEND_URL : ''; const priceForStripe = price * 100; - const publishablekey = 'pk_test_51IfAwgF7VDSpoZmOV8VtWIwE4hJOLce3ch0DPT5DkwR8Gm0g8DWhqqxGmI3qkSywYrnGEbdIbhaNNXpbTTpzWgGO00J2aOGAhi'; - //const secretkey = 'sk_test_51IfAwgF7VDSpoZmO90Kbmy03DFqIOQxE6r6niC190Z79kp94GJIILU8bGTjlFlOIN9TD4LTxdaoFCeQ3HzkPLXiw00sifdGSKj'; + const publishablekey = process.env.REACT_APP_STRIPE_PUBLISHABLE_KEY; const onToken = () => { axios({ url: `${backendURL}payment`, diff --git a/client/src/redux/user/user.saga.js b/client/src/redux/user/user.saga.js index 9db028c..9e09682 100644 --- a/client/src/redux/user/user.saga.js +++ b/client/src/redux/user/user.saga.js @@ -30,7 +30,6 @@ export function* getSnapshotFromUserAuth(userAuth, additionalData) { userAuth, additionalData ); - console.log({ userRef }); const userSnapshot = yield getDoc(userRef); if (userSnapshot) { yield put(SignInSuccess({ id: userSnapshot.id, ...userSnapshot.data() })); diff --git a/client/src/utils/stripe/stripe.utils.js b/client/src/utils/stripe/stripe.utils.js index 2be157f..a8295e9 100644 --- a/client/src/utils/stripe/stripe.utils.js +++ b/client/src/utils/stripe/stripe.utils.js @@ -4,4 +4,4 @@ import { loadStripe } from "@stripe/stripe-js"; //const secretkey = 'sk_test_51IfAwgF7VDSpoZmO90Kbmy03DFqIOQxE6r6niC190Z79kp94GJIILU8bGTjlFlOIN9TD4LTxdaoFCeQ3HzkPLXiw00sifdGSKj'; export const stripePromise = loadStripe( process.env.REACT_APP_STRIPE_PUBLISHABLE_KEY -); \ No newline at end of file +); diff --git a/package-lock.json b/package-lock.json index 6eb6962..3a5d9c2 100644 --- a/package-lock.json +++ b/package-lock.json @@ -10,7 +10,7 @@ "dependencies": { "body-parser": "^1.18.3", "compression": "^1.7.4", - "cors": "2.8.5", + "cors": "^2.8.5", "dotenv": "^7.0.0", "express": "^4.16.4", "express-sslify": "^1.2.0", diff --git a/package.json b/package.json index 5325be2..ea617af 100644 --- a/package.json +++ b/package.json @@ -10,7 +10,7 @@ "dependencies": { "body-parser": "^1.18.3", "compression": "^1.7.4", - "cors": "2.8.5", + "cors": "^2.8.5", "dotenv": "^7.0.0", "express": "^4.16.4", "express-sslify": "^1.2.0", diff --git a/server.js b/server.js index bcd4a5f..f67f808 100644 --- a/server.js +++ b/server.js @@ -2,27 +2,23 @@ const express = require("express"); const path = require("path"); const compression = require("compression"); const enforce = require("express-sslify"); +var cors = require("cors"); if (process.env.NODE_ENV !== "production") { require("dotenv").config(); } - const stripe = require("stripe")(process.env.STRYPE_SECRET_KEY); const app = express(); const port = process.env.PORT || 2500; //Middelwares -app.use(express.urlencoded({ extended: false })); //parsear el request por post y html por form url encoded -app.use(express.json()); //parsear el request por json +app.use(express.urlencoded({ extended: false })); +app.use(express.json()); if (process.env.NODE_ENV === "production") { app.use(compression()); - // app.use(enforce.HTTPS({trustProtoHeader:true})); - // app.use(express.static(path.join(__dirname, 'client/build'))); - // app.get('*', function(req, res){ - // res.sendFile(path.join(__dirname,'client/build','index.html')); - // }) } +app.use(cors()); app.listen(port, (error) => { if (error) {