From 6d31c0f86ea78b4cd32f561ae6cdcbdc9bf116cc Mon Sep 17 00:00:00 2001 From: Torsten Schulz Date: Wed, 4 Sep 2024 12:05:40 +0200 Subject: [PATCH] =?UTF-8?q?Zwei=20Fixes=20f=C3=BCr=20korrekten=20DB=20aufb?= =?UTF-8?q?au?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/controllers/clubsController.js | 2 +- backend/utils/encrypt.js | 15 +++++++++++---- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/backend/controllers/clubsController.js b/backend/controllers/clubsController.js index b33e62c..049ad86 100644 --- a/backend/controllers/clubsController.js +++ b/backend/controllers/clubsController.js @@ -37,7 +37,7 @@ const addClub = async (req, res) => { console.log('[addClub] - create club'); const newClub = await Club.create({ name: clubName }); console.log('[addClub] - add user to new club'); - UserClub.create({ userId: user.id, clubId: newClub.id, approved: true }); + await UserClub.create({ userId: user.id, clubId: newClub.id, approved: true }); console.log('[addClub] - prepare response'); res.status(200).json(newClub); console.log('[addClub] - done'); diff --git a/backend/utils/encrypt.js b/backend/utils/encrypt.js index f4f2f5a..66dd44f 100644 --- a/backend/utils/encrypt.js +++ b/backend/utils/encrypt.js @@ -5,16 +5,23 @@ const createHash = (value) => { } function encryptData(data) { - try { - const cipher = crypto.createCipheriv('aes-256-cbc', Buffer.from(process.env.ENCRYPTION_KEY, 'hex'), Buffer.alloc(16, 0)); + try { + if (data === null || data === undefined) { + data = ''; + } + const cipher = crypto.createCipheriv( + 'aes-256-cbc', + Buffer.from(process.env.ENCRYPTION_KEY, 'hex'), + Buffer.alloc(16, 0) + ); let encrypted = cipher.update(data, 'utf8', 'hex'); encrypted += cipher.final('hex'); - return encrypted; + return encrypted; } catch (error) { console.log(error, data, process.env.ENCRYPTION_KEY, typeof data, process.env.ENCRYPTION_KEY.length); return ''; } -} +} function decryptData(data) { const decipher = crypto.createDecipheriv('aes-256-cbc', Buffer.from(process.env.ENCRYPTION_KEY, 'hex'), Buffer.alloc(16, 0));