From be0dc55ba345a38843c4a70f195ee186320e3db5 Mon Sep 17 00:00:00 2001 From: Nikhil Saraf <1028334+nikhilsaraf@users.noreply.github.com> Date: Fri, 9 Apr 2021 17:59:14 +0530 Subject: [PATCH] Kelp GUI: allow multiple users on frontend via getUserData() localstorage method (closes #686) (#690) * 1 - add logic to create and read user_id from localStorage * 2 - add uuid dependency to package.json (via npm install) * 3 - updated yarn lock file after building frontend * 4 - fix import statement of uuid --- gui/web/package.json | 3 ++- gui/web/src/kelp-ops-api/getUserData.js | 12 +++++++++++- gui/web/yarn.lock | 5 +++++ 3 files changed, 18 insertions(+), 2 deletions(-) diff --git a/gui/web/package.json b/gui/web/package.json index 8fe0a3658..b437ddabd 100644 --- a/gui/web/package.json +++ b/gui/web/package.json @@ -10,7 +10,8 @@ "react-router-dom": "^5.0.0", "react-scripts": "2.1.8", "react-tooltip-lite": "^1.10.0", - "stellar-sdk": "^3.0.0" + "stellar-sdk": "^3.0.0", + "uuid": "^8.3.2" }, "scripts": { "start": "react-scripts start", diff --git a/gui/web/src/kelp-ops-api/getUserData.js b/gui/web/src/kelp-ops-api/getUserData.js index 72522832c..b102f21f7 100644 --- a/gui/web/src/kelp-ops-api/getUserData.js +++ b/gui/web/src/kelp-ops-api/getUserData.js @@ -1,5 +1,15 @@ +import { v4 as uuidv4 } from "uuid"; + export default () => { + const userIDKey = 'user_id'; + + let userId = localStorage.getItem(userIDKey); + if (userId == null) { + userId = uuidv4(); + localStorage.setItem(userIDKey, userId); + } + return { - ID: "1347129431489", + ID: userId, }; }; \ No newline at end of file diff --git a/gui/web/yarn.lock b/gui/web/yarn.lock index 1bff8b6e9..d39d519e0 100644 --- a/gui/web/yarn.lock +++ b/gui/web/yarn.lock @@ -10307,6 +10307,11 @@ uuid@^3.0.1, uuid@^3.3.2: resolved "https://registry.yarnpkg.com/uuid/-/uuid-3.4.0.tgz#b23e4358afa8a202fe7a100af1f5f883f02007ee" integrity sha512-HjSDRw6gZE5JMggctHBcjVak08+KEVhSIiDzFnT9S9aegmp85S/bReBVTb4QTFaRNptJ9kuYaNhnbNEOkbKb/A== +uuid@^8.3.2: + version "8.3.2" + resolved "https://registry.yarnpkg.com/uuid/-/uuid-8.3.2.tgz#80d5b5ced271bb9af6c445f21a1a04c606cefbe2" + integrity sha512-+NYs2QeMWy+GWFOEm9xnn6HCDp0l7QBD7ml8zLUmJ+93Q5NF0NocErnwkTkXVFNiX3/fpC6afS8Dhb/gz7R7eg== + validate-npm-package-license@^3.0.1: version "3.0.4" resolved "https://registry.yarnpkg.com/validate-npm-package-license/-/validate-npm-package-license-3.0.4.tgz#fc91f6b9c7ba15c857f4cb2c5defeec39d4f410a"