Skip to content

Commit

Permalink
Reverted changes made when attempting to publish API and Vue App to s…
Browse files Browse the repository at this point in the history
…ame directory. Removed the onMounted API check in App.vue
  • Loading branch information
rubenriseld committed May 21, 2024
1 parent 8825898 commit 1389591
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 108 deletions.
79 changes: 0 additions & 79 deletions .github/workflows/azure-static-web-apps-mango-ground-0dcb75603.yml

This file was deleted.

16 changes: 0 additions & 16 deletions Gallery.Web/src/App.vue
Original file line number Diff line number Diff line change
@@ -1,21 +1,5 @@
<script setup lang="ts">
import { onMounted } from 'vue';
import Menu from './components/Menu.vue'
import api from './api';
import { useStore } from 'vuex';
const store = useStore();
onMounted(async () => {
try {
const response = await api.get("auth/check");
if (response.status === 200) {
store.commit('SET_AUTH', true);
}
}
catch (error) {
console.error('Error checking authentication:', error);
}
})
</script>

<template>
Expand Down
2 changes: 1 addition & 1 deletion Gallery.Web/src/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import axios from 'axios'
import { useRouter } from 'vue-router'

const api = axios.create({
baseURL: "/api/",
baseURL: import.meta.env.VITE_API_URL,
headers: {
'Content-Type': 'application/json',
},
Expand Down
8 changes: 4 additions & 4 deletions Gallery.Web/src/components/Menu.vue
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ onMounted(async () => {
updateMenuItems();
isLoading.value = false;
});
const menuItems = ref<Array<{ name: string; path: string }>>([
{ name: 'Home', path: '/' },
{ name: 'Admin', path: '/admin' }]
Expand All @@ -50,13 +49,14 @@ async function getCollections() {
}
async function logout() {
try {
await api.post('auth/logout');
store.commit('SET_AUTH', false);
const response = await api.post('auth/logout');
if (response.status === 204) {
store.commit('SET_AUTH', false);
}
}
catch (error) {
console.error('Error logging out:', error);
}
isMenuOpen.value = false;
router.push('/');
}
Expand Down
14 changes: 6 additions & 8 deletions Gallery.Web/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,28 +19,26 @@ const store = createStore({
},
},
});

const routes = [
{ path: '/', component: IndexView },
{ path: '/admin', component: AdminView },
{ path: '/collection/:collectionId', name: 'collection', component: CollectionView, props: true },
{ path: '/login', component: LoginView }
]
];

const router = createRouter({
history: createWebHistory(),
routes,
})
});

router.beforeEach(async (to, from, next) => {
if (to.path === '/admin') {
!store.state.isAuthenticated ? next({ path: '/login', query: { redirect: '/admin' } })
: next()
if (to.path === '/admin' && store.state.isAuthenticated === false) {
next({ path: '/login', query: { redirect: '/admin' } });
}
else next()
else next();
})

createApp(App)
.use(router)
.use(store)
.mount('#app')
.mount('#app');

0 comments on commit 1389591

Please sign in to comment.