Skip to content

Commit 18c754e

Browse files
authored
Merge pull request #376 from Seluj78/373-refresh-token
2 parents 67bf60c + 6767b31 commit 18c754e

File tree

6 files changed

+34
-24
lines changed

6 files changed

+34
-24
lines changed

frontend/src/auth/logOut.js

Lines changed: 0 additions & 15 deletions
This file was deleted.

frontend/src/auth/tokens.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/* eslint-disable max-len */
22
import jwtDecode from 'jwt-decode';
33
import Axios from 'axios';
4-
import { logOut } from './logOut';
4+
import router from '@/router';
55

66
export const setAccessToken = (token) => (localStorage.setItem(process.env.VUE_APP_ACCESS_TOKEN, token));
77
export const setRefreshToken = (token) => (localStorage.setItem(process.env.VUE_APP_REFRESH_TOKEN, token));
@@ -24,7 +24,7 @@ export const renewAccessToken = async () => {
2424
const response = await Axios.post('/auth/refresh', {});
2525
localStorage.setItem('matchaAccessToken', response.data.access_token);
2626
} catch (error) {
27-
await logOut();
27+
await router.push('/accounts/signout');
2828
}
2929
}
3030
};

frontend/src/components/shared/FilterSliderDropdown.vue

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,9 @@ export default {
5454
this.slider.min = this.min;
5555
this.slider.max = this.max;
5656
this.slider.start = this.min;
57+
if (this.slider.min === this.slider.max) {
58+
this.slider.max += 1;
59+
}
5760
noUiSlider.create(this.$refs.slider, {
5861
start: [this.slider.startMin, this.slider.startMax],
5962
step: this.slider.step,

frontend/src/components/shared/NavBar.vue

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,13 @@
3030
<router-link v-if="loggedIn" to="/matches" v-bind:class="{'navigation-button-logged-in': true, 'font-black': currentRoute === 'Matches'}">Matches</router-link>
3131
<router-link v-if="loggedIn" to="/settings" v-bind:class="{'navigation-button-logged-in': true, 'font-black': currentRoute === 'Settings'}">Settings</router-link>
3232
<router-link v-if="loggedIn" to="/history" v-bind:class="{'navigation-button-logged-in': true, 'font-black': currentRoute === 'History'}">History</router-link>
33-
<router-link v-if="loggedIn" v-on:click.native="logout()" to="/" class="navigation-button-logged-in">Exit</router-link>
33+
<router-link v-if="loggedIn" to="/accounts/signout" class="navigation-button-logged-in">Exit</router-link>
3434
</div>
3535
</nav>
3636
</template>
3737

3838
<script>
3939
/* eslint-disable indent */
40-
import { logOut } from '@/auth/logOut';
4140
4241
export default {
4342
name: 'Navigation',
@@ -52,10 +51,5 @@ export default {
5251
return this.$store.getters.getLoggedInUser;
5352
},
5453
},
55-
methods: {
56-
async logout() {
57-
await logOut();
58-
},
59-
},
6054
};
6155
</script>

frontend/src/router/index.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import Settings from '../views/app/Settings.vue';
1515
import User from '../components/app/users/User.vue';
1616
import History from '../views/app/History.vue';
1717
import Matches from '../views/app/Matches.vue';
18+
import SignOut from '../views/auth/SignOut.vue';
1819
import store from '../store/index';
1920

2021
Vue.use(VueRouter);
@@ -132,6 +133,11 @@ const routes = [
132133
component: Matches,
133134
beforeEnter: notLoggedInRedirectLogin,
134135
},
136+
{
137+
path: '/accounts/signout',
138+
component: SignOut,
139+
beforeEnter: notLoggedInRedirectLogin,
140+
},
135141
];
136142

137143
const router = new VueRouter({
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<template>
2+
<div>signing out...</div>
3+
</template>
4+
5+
<script>
6+
7+
export default {
8+
name: 'SignOut',
9+
async mounted() {
10+
await this.$http.post('/auth/logout', {
11+
access_token: localStorage.getItem(process.env.VUE_APP_ACCESS_TOKEN),
12+
refresh_token: localStorage.getItem(process.env.VUE_APP_REFRESH_TOKEN),
13+
});
14+
localStorage.removeItem(process.env.VUE_APP_ACCESS_TOKEN);
15+
localStorage.removeItem(process.env.VUE_APP_REFRESH_TOKEN);
16+
localStorage.removeItem(process.env.VUE_APP_VUEX_PERSISTED_STATE);
17+
localStorage.removeItem(process.env.VUE_APP_SECURE_LS_METADATA);
18+
await this.$store.dispatch('logout');
19+
window.location.reload();
20+
},
21+
};
22+
</script>

0 commit comments

Comments
 (0)