Skip to content

Commit

Permalink
[email protected] - auth token check (#1803)
Browse files Browse the repository at this point in the history
* auth token check

* removing unused function

* removing unused function
  • Loading branch information
matthewhardern authored Apr 13, 2022
1 parent 9f68d78 commit 8de42fc
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 37 deletions.
8 changes: 8 additions & 0 deletions packages/components/pages/f-loyalty/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,14 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).


v1.7.3
------------------------------
*April 12, 2022*

### Added
- Check for auth token before setting global user id


v1.7.2
------------------------------
*April 05, 2022*
Expand Down
2 changes: 1 addition & 1 deletion packages/components/pages/f-loyalty/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@justeat/f-loyalty",
"description": "Fozzie Loyalty - provides a way for customers to collect loyalty stamps for restaurants",
"version": "1.7.2",
"version": "1.7.3",
"main": "dist/f-loyalty.umd.min.js",
"maxBundleSize": "101kB",
"files": [
Expand Down
10 changes: 2 additions & 8 deletions packages/components/pages/f-loyalty/src/components/Loyalty.vue
Original file line number Diff line number Diff line change
Expand Up @@ -123,20 +123,14 @@ export default {
async mounted () {
await this.init({
brazeApiKey: this.brazeApiKey,
authToken: this.authToken,
logger: this.$log,
errorHandler: this.handleErrors
authToken: this.authToken
});
},
methods: {
...mapActions(VUEX_MODULE_NAMESPACE_LOYALTY, {
init: ACTION_INITIALISE_LOYALTY
}),
handleErrors (error) {
this.$emit('onError', error);
}
})
}
};
</script>
Expand Down
36 changes: 8 additions & 28 deletions packages/components/pages/f-loyalty/src/store/loyalty.module.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,32 +10,10 @@ import {
/**
* @function resolveGlobalUserID
* @param {string} authToken - auth token.
* @param logger
* @param errorHandler
*/
const resolveGlobalUserID = (authToken, logger, errorHandler) => {
try {
const tokenData = jwtDecode(authToken);
return tokenData?.global_user_id;
} catch (error) {
logger.error(
'Error Decoding JWT token',
error,
'loyalty',
{
authToken,
exception: error.name,
exceptionMessage: error.message,
exceptionStackTrace: error.stack,
traceId: error.traceId || (error.response && error.response.data.traceId),
errorCode: error.errorCode
}
);
// return null and emit error to allow component to emit on error event to
// prevent error being handled by general catch all error handler
errorHandler(error);
return null;
}
const resolveGlobalUserID = authToken => {
const tokenData = jwtDecode(authToken);
return tokenData?.global_user_id;
};

export default {
Expand Down Expand Up @@ -73,12 +51,14 @@ export default {
commit(ACTION_SET_GLOBAL_USER_ID, resolveGlobalUserID(authToken, logger, errorHandler));
},

[ACTION_INITIALISE_LOYALTY]: ({ commit, dispatch }, {
brazeApiKey, authToken, logger, errorHandler
[ACTION_INITIALISE_LOYALTY]: ({ commit, dispatch, getters }, {
brazeApiKey, authToken
}) => {
commit(MUTATION_SET_AUTH_TOKEN, authToken);
commit(MUTATION_SET_BRAZE_KEY, brazeApiKey);
dispatch(ACTION_SET_GLOBAL_USER_ID, { authToken, logger, errorHandler });
if (getters.isAuthenticated) {
dispatch(ACTION_SET_GLOBAL_USER_ID, { authToken });
}
}
},

Expand Down

0 comments on commit 8de42fc

Please sign in to comment.