Next.js Discord

Discord Forum

DYNAMIC_SERVER_USAGE

Answered
African Slender-snouted Crocodil… posted this in #help-forum
Open in Discord
African Slender-snouted CrocodileOP
Below is the code which calls a server function which worked in the previous version of nextjs but now i keep getting this error when i try to build using turbopack

description: "Route /auth/login couldn't be rendered statically because it used cookies. See more info here: https://nextjs.org/docs/messages/dynamic-server-error",
digest: 'DYNAMIC_SERVER_USAGE'
}
Error occurred prerendering page "/auth/login". Read more: https://nextjs.org/docs/messages/prerender-error
TypeError: Cannot read properties of undefined (reading 'forEach')
at bS (.next/server/chunks/ssr/78d98977..js:1:33331) {
digest: '3648386664'
}

 const onSubmit = async (data: LoginValues) => {
   setIsLoading(true)
   try {
     const user = await UserLogin("login", data)
     if (user.success === true) {
       setUser(user.data.token);
       setRefreshToken(user.data.device.id);
       toaster(
           "Successfully",
           "Logged In Successfully"
       )

      return router.push("/")
     }

     setIsLoading(false)
     return toaster(
         "Error",
         "Incorrect credentials"
     )

   } catch (error) {
     toaster(
       "Error",
       "An unexpected error occurred",
     )
   } finally {
     setIsLoading(false)
   }
 }
Answered by African Slender-snouted Crocodile
Putting the page as server and then reusing the client form on the page solved the issue
View full answer

1 Reply

African Slender-snouted CrocodileOP
Putting the page as server and then reusing the client form on the page solved the issue
Answer