Mads
Mads
Explore posts from servers
NNuxt
Created by Paolo on 8/26/2024 in #❓・help
Metadata for Route
Or maybe be wrong. You want to do a navigation and pass some data along, without setting a query? It seems like the wrong approach. I would look into using setting a useState or maybe definePageMeta like so. definePageMeta({ pageType: 'Checkout', })
3 replies
NNuxt
Created by Paolo on 8/26/2024 in #❓・help
Metadata for Route
You still can using definePageMeta.
3 replies
NNuxt
Created by Gregor on 8/27/2024 in #❓・help
pretty urls for e-commerce shop
Why not use a folder structure like this /[category]/[subcategory]/[subsubcategory]/[product] It sounds like you need to define a structure. Also use useRouter() to extract the queries and params. Much easier.
3 replies
NNuxt
Created by isakwang on 8/27/2024 in #❓・help
Non fatal server error
You should probably set ignoreResponseError to true. Assuming you use $fetch (useFetch) await $fetch('/api/used-cars/all', { method: 'GET', ignoreResponseError: true, })
7 replies
NNuxt
Created by Josh Deltener on 8/26/2024 in #❓・help
Is there a way to NOT show an HTML error from an API?
But yes, as you mentioned I do set the responseStatus. The createError is a suboptimal solution imo.
8 replies
NNuxt
Created by Josh Deltener on 8/26/2024 in #❓・help
Is there a way to NOT show an HTML error from an API?
Then I use it something like this
try {
const response = await $fetch('/api/used-cars/all', {
method: 'GET',
ignoreResponseError: true,
})

if (response && 'value' in response) {
return response.value.used_cars
}
else {
if (response.error._tag === 'UnauthorizedError') {
toast.add({ title: 'Du er ikke autoriseret', description: 'Du er måske ikke logget ind, eller har ikke autorisation til at oprette en prisprotokol', color: 'red' })
}
try {
const response = await $fetch('/api/used-cars/all', {
method: 'GET',
ignoreResponseError: true,
})

if (response && 'value' in response) {
return response.value.used_cars
}
else {
if (response.error._tag === 'UnauthorizedError') {
toast.add({ title: 'Du er ikke autoriseret', description: 'Du er måske ikke logget ind, eller har ikke autorisation til at oprette en prisprotokol', color: 'red' })
}
8 replies
NNuxt
Created by Josh Deltener on 8/26/2024 in #❓・help
Is there a way to NOT show an HTML error from an API?
import { and, eq } from 'drizzle-orm'
import { Err, Ok } from 'ts-results-es'
import { used_cars } from '@/../server/database/core-schema'

export default defineEventHandler(async (event) => {
if (!event.context.session) {
setResponseStatus(event, 401, 'You are not logged in')
return new Err({ _tag: 'UnauthorizedError', message: 'You are not logged in' } as const)
}
if (!event.context.user) {
setResponseStatus(event, 401, 'Could not find user')
return new Err({ _tag: 'UnauthorizedError', message: 'Could not find user' } as const)
}

const user = event.context.user

if (!user.selected_company_id) {
setResponseStatus(event, 401, 'User has no selected company')
return new Err({ _tag: 'NoSelectedCompanyError', message: 'User has no selected company' } as const)
}

try {
const cars = await useDB().query.used_cars.findMany({
where: and(
eq(used_cars.company_id, user.selected_company_id),
),
}).execute()

return new Ok({
_tag: 'Success',
message: 'Used cars found',
used_cars: cars,
} as const)
}
catch (error) {
console.error(error)
setResponseStatus(event, 500, 'Failed to fetch used cars')
return new Err({ _tag: 'DatabaseFetchError', message: 'Failed to fetch used cars', error } as const)
}
})
import { and, eq } from 'drizzle-orm'
import { Err, Ok } from 'ts-results-es'
import { used_cars } from '@/../server/database/core-schema'

export default defineEventHandler(async (event) => {
if (!event.context.session) {
setResponseStatus(event, 401, 'You are not logged in')
return new Err({ _tag: 'UnauthorizedError', message: 'You are not logged in' } as const)
}
if (!event.context.user) {
setResponseStatus(event, 401, 'Could not find user')
return new Err({ _tag: 'UnauthorizedError', message: 'Could not find user' } as const)
}

const user = event.context.user

if (!user.selected_company_id) {
setResponseStatus(event, 401, 'User has no selected company')
return new Err({ _tag: 'NoSelectedCompanyError', message: 'User has no selected company' } as const)
}

try {
const cars = await useDB().query.used_cars.findMany({
where: and(
eq(used_cars.company_id, user.selected_company_id),
),
}).execute()

return new Ok({
_tag: 'Success',
message: 'Used cars found',
used_cars: cars,
} as const)
}
catch (error) {
console.error(error)
setResponseStatus(event, 500, 'Failed to fetch used cars')
return new Err({ _tag: 'DatabaseFetchError', message: 'Failed to fetch used cars', error } as const)
}
})
8 replies
NNuxt
Created by Josh Deltener on 8/26/2024 in #❓・help
Is there a way to NOT show an HTML error from an API?
Hi Josh. I recently went through same frustration. Here’s how I handle it:
8 replies
NNuxt
Created by tsi-trevor on 5/14/2024 in #❓・help
How can I remove a route parameter value?
Remember to use await or return
4 replies
NNuxt
Created by tsi-trevor on 5/14/2024 in #❓・help
How can I remove a route parameter value?
or navigateTo({ path: ‘/foo’})
4 replies
NNuxt
Created by 83inc on 5/15/2024 in #❓・help
Amateur Looking for Help Making POST to MySQL Using Nuxt 3
Would you be able to post it as a Gist or just add the code in here? But from just reading your post I would assume your connection to the Nitro backend is fine and gets called when you want it to. It seems like the data it receives could be wrong. I would debug here first, throw in some console logs to see what it catches. Does it receive your body data? If it does, onto next issue. Other than that, I would highly recommend Drizzle or Prisma as it would give you some better error logs on what goes wrong.
2 replies
NNuxt
Created by marvin on 5/16/2024 in #❓・help
Best practice for using the Route for storing state
I believe what you are talking about is modal routes. It’s a bit complex to build as there can be many edge cases. Luckily there is a module for that. https://nuxt-pages-plus.pages.dev/routing/modal-routes/ It is great practice to add /create for creation, this way you can link to the page of creation. Adding a modal is just a style preference. Best of luck.
3 replies
NNuxt
Created by Mads on 7/20/2023 in #❓・help
Layer Extend broken on Vercel
I don't think you are doing anything wrong. I believe Nuxt has a bug where it will fail deployment as soon as you extend and use a component.
25 replies
NNuxt
Created by Mads on 7/20/2023 in #❓・help
Layer Extend broken on Vercel
Yeah, I would try to keep both extended layers and comment out the component you use.
25 replies
NNuxt
Created by Mads on 7/20/2023 in #❓・help
Layer Extend broken on Vercel
Are you using a component from layer that is failing?
25 replies