Using Server Actions to sign up, log in, and create new posts
So far, we have only been fetching data from the database on the server and sending it to the client, but for user interactivity, we need to be able to send data back from the client to the server. To be able to do this, React introduced a pattern called Server Actions.
Server Actions are functions that are executed on the server side but can be triggered from the client side, for example, through a form submission. This can be done even with JavaScript disabled on the client, which will then submit the form using regular form submission. When JavaScript is enabled, the form will be progressively enhanced and not require a full refresh to submit. These functions are defined by tagging regular JavaScript functions with the "use server"
directive, and then either importing them into a client component or passing them to a client component via props. While regular JavaScript functions cannot be passed to client...