feature: add user to settings

This commit is contained in:
Aleksei Tsybin 2022-03-02 23:20:49 +03:00
parent a70ec8a49a
commit 678ba6ccd2
3 changed files with 11 additions and 2 deletions

View File

@ -1 +1 @@
<template> <div id="app"> <div class="container"> <HeaderComponent @checkAuth="checkAuth" :auth="isAuth" :user="user" /> <router-view @checkAuth="checkAuth"></router-view> </div> </div> </template> <script> import HeaderComponent from '@/components/HeaderComponent' export default { components: { HeaderComponent }, data() { return { isAuth: null, user: '', } }, methods: { loggedOut() { this.isAuth = false }, async checkAuth() { this.isAuth = localStorage.getItem('jwt') != null if (this.isAuth) { await this.$http .get('me', { headers: { Authorization: `Bearer ${localStorage.getItem('jwt')}` }, }) .then((response) => { localStorage.setItem('user', JSON.stringify(response.data.user)) this.user = response.data.user }) .catch(function (error) { console.error(error.response) }) } }, }, async mounted() { await this.checkAuth() }, } </script>
<template> <div id="app"> <div class="container"> <HeaderComponent @checkAuth="checkAuth" :auth="isAuth" :user="user" /> <router-view @checkAuth="checkAuth" :user="user"></router-view> </div> </div> </template> <script> import HeaderComponent from '@/components/HeaderComponent' export default { components: { HeaderComponent }, data() { return { isAuth: null, user: '', } }, methods: { loggedOut() { this.isAuth = false }, async checkAuth() { this.isAuth = localStorage.getItem('jwt') != null if (this.isAuth) { await this.$http .get('me', { headers: { Authorization: `Bearer ${localStorage.getItem('jwt')}` }, }) .then((response) => { localStorage.setItem('user', JSON.stringify(response.data.user)) this.user = response.data.user }) .catch(function (error) { console.error(error.response) }) } }, }, async mounted() { await this.checkAuth() }, } </script>

View File

@ -47,6 +47,7 @@
rounded
onclick="this.blur()"
type="submit"
:disabled="password.length < 1 || username.length < 1"
@click.prevent="handleSubmit"
>
Log in

View File

@ -1,10 +1,18 @@
<template>
<h2>settings</h2>
<div>
<h2>settings</h2>
<p>user data from backend: {{ user }}</p>
</div>
</template>
<script>
export default {
name: 'SettingsView',
props: {
user: {
type: [String, Object],
},
},
}
</script>