Skip to content

Commit 07fc45e

Browse files
committed
Admin Panel Update
1 parent 2a19eea commit 07fc45e

File tree

8 files changed

+86
-97
lines changed

8 files changed

+86
-97
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
"license": "MIT",
1010
"require": {
1111
"php": "^8.1",
12-
"atomjoy/apilogin": "^4.4.7",
12+
"atomjoy/apilogin": "^4.4.8",
1313
"guzzlehttp/guzzle": "^7.2",
1414
"laravel/framework": "^10.10",
1515
"laravel/sanctum": "^3.2",

composer.lock

Lines changed: 61 additions & 88 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

resources/js/atomjoy/notify/NotifyPanel/stores/notify-panel.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ import axios from 'axios'
55
export const useNotifyStore = defineStore('notify', () => {
66
// State
77
const items = ref(new Map())
8-
const page = ref(1)
9-
const unread = ref(0)
10-
const open = ref(false)
8+
let page = ref(1)
9+
let unread = ref(0)
10+
let open = ref(false)
1111

1212
// Actions
1313
function toggleOpen() {

resources/js/atomjoy/notify/ProfilMenu/ProfilMenu.vue

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,11 @@ if (props.avatar) {
3030
avatar_path.value = avatar_default
3131
}
3232
33+
function defImage(e) {
34+
e.onerror = null
35+
e.target.src = avatar_default
36+
}
37+
3338
onMounted(() => {})
3439
</script>
3540
<template>
@@ -56,7 +61,7 @@ onMounted(() => {})
5661
</div>
5762

5863
<div class="user-image">
59-
<img :src="avatar_path" />
64+
<img :src="avatar_path" @error="defImage" />
6065
<div :class="{ 'open-icon': true, 'close-icon': open }"><ChevronIcon /></div>
6166
</div>
6267
</div>

resources/js/atomjoy/panel/client/components/Topbar/Topbar.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ const notify = useNotifyStore()
2323
<ProfilMenu :logged="logged" :profil="true" :avatar="avatar_path" :name="user.name" :email="user.email" />
2424
<div class="notify-box">
2525
<ChangeTheme />
26-
<AdminPanelButton :active="true" />
26+
<AdminPanelButton v-if="user.is_admin" :active="false" />
2727
<MessagesButton :active="message" @click="message = !message" />
2828
<NotifyButton :active="notify.unread > 0" @click="notify.toggleOpen" />
2929
<NotifyPanel />

resources/js/atomjoy/panel/client/router/routes.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,10 @@ const routes = [
2020
},
2121
// admin panel dashboard
2222
{
23-
path: '/panel/dashboard',
23+
path: '/admin/dashboard',
2424
name: 'admin.dashboard',
2525
component: () => import('@/atomjoy/panel/admin/views/DashboardView.vue'),
26-
meta: { requiresAuth: true },
26+
meta: { requiresAuth: true, requiresAdmin: true },
2727
},
2828
// client panel profil
2929
{

resources/js/atomjoy/panel/client/slots/NavbarSlot.vue

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@ import { ref } from 'vue'
33
import { RouterLink } from 'vue-router'
44
import ChevronIcon from '@/atomjoy/icons/ChevronIcon.vue'
55
import MenuIcon from '@/atomjoy/icons/MenuIcon.vue'
6+
import { useAuthStore } from '@/atomjoy/auth/stores/auth.js'
7+
8+
const auth = useAuthStore()
9+
const user = auth.getUser
610
const open = ref(false)
711
</script>
812

@@ -19,7 +23,7 @@ const open = ref(false)
1923

2024
<slot name="footer">
2125
<div class="footer-links">
22-
<RouterLink to="/admin/panel" class="link-admin-dashboard"> {{ $t('Go to admin panel') }} </RouterLink>
26+
<RouterLink v-if="user.is_admin" to="/admin/panel" class="link-admin-dashboard"> {{ $t('Go to admin panel') }} </RouterLink>
2327
</div>
2428
</slot>
2529
</div>

resources/js/router/index.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,13 @@ router.beforeEach(async (to, from, next) => {
4848
const auth = useAuthStore()
4949
// ✅ Login with remember me token and/or check is user authenticated
5050
await auth.isAuthenticated()
51+
// Only admin route
52+
if (to.meta.requiresAdmin) {
53+
if (!auth.isLoggedIn.value || auth.getUser.value.is_admin != 1) {
54+
// ✅ Redirect to login if not logged or not admin
55+
next({ name: 'login' })
56+
}
57+
}
5158
// ✅ Redirect to panel if logged
5259
if (to.name == 'login' && auth.isLoggedIn.value) {
5360
// Panel route name here: panel or client.panel

0 commit comments

Comments
 (0)