2 questions server actions and layouts
Unanswered
Giant panda posted this in #help-forum
Giant pandaOP
Hi there i need some help.
I want to know if for x reason iam building a nextjs app with a separated backend (I know this is not ideal) I can make post request to the api inside a server action? Like don’t know
“use serverâ€
...
await axios.post(...)
...
And the second is about auth and layouts, if I want to build a dashboard and I want a user profile button in the layout how can I archive this because layout aren’t rendered between navigation...some code example will be appreciated
I want to know if for x reason iam building a nextjs app with a separated backend (I know this is not ideal) I can make post request to the api inside a server action? Like don’t know
“use serverâ€
...
await axios.post(...)
...
And the second is about auth and layouts, if I want to build a dashboard and I want a user profile button in the layout how can I archive this because layout aren’t rendered between navigation...some code example will be appreciated
4 Replies
If you need to re-render a layout on each navigation consider using the
See: https://nextjs.org/docs/app/api-reference/file-conventions/template
template.tsx
file convention. Whatever you return from a template will be rendered between your layout and page content and it will re-render on every navigation.See: https://nextjs.org/docs/app/api-reference/file-conventions/template
And yes, you can use server actions to perform any kind of fetch request. They are just asynchronous functions that run on the server and that can be invoked from your app/website.
See: https://nextjs.org/docs/app/building-your-application/data-fetching/server-actions-and-mutations
See: https://nextjs.org/docs/app/building-your-application/data-fetching/server-actions-and-mutations
Giant pandaOP
Wow thanks for your time,
Giant pandaOP
I think I can make route groups also and with a good distribution a could archive this (idea from a oss repo)