how to use prisma in middleware
Unanswered
<ragewire/> posted this in #help-forum
the title says it all (im not using serverless at all)
44 Replies
sadly middleware is forced to edge runtime... since you are using selfhost, you could fetch your own route with has it...
but middleware in meant to be fast, and if your adding db req it makes it slowr. so are you sure you want to do that?
but middleware in meant to be fast, and if your adding db req it makes it slowr. so are you sure you want to do that?
validation
i was told by @joulev it is possible
when nextjs builds it, would it be able to, like would the route be ready
@<ragewire/> the title says it all (im not using serverless at all)
you can't.* you must work around it by fetching your own nodejs route handler in middleware and query prisma inside that nodejs route handler.
* you can if you use prisma accelerate, though it's unlikely you would want to use that since you are not using serverless.
* you can if you use prisma accelerate, though it's unlikely you would want to use that since you are not using serverless.
yes
@joulev yes
ok i wont have a build error or nothing
no
middleware is not run during build
and can i in a layout file have i "time", that runs every 15s and does something, (i plan on having it check user session since i want to auto log out if the token is invalid while the user is sitting on the page)
@joulev
if possible on the server
@joulev client component, setInterval
i do, but it doesnt run at the right setINterval
ends up just spamming my thing
that's wrong
@joulev that's wrong
what do i need to do to fix it
"use client";
function Foo() {
useEffect(() => {
setInterval(...);
}, []);
...
}@joulev ts
"use client";
function Foo() {
useEffect(() => {
setInterval(...);
}, []);
...
}
still doesnt follow the time
nvm i changed it
useEffect(() => {
setInterval(() => {console.log(1)}, 10000)
}, [])
but it runs twice
each time
@joulev is that just do to how useEffect works? and if so / not can i stop that from happening since it would be calling a api endpoint
@<ragewire/> ts
useEffect(() => {
setInterval(() => {console.log(1)}, 10000)
}, [])
actually i forgot the cleanup.
useEffect(() => {
const interval = setInterval(() => {console.log(1)}, 10000);
return () => clearInterval(interval);
}, [])this should work now
@joulev try it
fixed that bug
@joulev idk how people keep track of all the little stuff you got to do
experience i guess, i don't keep track of the things but when things go wrong i usually know why
@joulev experience i guess, i don't keep track of the things but when things go wrong i usually know why
ah, im more of a backend guy but when i have to do frontend i do it but slowly lol
that what happens when you work in a team of 3 and are the only programmer
@joulev is there a way i can apply this to all pages?
apply what?
@joulev apply what?
the set interval code
is it possible to have it in a layout file
because i tried it and it didnt work
@joulev yes
i just figured it out