diff --git a/app/Classes/Modules/Accounts/Services/GeneratesAuthenticationToken.php b/app/Classes/Modules/Accounts/Services/GeneratesAuthenticationToken.php
index 72296b97..2116895c 100644
--- a/app/Classes/Modules/Accounts/Services/GeneratesAuthenticationToken.php
+++ b/app/Classes/Modules/Accounts/Services/GeneratesAuthenticationToken.php
@@ -65,8 +65,12 @@ class GeneratesAuthenticationToken {
];
if($user->type === RoleTypes::USER) {
+
+ /** @var Company $companyModule */
$claims = array_merge($claims, [
- 'company_id' => $company->id
+ 'company_id' => $company->id,
+ 'company_name' => $company->name,
+ 'company_marking' => $company->reference,
]);
}
diff --git a/resources/assets/vue/app.js b/resources/assets/vue/app.js
index 1d98d12d..d9e2e465 100644
--- a/resources/assets/vue/app.js
+++ b/resources/assets/vue/app.js
@@ -50,6 +50,19 @@ const app = new Vue({
store,
created(){
this.routesGuard();
+ if (!this.$store.getters.isAdmin && !('company_marking' in this.$store.getters.getDecodedAccessToken.user) && this.isProtectedRoute() && !this.isWithTokenRoute()) {
+ this.$store.dispatch('crudRequest', {endpoint: this.route('api.account.authentication.refresh'), method: 'get'}).then(response => {
+ let success = response.ok;
+ response.json().then(response => {
+
+ if(!success){return;}
+
+ this.$store.dispatch('userAuthentication', {access_token: response.payload.refresh_token, redirect_url: window.location.href});
+
+ });
+ })
+
+ }
},
methods: {
route: route
diff --git a/resources/assets/vue/general/mixins/guards.js b/resources/assets/vue/general/mixins/guards.js
index 18681e5d..3b39baad 100644
--- a/resources/assets/vue/general/mixins/guards.js
+++ b/resources/assets/vue/general/mixins/guards.js
@@ -1,16 +1,15 @@
export default {
methods: {
routesGuard(){
- (!this.$store.getters.isAuthenticated && this.isProtectedRoute()&& this.isWithTokenRoute()) ? window.location.href = this.route('login') : '';
- (this.$store.getters.isAuthenticated && !this.isProtectedRoute()&& this.isWithTokenRoute()) ? window.location.href = this.route('dashboard') : '';
+ (!this.$store.getters.isAuthenticated && this.isProtectedRoute()&& !this.isWithTokenRoute()) ? window.location.href = this.route('login') : '';
+ (this.$store.getters.isAuthenticated && !this.isProtectedRoute()&& !this.isWithTokenRoute()) ? window.location.href = this.route('dashboard') : '';
},
isProtectedRoute(){
const unprotectedRoutes = [this.route('login'), this.route('account.email.verification')];
return !unprotectedRoutes.includes(window.location.href);
},
isWithTokenRoute(){
- const unprotectedRoutesWithToken = [this.route('account.password.reset')];
- return !window.location.href.includes(unprotectedRoutesWithToken);
+ return window.location.href.includes(this.route('account.password.reset'));
}
}
diff --git a/resources/assets/vue/vuex/modules/authentication.js b/resources/assets/vue/vuex/modules/authentication.js
index 19ab2317..f822d26b 100644
--- a/resources/assets/vue/vuex/modules/authentication.js
+++ b/resources/assets/vue/vuex/modules/authentication.js
@@ -9,8 +9,6 @@ export default {
},
getters: {
isAuthenticated: state => !!state.authentication.access_token,
- getAccessToken: state => state.authentication.access_token,
-
isSuperAdmin: (state, getters) => getters.getDecodedAccessToken.user.type === 0 || getters.getDecodedAccessToken.user.type === 1,
isAdmin: (state, getters) => getters.getDecodedAccessToken.user.type === 0 || getters.getDecodedAccessToken.user.type === 1 || getters.getDecodedAccessToken.user.type === 2,
isCustomer: (state, getters) => getters.getDecodedAccessToken.user.type === 3,
@@ -19,7 +17,27 @@ export default {
getUserId: (state, getters) => getters.getDecodedAccessToken.user.id,
getUserEmail: (state, getters) => getters.getDecodedAccessToken.user.email,
getCompanyId: (state, getters) => getters.getDecodedAccessToken.user.company_id,
+ getAccessToken(state, getters, dispatch) {
+ if(getters.isAuthenticated){
+ $crisp.push(["set", "user:email", getters.getUserEmail]);
+ if(getters.isAdmin){
+ $crisp.push(["set", "user:nickname", getters.getUserName]);
+ }
+
+ if(getters.isCustomer && ('company_marking' in getters.getDecodedAccessToken.user)){
+ $crisp.push(["set", "user:nickname", getters.getDecodedAccessToken.user.company_marking]);
+ $crisp.push(["set", "session:data", [
+ [
+ ["exchange-marking", getters.getDecodedAccessToken.user.company_marking],
+ ["company-name", getters.getDecodedAccessToken.user.company_name]
+ ]
+ ]]);
+ }
+ }
+
+ return state.authentication.access_token
+ },
getDecodedAccessToken(state) {
try{
return jwt_decode(state.authentication.access_token);
diff --git a/resources/views/vendor/js.blade.php b/resources/views/vendor/js.blade.php
index 9adee26b..41482a0d 100644
--- a/resources/views/vendor/js.blade.php
+++ b/resources/views/vendor/js.blade.php
@@ -6,6 +6,7 @@
'routes' => collect(\Route::getRoutes())->mapWithKeys(function ($route) { return [$route->getName() => $route->uri()]; })
]) !!};
+