Skip to content

Commit

Permalink
disable websockets
Browse files Browse the repository at this point in the history
  • Loading branch information
Varkoff committed Sep 21, 2024
1 parent 574587c commit a5be262
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 29 deletions.
4 changes: 2 additions & 2 deletions src/api/produit/controllers/produit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { type Core, factories } from "@strapi/strapi";
import type { ExtendableContext } from "koa";
import Stripe from "stripe";
import { z } from "zod";
import { io } from "../../..";
// import { io } from "../../..";

const stripe = new Stripe(process.env.STRIPE_SECRET_KEY, {
apiVersion: "2024-06-20",
Expand Down Expand Up @@ -343,7 +343,7 @@ const createStripeCheckout = async ({
},
});

io.to(existingOrder.user.id).emit("checkout", session.url);
// io.to(existingOrder.user.id).emit("checkout", session.url);
await strapi.plugins.email.services.email.send({
to: existingOrder.user.email,
from: "Strapi Ecommerce <[email protected]>",
Expand Down
54 changes: 27 additions & 27 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import type { Core } from "@strapi/strapi";
import { Server } from "socket.io";
// import { Server } from "socket.io";

export const io = new Server(strapi.server.httpServer, {
cors: {
origin: `${process.env.FRONTEND_URL}`,
methods: ["GET", "POST"],
},
});
// export const io = new Server(strapi.server.httpServer, {
// cors: {
// origin: `${process.env.FRONTEND_URL}`,
// methods: ["GET", "POST"],
// },
// });

export default {
/**
Expand All @@ -25,26 +25,26 @@ export default {
* run jobs, or perform some special logic.
*/
bootstrap({ strapi }: { strapi: Core.Strapi }) {
io.use(async (socket, next) => {
try {
//Socket Authentication
const result = await strapi.plugins[
"users-permissions"
].services.jwt.verify(socket.handshake.query.token);
// io.use(async (socket, next) => {
// try {
// //Socket Authentication
// const result = await strapi.plugins[
// "users-permissions"
// ].services.jwt.verify(socket.handshake.query.token);

console.log(result);
//Save the User ID to the socket connection
// @ts-ignore
socket.user = result.id;
next();
} catch (error) {
console.log(error);
}
}).on("connection", (socket) => {
// @ts-ignore
socket.join(socket.user)
console.log(`socket connected ${socket.id}`);
socket.emit('confirmation')
});
// console.log(result);
// //Save the User ID to the socket connection
// // @ts-ignore
// socket.user = result.id;
// next();
// } catch (error) {
// console.log(error);
// }
// }).on("connection", (socket) => {
// // @ts-ignore
// socket.join(socket.user)
// console.log(`socket connected ${socket.id}`);
// socket.emit('confirmation')
// });
},
};

0 comments on commit a5be262

Please sign in to comment.