Commit f0aa6f6 1 parent 036ef13 commit f0aa6f6 Copy full SHA for f0aa6f6
File tree 6 files changed +63
-24
lines changed
6 files changed +63
-24
lines changed Original file line number Diff line number Diff line change 5
5
</template >
6
6
7
7
<script >
8
+ import Vue from " vue" ;
9
+ import interceptor from " ./interceptor" ;
10
+
8
11
export default {
9
12
created : function () {
10
- this .$http .interceptors .response .use (undefined , function (err ) {
11
- if (err .status === 401 && err .config && ! err .config .__isRetryRequest ) {
12
- this .$store .dispatch (" logout" );
13
- }
14
- Promise .reject (err);
13
+ this .$http .interceptors .response .eject (interceptor);
14
+ this .$http .interceptors .response .use (undefined , err => {
15
+ return new Promise ((resolve , reject ) => {
16
+ let res = err .response ;
17
+ if (res .status === 200 ) resolve ();
18
+ if (res .status === 401 && res .config && ! res .config .__isRetryRequest ) {
19
+ Vue .nextTick (() => this .$store .dispatch (" logout" ));
20
+ }
21
+ reject (err);
22
+ });
15
23
});
16
24
}
17
25
};
Original file line number Diff line number Diff line change @@ -183,12 +183,14 @@ export default {
183
183
Vue .set (this .filters , field .key , null );
184
184
}
185
185
});
186
+ this .fetchTags ();
186
187
if (this .$route .query .target ) {
187
188
this .collectKills ();
188
189
}
189
190
},
190
191
watch: {
191
192
$route : function () {
193
+ this .fetchTags ();
192
194
if (this .$route .query .target ) {
193
195
this .collectKills ();
194
196
}
@@ -272,6 +274,18 @@ export default {
272
274
let end = this .pickerEnd ;
273
275
this .filters [field].start = start ? new Date (start) : null ;
274
276
this .filters [field].end = end ? new Date (end) : null ;
277
+ },
278
+ fetchTags : function () {
279
+ // handle tag fetches
280
+ this .$http
281
+ .get (` ${ process .env .VUE_APP_API_URL } /profile` )
282
+ .then (res => {
283
+ this .$store .dispatch (" updateTags" , res .data );
284
+ })
285
+ .catch (err => {
286
+ console .log (err);
287
+ this .$store .dispatch (" updateTags" , []);
288
+ });
275
289
}
276
290
}
277
291
};
Original file line number Diff line number Diff line change
1
+ import axios from "axios" ;
2
+
3
+ const interceptor = axios . interceptors . response . use ( undefined , function ( err ) {
4
+ return new Promise ( function ( resolve , reject ) {
5
+ let res = err . response ;
6
+ if ( res . status === 200 ) resolve ( ) ;
7
+ if ( res . status === 401 && res . config && ! res . config . __isRetryRequest ) {
8
+ localStorage . removeItem ( "token" ) ;
9
+ delete axios . defaults . headers . common [ "Authorization" ] ;
10
+ }
11
+ reject ( err ) ;
12
+ } ) ;
13
+ } ) ;
14
+
15
+ export default interceptor ;
Original file line number Diff line number Diff line change @@ -8,6 +8,7 @@ import App from "./App.vue";
8
8
import { createStore } from "./store" ;
9
9
import router from "./router" ;
10
10
import axios from "axios" ;
11
+ import "./interceptor" ;
11
12
import VueAxios from "vue-axios" ;
12
13
import { library } from "@fortawesome/fontawesome-svg-core" ;
13
14
import {
Original file line number Diff line number Diff line change @@ -68,24 +68,22 @@ export function createStore(initialState) {
68
68
} ,
69
69
actions : {
70
70
login : ( context , promise ) => {
71
- return new Promise ( ( resolve , reject ) => {
72
- promise
73
- . then ( res => {
74
- localStorage . setItem ( "token" , res . data . token ) ;
75
- axios . defaults . headers . common [
76
- "Authorization"
77
- ] = `Bearer ${ res . data . token } ` ;
78
- context . commit ( "authenticated" , {
79
- token : res . data . token ,
80
- user : res . data . user
81
- } ) ;
82
- resolve ( res ) ;
83
- } )
84
- . catch ( err => {
85
- context . commit ( "denied" ) ;
86
- reject ( err ) ;
71
+ return promise
72
+ . then ( res => {
73
+ localStorage . setItem ( "token" , res . data . token ) ;
74
+ axios . defaults . headers . common [
75
+ "Authorization"
76
+ ] = `Bearer ${ res . data . token } ` ;
77
+ context . commit ( "authenticated" , {
78
+ token : res . data . token ,
79
+ user : res . data . user
87
80
} ) ;
88
- } ) ;
81
+ return res ;
82
+ } )
83
+ . catch ( err => {
84
+ context . commit ( "denied" ) ;
85
+ throw err ;
86
+ } ) ;
89
87
} ,
90
88
register : ( context , promise ) => {
91
89
return new Promise ( ( resolve , reject ) => {
Original file line number Diff line number Diff line change 17
17
<template v-slot :button-content >
18
18
<em >{{ username }}</em >
19
19
</template >
20
- <b-dropdown-item href =" #" >Profile</b-dropdown-item >
20
+ <b-dropdown-item v-b-modal.modal-profile >Profile</b-dropdown-item >
21
+ <profile :username =" username" ></profile >
21
22
<b-dropdown-item-button @click =" logout" >
22
23
Sign out
23
24
</b-dropdown-item-button >
32
33
// @ is an alias to /src
33
34
import Hunter from " @/components/Hunter.vue" ;
34
35
import Trophies from " @/components/Trophies.vue" ;
36
+ import Profile from " @/components/Profile.vue" ;
35
37
36
38
export default {
37
39
name: " search" ,
38
40
components: {
39
41
Hunter,
40
- Trophies
42
+ Trophies,
43
+ Profile
41
44
},
42
45
computed: {
43
46
username : function () {
You can’t perform that action at this time.
0 commit comments