Allow perk access without login and fix logout bug
This commit is contained in:
parent
90156d97f7
commit
ec6d83a7a8
|
@ -16,6 +16,11 @@ const AUTH_HEADER = 'Authorization';
|
||||||
|
|
||||||
export default class AuthApi {
|
export default class AuthApi {
|
||||||
static setAuthHeader(token) {
|
static setAuthHeader(token) {
|
||||||
|
if (!token) {
|
||||||
|
Reflect.deleteProperty(Axios.defaults.headers.common, AUTH_HEADER);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
Axios.defaults.headers.common[AUTH_HEADER] = `Bearer ${token}`;
|
Axios.defaults.headers.common[AUTH_HEADER] = `Bearer ${token}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -45,6 +45,7 @@ export default {
|
||||||
{ icon: 'fas fa-sign-out-alt', text: 'Logout', to: { name: 'logout' } },
|
{ icon: 'fas fa-sign-out-alt', text: 'Logout', to: { name: 'logout' } },
|
||||||
],
|
],
|
||||||
false: [
|
false: [
|
||||||
|
{ icon: 'fas fa-code-branch', text: 'Perk trees', to: { name: 'trees' } },
|
||||||
{ icon: 'fas fa-sign-in-alt', text: 'Login', to: { name: 'login' } },
|
{ icon: 'fas fa-sign-in-alt', text: 'Login', to: { name: 'login' } },
|
||||||
{ icon: 'fas fa-user-plus ', text: 'Sign up', to: { name: 'signup' } },
|
{ icon: 'fas fa-user-plus ', text: 'Sign up', to: { name: 'signup' } },
|
||||||
],
|
],
|
||||||
|
|
|
@ -49,8 +49,10 @@
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
import * as d3 from 'd3';
|
import * as d3 from 'd3';
|
||||||
import Sankey from 'd3.chart.sankey';
|
|
||||||
import * as _ from 'lodash';
|
import * as _ from 'lodash';
|
||||||
|
import Sankey from 'd3.chart.sankey';
|
||||||
|
|
||||||
|
import { mapGetters } from 'vuex';
|
||||||
|
|
||||||
import PerkController from '../controllers/perk.controller';
|
import PerkController from '../controllers/perk.controller';
|
||||||
import UserController from '../controllers/user.controller';
|
import UserController from '../controllers/user.controller';
|
||||||
|
@ -86,7 +88,12 @@ export default {
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
computed: {
|
computed: {
|
||||||
|
...mapGetters(['authStatus']),
|
||||||
canUnlock() {
|
canUnlock() {
|
||||||
|
if (!this.authStatus) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
const isLocked = _.indexOf(this.user.perks, this.selectedPerk.id);
|
const isLocked = _.indexOf(this.user.perks, this.selectedPerk.id);
|
||||||
if (isLocked !== -1) {
|
if (isLocked !== -1) {
|
||||||
return false;
|
return false;
|
||||||
|
@ -98,6 +105,10 @@ export default {
|
||||||
return requirement_ids.every((req) => this.user.perks.includes(req));
|
return requirement_ids.every((req) => this.user.perks.includes(req));
|
||||||
},
|
},
|
||||||
canLock() {
|
canLock() {
|
||||||
|
if (!this.authStatus) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
const dependencies = _.filter(this.graphData.links, { source: this.selectedPerk });
|
const dependencies = _.filter(this.graphData.links, { source: this.selectedPerk });
|
||||||
const dependency_ids = _.map(dependencies, 'target.id');
|
const dependency_ids = _.map(dependencies, 'target.id');
|
||||||
const isLocked = _.indexOf(this.user.perks, this.selectedPerk.id);
|
const isLocked = _.indexOf(this.user.perks, this.selectedPerk.id);
|
||||||
|
@ -172,6 +183,9 @@ export default {
|
||||||
PerkController.getPerks(this.$route.params.tree).then((response) => {
|
PerkController.getPerks(this.$route.params.tree).then((response) => {
|
||||||
this.graphData = response.data;
|
this.graphData = response.data;
|
||||||
this.renderGraph(this.graphData);
|
this.renderGraph(this.graphData);
|
||||||
|
if (!this.authStatus) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
UserController.getUser().then((response) => {
|
UserController.getUser().then((response) => {
|
||||||
this.user = response.data;
|
this.user = response.data;
|
||||||
this.markUnlockedPerks();
|
this.markUnlockedPerks();
|
||||||
|
|
|
@ -57,7 +57,7 @@ export default class AuthController {
|
||||||
static logout() {
|
static logout() {
|
||||||
AuthController.clearLocalStorageToken();
|
AuthController.clearLocalStorageToken();
|
||||||
store.commit('logout');
|
store.commit('logout');
|
||||||
AuthApi.setAuthHeader('');
|
AuthApi.setAuthHeader(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
static changePassword(data) {
|
static changePassword(data) {
|
||||||
|
|
Reference in New Issue