mirror of
https://github.com/ZorgCC/psina-avatar-frontend.git
synced 2025-06-06 02:22:03 +03:00
feature: add user to settings
This commit is contained in:
parent
a70ec8a49a
commit
678ba6ccd2
@ -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>
|
@ -47,6 +47,7 @@
|
||||
rounded
|
||||
onclick="this.blur()"
|
||||
type="submit"
|
||||
:disabled="password.length < 1 || username.length < 1"
|
||||
@click.prevent="handleSubmit"
|
||||
>
|
||||
Log in
|
||||
|
@ -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>
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user