roobr
roobr
Explore posts from servers
NNuxt
Created by roobr on 6/2/2024 in #❓・help
Tips to secure your nuxt Application.
Hi All, I am currently having lots of triggers on my production build of people triggering routes that dont exist like.env and the likes, is there any way to time these people out or block them if they hit to many wrong routes?
22 replies
PPrisma
Created by roobr on 5/27/2024 in #help-and-questions
Nuxt 3 - Prisma building production
Hi Guys, it seems like I am havcing issues with my Prisma sections of my system working once i build and run my application. Just wondering if there is another step I am missing as it works fine when doing it on my dev server using pnpm run dev. Thanks in advance
22 replies
NNuxt
Created by roobr on 5/19/2024 in #❓・help
Nuxt 3 Supabase serverSupabaseUser(event) returning NULL
Hello, I am currently having issues getting the client via the serverSuperbaseUser function. Can you please let me know if I am handling fetching a user on server api correctly? sometimes it works and sometimes it returns null even when logged in using supabase auth I have tried changing cookie options to get it to work correctly but doesn't seem to function all the time. Code for reference:
import { PrismaClient } from '@prisma/client'
import { serverSupabaseUser } from '#supabase/server';
import { ref } from 'vue'

const prisma = new PrismaClient()
const type = ref("")

export default defineEventHandler(async (event) => {
type.value = event.context.params.type
console.log(type)
if (!(type.value === 'agency' || type.value === 'general' || type.value === 'admin')) {
throw createError({ statusCode: 400, message: 'Invalid type' })
}
// add in check to see if admin is authorised
if (type.value === 'admin') {
const user = await serverSupabaseUser(event)
if (!user) {
throw createError({ statusCode: 401, message: 'Unauthorized' })
}
const admin = await prisma.admin_users.findFirst({
where: {
user_id: user.id,
},
})
if (!admin) {
throw createError({ statusCode: 401, message: 'Unauthorized' })
}
}
try {
const items = await prisma.items.findMany({
include: {
item_categories_item_categories_item_idTocategories: {
include: {
categories_item_categories_category_idTocategories: {
select: {
id: true,
name: true,
},
},
},
},
item_subcategory_item_subcategory_item_idTosubcategories: {
include: {
subcategories_item_subcategory_subcat_idTosubcategories: {
select: {
id: true,
name: true,
main_category: true,
},
},
},
},
},
})
const categories = await prisma.categories.findMany(
{
select: {
id: true,
name: true,
agency_category: true,
general_category: true,
},
orderBy: {
list_order: 'asc',
},
}
)
const subcategories = await prisma.subcategories.findMany(
{
select: {
id: true,
name: true,
main_category: true,
},
}
)

const formattedItems = items
.map((item) => {
const category = item.item_categories_item_categories_item_idTocategories?.categories_item_categories_category_idTocategories
if (!category) {
console.warn('Category details are missing for item:', item)
return null
}

const subcategory = item.item_subcategory_item_subcategory_item_idTosubcategories?.subcategories_item_subcategory_subcat_idTosubcategories
const subCategoryName = subcategory ? subcategory.name : 'Other'

return {
id: item.item_id,
title: item.item_title,
description: item.item_description,
image: item.item_image,
melb_stock: item.melb_stock,
syd_stock: item.syd_stock,
qld_stock: item.qld_stock,
total_stock: item.total_stock,
category: category.name,
categoryId: category.id,
subCategories: [subCategoryName],
agency_item: item.agency_item,
general_item: item.general_item,
...((type.value === 'agency' || type.value === 'admin') && { price: item.rate })
}
})
.filter((item) => item !== null)

return { formattedItems, categories, subcategories }
} catch (error) {
console.error('Failed to fetch items:', error)
throw createError({ statusCode: 500, message: 'Failed to fetch items' })
}
})
import { PrismaClient } from '@prisma/client'
import { serverSupabaseUser } from '#supabase/server';
import { ref } from 'vue'

const prisma = new PrismaClient()
const type = ref("")

export default defineEventHandler(async (event) => {
type.value = event.context.params.type
console.log(type)
if (!(type.value === 'agency' || type.value === 'general' || type.value === 'admin')) {
throw createError({ statusCode: 400, message: 'Invalid type' })
}
// add in check to see if admin is authorised
if (type.value === 'admin') {
const user = await serverSupabaseUser(event)
if (!user) {
throw createError({ statusCode: 401, message: 'Unauthorized' })
}
const admin = await prisma.admin_users.findFirst({
where: {
user_id: user.id,
},
})
if (!admin) {
throw createError({ statusCode: 401, message: 'Unauthorized' })
}
}
try {
const items = await prisma.items.findMany({
include: {
item_categories_item_categories_item_idTocategories: {
include: {
categories_item_categories_category_idTocategories: {
select: {
id: true,
name: true,
},
},
},
},
item_subcategory_item_subcategory_item_idTosubcategories: {
include: {
subcategories_item_subcategory_subcat_idTosubcategories: {
select: {
id: true,
name: true,
main_category: true,
},
},
},
},
},
})
const categories = await prisma.categories.findMany(
{
select: {
id: true,
name: true,
agency_category: true,
general_category: true,
},
orderBy: {
list_order: 'asc',
},
}
)
const subcategories = await prisma.subcategories.findMany(
{
select: {
id: true,
name: true,
main_category: true,
},
}
)

const formattedItems = items
.map((item) => {
const category = item.item_categories_item_categories_item_idTocategories?.categories_item_categories_category_idTocategories
if (!category) {
console.warn('Category details are missing for item:', item)
return null
}

const subcategory = item.item_subcategory_item_subcategory_item_idTosubcategories?.subcategories_item_subcategory_subcat_idTosubcategories
const subCategoryName = subcategory ? subcategory.name : 'Other'

return {
id: item.item_id,
title: item.item_title,
description: item.item_description,
image: item.item_image,
melb_stock: item.melb_stock,
syd_stock: item.syd_stock,
qld_stock: item.qld_stock,
total_stock: item.total_stock,
category: category.name,
categoryId: category.id,
subCategories: [subCategoryName],
agency_item: item.agency_item,
general_item: item.general_item,
...((type.value === 'agency' || type.value === 'admin') && { price: item.rate })
}
})
.filter((item) => item !== null)

return { formattedItems, categories, subcategories }
} catch (error) {
console.error('Failed to fetch items:', error)
throw createError({ statusCode: 500, message: 'Failed to fetch items' })
}
})
4 replies
PPrisma
Created by roobr on 5/6/2024 in #help-and-questions
orderBy on a relation include
Hello, I am hoping for some assistance with the best way to handle my query and see what is possible.
const items = await prisma.items.findMany({
include: {
item_categories_item_categories_item_idTocategories: {
include: {
categories_item_categories_category_idTocategories: {
select: {
id: true,
name: true,
},
orderBy: {
list_order: 'asc',
},
},
},
},
item_subcategory_item_subcategory_item_idTosubcategories: {
include: {
subcategories_item_subcategory_subcat_idTosubcategories: {
select: {
id: true,
name: true,
main_category: true,
},
},
},
},
},
const items = await prisma.items.findMany({
include: {
item_categories_item_categories_item_idTocategories: {
include: {
categories_item_categories_category_idTocategories: {
select: {
id: true,
name: true,
},
orderBy: {
list_order: 'asc',
},
},
},
},
item_subcategory_item_subcategory_item_idTosubcategories: {
include: {
subcategories_item_subcategory_subcat_idTosubcategories: {
select: {
id: true,
name: true,
main_category: true,
},
},
},
},
},
4 replies