-
SummaryHi, i just want to migrate to next JS 14, when i want to built an authentication i saw the documentation in Next Auth doc and found this https://next-auth.js.org/configuration/initialization#route-handlers-app
I don't understand the meaning of the export syntax like this Can help to explain or provide documentation for me to read? Additional informationNo response ExampleNo response |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
Hi, The new Route Handlers in App Router, use their function name to match a particular HTTP Request Method. Typically, you'd do: export const GET = () => {/* function body */}
export const POST = () => {/* function body */} And that'll setup to handlers, one for GET requests, and one for POST requests. However, some people, for whichever reason, might be able to use the same So you can create a function named, whatever, for example, const handler = () => {/* function body */}
export { handler as GET, handler as POST } People who consume this module, and mainly the Next.js server compiler, would be able to So, it is a syntax shorthand for: const handler = () => {/* function body */}
export const GET = handler;
export const POST = handler; You can also rename things as you import them, |
Beta Was this translation helpful? Give feedback.
Hi,
The new Route Handlers in App Router, use their function name to match a particular HTTP Request Method.
Typically, you'd do:
And that'll setup to handlers, one for GET requests, and one for POST requests.
However, some people, for whichever reason, might be able to use the same
function body
logic to serve both kinds of requests.So you can create a function named, whatever, for example,
handler
and export it asGET
andPOST
.People who consume this module, and mainly the Next.js server compiler, would b…