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));