Skip to content

Commit

Permalink
Merge pull request #18 from fumeapp/auth-utils
Browse files Browse the repository at this point in the history
⚗️ a 1st attempt at implimenting a controller authorization system
  • Loading branch information
acidjazz authored Sep 2, 2024
2 parents d8493da + 64f0a11 commit 6425bce
Show file tree
Hide file tree
Showing 47 changed files with 7,332 additions and 6,112 deletions.
2 changes: 1 addition & 1 deletion app/components/cartridge/CartridgeList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ defineProps<{ cartridges: Cartridge[] }>()

<template>
<div>
<div class="grid grid-cols-1 gap-4 sm:grid-cols-2 lg:grid-cols-4">
<div class="grid grid-cols-1 gap-4 sm:grid-cols-2 lg:grid-cols-3">
<cartridge-card v-for="cartridge in cartridges" :key="cartridge.id.toString()" :cartridge="cartridge" />
</div>
</div>
Expand Down
46 changes: 30 additions & 16 deletions app/components/header/HeaderProfile.vue
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,20 @@ const items = [
},
],
[
{ shortcuts: ['T'], ...fromLink('Tokens') },
{ shortcuts: ['U'], disabled: !user.value.isAdmin, ...fromLink('Users') },
{
label: 'Tokens',
icon: 'i-mdi-key',
click: async () => await navigateTo('/tokens'),
shortcuts: ['T'],
},
{
label: 'Users',
icon: 'i-mdi-account-multiple',
click: async () => await navigateTo('/users'),
shortcuts: ['U'],
disabled: !user.value.isAdmin,
},
],
[
{
Expand All @@ -32,20 +44,22 @@ const items = [
</script>

<template>
<u-dropdown :items="items">
<u-avatar
:src="user.avatar"
size="sm"
icon="i-mdi-account-circle"
:ui="{ rounded: 'bg-gray-200 dark:bg-gray-800' }"
/>
<template #account="{ item }">
<div class="flex flex-col items-start">
<div class="font-semibold text-gray-800 dark:text-gray-300">{{ item.name }}</div>
<div class="text-sm text-gray-500 dark:text-gray-400">{{ item.email }}</div>
</div>
</template>
</u-dropdown>
<div>
<u-dropdown :items="items">
<u-avatar
:src="user.avatar"
size="sm"
icon="i-mdi-account-circle"
:ui="{ rounded: 'bg-gray-200 dark:bg-gray-800' }"
/>
<template #account="{ item }">
<div class="flex flex-col items-start">
<div class="font-semibold text-gray-800 dark:text-gray-300">{{ item.name }}</div>
<div class="text-sm text-gray-500 dark:text-gray-400">{{ item.email }}</div>
</div>
</template>
</u-dropdown>
</div>
</template>

<style scoped></style>
5 changes: 2 additions & 3 deletions app/components/shot/ShotForm.vue
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ const route = useRoute()
const { user } = useUserSession()
const form = ref<Form<any>>()
const state = reactive({
user: route.params.user ? route.params.user : user.id,
cartridge: props.pen.cartridge?.id,
cartridgeId: props.pen.cartridge?.id,
units: shotUnits[1],
date: format(new Date(), 'yyyy-MM-dd'),
})
Expand All @@ -27,7 +26,7 @@ const options = computed(() =>
const create = async () => useApi()
.setForm(form?.value)
.api<MetapiResponse<Shot>>(
route.params.user ? `/api/user/${route.params.user}/shot` : '/api/shot',
`/api/user/${route.params.user ? route.params.user : user.value.id}/shot`,
{ method: 'POST', body: { ...state, date: new Date(`${state.date}T00:00:00`).toISOString() } },
)
.then(() => emit('created'))
Expand Down
10 changes: 6 additions & 4 deletions app/components/shot/ShotLog.vue
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@ import { format } from 'date-fns'
defineProps<{ shots?: Shot[] }>()
const emit = defineEmits(['reload'])
const route = useRoute()
const { user } = useUserSession()
const remove = async (id: bigint) =>
await useApi().api(route.params.user
? `/api/user/${route.params.user}/shot/${id.toString()}`
: `/api/shot/${id.toString()}`, { method: 'DELETE' }).then(() => emit('reload'))
const remove = async (id: number) =>
await useApi().api(
`/api/user/${route.params.user ? route.params.user : user.value.id}/shot/${id}`,
{ method: 'DELETE' },
).then(() => emit('reload'))
const confirm = (shot: Shot) =>
useConfirm()
Expand Down
6 changes: 3 additions & 3 deletions app/pages/home.vue
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ useSeoMeta({
ogDescription: page.value.description,
})
const { loggedIn } = useUserSession()
const { loggedIn, user } = useUserSession()
const { data: pens, refresh: pensRefresh } = await useFetch<MetapiResponse<Pen[]>>('/api/pen')
const { data: cartridges, refresh: cartridgesRefresh } = await useFetch<MetapiResponse<Cartridge[]>>('/api/cartridge')
const { data: pens, refresh: pensRefresh } = await useFetch<MetapiResponse<Pen[]>>(`/api/user/${user.value.id}/pen`)
const { data: cartridges, refresh: cartridgesRefresh } = await useFetch<MetapiResponse<Cartridge[]>>(`/api/user/${user.value.id}/cartridge`)
const reload = async () => {
await pensRefresh()
Expand Down
25 changes: 5 additions & 20 deletions app/pages/users/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -15,26 +15,11 @@ set(
)
const columns = [
{
label: 'User',
key: 'user',
},
{
label: 'Created At',
key: 'createdAt',
},
{
label: 'Updated At',
key: 'updatedAt',
},
{
label: 'Pens',
key: 'pens',
},
{
label: 'Actions',
key: 'actions',
},
{ label: 'User', key: 'user' },
{ label: 'Created At', key: 'createdAt' },
{ label: 'Updated At', key: 'updatedAt' },
{ label: 'Pens', key: 'pens' },
{ label: 'Actions', key: 'actions' },
]
const { data: users } = await useFetch<MetapiResponse<User>>('/api/all/user')
Expand Down
Loading

0 comments on commit 6425bce

Please sign in to comment.