Added UserProfile view and endpoint
continuous-integration/drone/push Build is passing
Details
continuous-integration/drone/push Build is passing
Details
parent
016a01614a
commit
14aa05e9fe
@ -0,0 +1,76 @@
|
||||
<template>
|
||||
<div class="Profile">
|
||||
<div class="updateProfile">
|
||||
<label for="first_name">Fornavn:</label>
|
||||
<input type="text" v-model="user.first_name" name="first_name">
|
||||
<label for="last_name">Efternavn:</label>
|
||||
<input type="text" v-model="user.last_name" name="last_name">
|
||||
<input type="submit" value="Opdater" @click="updateProfile">
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
.Profile {
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
}
|
||||
|
||||
.updateProfile {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
width: fit-content;
|
||||
gap: 5px;
|
||||
|
||||
}
|
||||
</style>
|
||||
|
||||
<script lang="ts">
|
||||
import type { User } from '@/interfaces/user';
|
||||
|
||||
export default {
|
||||
name: "UserProfile",
|
||||
data() {
|
||||
return {
|
||||
user: {} as User
|
||||
};
|
||||
},
|
||||
async created() {
|
||||
await this.getUserInfo();
|
||||
},
|
||||
methods: {
|
||||
async updateProfile() {
|
||||
const res = await fetch(`${import.meta.env.VITE_BASE_API_URL}/user`, {
|
||||
credentials: import.meta.env.DEV ? "include" : undefined,
|
||||
method: "PUT",
|
||||
body: JSON.stringify({
|
||||
first_name: this.user.first_name,
|
||||
last_name: this.user.last_name
|
||||
}),
|
||||
headers: {
|
||||
"Content-Type": "Application/json"
|
||||
}
|
||||
});
|
||||
if (res.status === 401 || res.status === 403) {
|
||||
this.$router.push({ path: "/login", query: { ref: this.$route.path } });
|
||||
}
|
||||
else if (res.status === 200) {
|
||||
const data = await res.json();
|
||||
this.user = data;
|
||||
}
|
||||
},
|
||||
async getUserInfo() {
|
||||
const res = await fetch(`${import.meta.env.VITE_BASE_API_URL}/user`, {
|
||||
credentials: import.meta.env.DEV ? "include" : undefined
|
||||
});
|
||||
if (res.status === 401 || res.status === 403) {
|
||||
this.$router.push({ path: "/login", query: { ref: this.$route.path } });
|
||||
}
|
||||
else if (res.status === 200) {
|
||||
const data = await res.json();
|
||||
this.user = data;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
||||
Loading…
Reference in New Issue