From 239b33c3e21e1dac5635906512a203c1178ab301 Mon Sep 17 00:00:00 2001 From: Raul Hernandez Date: Wed, 29 May 2019 11:08:10 -0400 Subject: [PATCH] fix: add check integrity to geo data --- src/helpers/index.js | 16 ++++++++++++++++ src/user.js | 5 ++++- 2 files changed, 20 insertions(+), 1 deletion(-) create mode 100644 src/helpers/index.js diff --git a/src/helpers/index.js b/src/helpers/index.js new file mode 100644 index 0000000..4d267fc --- /dev/null +++ b/src/helpers/index.js @@ -0,0 +1,16 @@ +/** + * Check json integrity + * @param {object} json + */ +const isJSON = json => { + try { + if (json && typeof json === 'object' && json !== null) { + return true + } + } catch (err) {} + return false +} + +export default { + isJSON +} diff --git a/src/user.js b/src/user.js index 8c2b1d2..1357f4a 100755 --- a/src/user.js +++ b/src/user.js @@ -1,3 +1,5 @@ +import helpers from '@/helpers' + /** * Get user geo from device * @return {Promise} @@ -53,7 +55,8 @@ const getUserGeoDataFromStorage = () => { * Check if user has geo data */ const checkUserGeoData = () => { - return !!localStorage.getItem('userGeoData') + const data = getUserGeoDataFromStorage() + return helpers.isJSON(data) && data.lat && data.long } /**