mrk
mrk
Explore posts from servers
NNuxt
Created by mrk on 11/26/2024 in #❓・help
How to check if request to API endpoint is internal or external?
I have custom API endpoints under /api protected using nuxt-auth-utils and a server middleware which uses requireUserSession() for all routes under /api. I wish to omit one of these routes from requiring a cookie (logged-in session) ONLY if the request is an internal request, that is, if it was made by either the server (nitro) or the client (nuxt). Is there a deterministic way of checking if a request is an internal request coming from within the app (nuxt and/or nitro)? I already searched through the nuxt, nitro and h3 docs and couldn't find anyting. I would also like to avoid using e.g. "Referer" header which is not 100% deterministic and still only comes from client requests
5 replies
DTDrizzle Team
Created by mrk on 5/24/2024 in #help
UPSERT operation not working for SQLite/Turso
Hey! So I'm trying to do a BULK UPSERT for multiple rows with a .returning() and its not working. I expect: - UPDATE: rows which include the PKs "id" - INSERT: rows which DO NOT include the PKs "id" the code is as follows (I've followed the docs and tried some variants):
const data [
// this row IS NOT updated (from "Untitled1" to "John")
{ id: "nhdbw1xklex5", name: "John" },
// this row IS properly inserted
{ name: "Unknown2" }
]
const result = await db
.insert(users)
.values(data)
.onConflictDoUpdate({
target: users.id,
set: { id: sql.raw(`excluded.${user.id.name}`) },
})
.returning();
const data [
// this row IS NOT updated (from "Untitled1" to "John")
{ id: "nhdbw1xklex5", name: "John" },
// this row IS properly inserted
{ name: "Unknown2" }
]
const result = await db
.insert(users)
.values(data)
.onConflictDoUpdate({
target: users.id,
set: { id: sql.raw(`excluded.${user.id.name}`) },
})
.returning();
I would expect results being:
[
{ id: "nhdbw1xklex5", name: "John" },
{ id: "<nanoid-here>", name: "Untitled2" }
]
[
{ id: "nhdbw1xklex5", name: "John" },
{ id: "<nanoid-here>", name: "Untitled2" }
]
and I keep getting (the first row is unchanged / not updated):
[
{ id: "nhdbw1xklex5", name: "Untitled1" },
{ id: "<nanoid-here>", name: "Untitled2" }
]
[
{ id: "nhdbw1xklex5", name: "Untitled1" },
{ id: "<nanoid-here>", name: "Untitled2" }
]
Am I doing something wrong? Thanks! Any help is greatly appreciated!
9 replies
DDeno
Created by mrk on 9/20/2023 in #help
Deno-native Nuxt.js?
No description
7 replies