Skip to content
Snippets Groups Projects
Commit a07f0a80 authored by JunGu Kang's avatar JunGu Kang
Browse files

Implement Logout Feature and Display Logout Button on AppBar

parent 37fdbaad
No related branches found
No related tags found
2 merge requests!37Deploy,!9#7 Implement Logout Feature and Display Logout Button on AppBar
Pipeline #4119 passed
......@@ -80,7 +80,7 @@ export default {
if ([200, 201, 400, 404].includes(res.status)) {
return Promise.all([res.json(), res]);
}
// If response status is not equal to 200 or 404, go to catch.
// If response status is not equal to 200, 201, 400, or 404, go to catch.
throw new Error('알 수 없는 응답입니다.');
})
.then((values) => {
......
......@@ -11,16 +11,26 @@
<v-toolbar-title>FITMIN</v-toolbar-title>
<v-spacer></v-spacer>
<span
class="mr-3"
v-if="isLogin"
>
{{ loginUser.name }}{{ loginUser.nickname ? `(${loginUser.nickname})` : '' }} 트레이너
</span>
<v-btn
icon
v-if="isLogin"
@click="doLogout"
>
<v-icon>mdi-logout</v-icon>
</v-btn>
</v-app-bar>
</template>
<script>
import { mapState, mapGetters, mapActions } from 'vuex';
import APISetting from '@/settings/api';
export default {
name: 'NavigationBar',
......@@ -38,8 +48,23 @@ export default {
},
methods: {
doLogout() {
fetch(APISetting.endpoints.auth.logout, APISetting.settings.post(null))
.then((res) => {
if (res.status === 204) {
this.setLogout();
this.$router.push('/');
}
// If response status is not equal to 204, go to catch.
throw new Error('알 수 없는 응답입니다.');
})
.catch(() => {
// Do nothing.
});
},
...mapActions([
'toggleNavDrawer',
'setLogout',
]),
},
};
......
......@@ -22,7 +22,7 @@ export default {
mode: 'cors',
},
post: data => ({
body: JSON.stringify(data),
body: data !== null ? JSON.stringify(data) : null,
credentials: 'include',
headers: {
Accept: 'application/json',
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment