From 5b2ab72ed8258b3f850632a6ad135fd28b14e23d Mon Sep 17 00:00:00 2001 From: aleksaelezovic Date: Fri, 4 Apr 2025 11:34:48 +0200 Subject: [PATCH] add browser-only-wallets --- index.js | 7 +++++-- ...0214000000-add-browser-only-to-user-wallets.js | 15 +++++++++++++++ models/UserWallet.js | 5 +++++ 3 files changed, 25 insertions(+), 2 deletions(-) create mode 100644 migrations/20250214000000-add-browser-only-to-user-wallets.js diff --git a/index.js b/index.js index 4590a6a..704ab05 100644 --- a/index.js +++ b/index.js @@ -151,6 +151,7 @@ app.get('/check', async (req, res, next) => { app.get('/wallets', async (req, res, next) => { const authHeader = req.headers['authorization']; + const browserOnly = req.query.browser_only === 'true'; if (authHeader && authHeader.startsWith('Bearer ')) { // Verify the token using Passport's JWT strategy @@ -182,7 +183,8 @@ app.get('/wallets', async (req, res, next) => { // Fetch the user's wallets const wallets = await UserWallet.findAll({ where: { - user_id: userDB.id + user_id: userDB.id, + browser_only: browserOnly } }); @@ -212,7 +214,8 @@ app.get('/wallets', async (req, res, next) => { }); const wallets = await UserWallet.findAll({ where: { - user_id: user.id + user_id: user.id, + browser_only: browserOnly } }); const { password, ...safeUser } = user.dataValues; diff --git a/migrations/20250214000000-add-browser-only-to-user-wallets.js b/migrations/20250214000000-add-browser-only-to-user-wallets.js new file mode 100644 index 0000000..ebda1c4 --- /dev/null +++ b/migrations/20250214000000-add-browser-only-to-user-wallets.js @@ -0,0 +1,15 @@ +'use strict'; + +module.exports = { + async up(queryInterface, Sequelize) { + await queryInterface.addColumn('user_wallets', 'browser_only', { + type: Sequelize.BOOLEAN, + allowNull: false, + defaultValue: false + }); + }, + + async down(queryInterface, Sequelize) { + await queryInterface.removeColumn('user_wallets', 'browser_only'); + } +}; diff --git a/models/UserWallet.js b/models/UserWallet.js index ccd3865..ae91387 100644 --- a/models/UserWallet.js +++ b/models/UserWallet.js @@ -15,6 +15,11 @@ module.exports = (sequelize, DataTypes) => { blockchain: { type: DataTypes.STRING, allowNull: false + }, + browser_only: { + type: DataTypes.BOOLEAN, + allowNull: false, + defaultValue: false } }, {