Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
khanzadimahdi committed Apr 2, 2024
1 parent 167f799 commit 45dbc53
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 25 deletions.
17 changes: 9 additions & 8 deletions frontend/components/dashboard/articles/list.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,20 @@
const showConfirm = ref(false)
const confirmDelete = ref(false)
const showModal = ref(false)
const cookie = useState("cookie")
const cookie = useCookie("jwt")
const postData = ref("")
const uuid = ref("")
const resolveUrl = useApiUrlResolver().resolve
const {
data: response,
status,
pending,
error,
} = await useAsyncData('articles' , () => $fetch(`${baseURL}/api/dashboard/articles`, {
headers: {authorization: `Bearer ${cookie.value}`}
}),{ lazy:true})
} = await useAsyncData('articles' , () => $fetch(resolveUrl(`api/dashboard/articles`), {
lazy:true,
headers: {authorization: `Bearer ${cookie.value}`}
}))
if (status.value = "success") {
postData.value = response.value.items
Expand All @@ -25,8 +27,7 @@ function changePost(id) {
}
async function putData(value) {
const cookie = useCookie("jwt")
const url = useApiUrlResolver().resolve(`api/dashboard/articles`)
const url = resolveUrl(`api/dashboard/articles`)
const {status, error } = await useAsyncData('change',() => $fetch(url, {
method: "PUT",
Expand All @@ -47,7 +48,7 @@ async function putData(value) {
watch(confirmDelete, async () => {
if (confirmDelete.value) {
const {status, error} = await useAsyncData('delete' , ()=>$fetch(`${baseURL}/api/dashboard/articles/${id}`, {
const {status, error} = await useAsyncData('delete' , ()=>$fetch(resolveUrl(`api/dashboard/articles/${id}`), {
method: "DELETE",
headers: {
Authorization: `Bearer ${cookie.value}`
Expand Down Expand Up @@ -109,7 +110,7 @@ function close() {
<tbody class="text-center " v-if="postData.length">
<tr v-for="(item,index) in postData" :key="index">
<th>{{ index + 1 }}</th>
<td class="col"><img class="img-fluid rounded m-auto w-100 h-100" :src="`${baseURL}/files/${item.cover}`"
<td class="col"><img class="img-fluid rounded m-auto w-100 h-100" :src="resolveUrl(`files/${item.cover}`)"
:alt="item.title"></td>
<td class="col">{{ item.author.name }}</td>
<td class="col"><span class="limited" v-if="item.uuid">{{ item.uuid }}</span></td>
Expand Down
10 changes: 8 additions & 2 deletions frontend/middleware/auth.global.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
export default defineNuxtRouteMiddleware((to, from) => {
//console.log(to);
//console.log(from);
if (! to.path.startsWith("/dashboard")) {
return
}

const cookie = useCookie("jwt")
if (!cookie.value) {
navigateTo("/auth/login")
}
});
3 changes: 2 additions & 1 deletion frontend/pages/auth/login.vue
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,8 @@ onMounted(() => {
})
function setCookie(token) {
const expiresAt = (new Date()).setTime(time.getTime() + (60 * 15 * 1000))
const time = new Date()
const expiresAt = time.setTime(time.getTime() + (60 * 15 * 1000))
document.cookie = `jwt=${token};expires=${expiresAt};path=/`
}
Expand Down
12 changes: 1 addition & 11 deletions frontend/pages/dashboard/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,10 @@
<div class="animsition">
<div class="page-wrapper">

<!-- WELCOME-->
<section class="welcome2 p-t-40 p-b-55">
<DashboardHomeWelcome/>
</section>
<!-- END WELCOME-->

<!-- PAGE CONTENT-->
<div class="page-container3">
<section class="alert-wrap p-t-70 p-b-70">
<div class="container">
<!-- ALERT-->
<DashboardHomeAlert />
<!-- END ALERT-->
</div>
<DashboardHomeAlert />
</section>
<section>
<div class="container">
Expand Down
4 changes: 2 additions & 2 deletions frontend/pages/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ const data = computed(()=> store.getData)
</script>

<template>
<div v-if="responses">
<template v-if="responses?.elements" v-for="element in responses.elements">
<div v-if="data">
<template v-if="data?.elements" v-for="element in data.elements">
<Jumbotron v-if="element.type=='jumbotron'" :body="element.body"/>
<Featured v-if="element.type=='featured'" :body="element.body"/>
</template>
Expand Down
2 changes: 1 addition & 1 deletion frontend/store/homePage.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
actions: {
async fetchData() {
const data = await $fetch(useApiUrlResolver().resolve("api/home"))
this.homeAll = data
this.data = data
}
}
})

0 comments on commit 45dbc53

Please sign in to comment.