Skip to content

What does the following code mean "export { handler as GET, handler as POST }" in NEXT AUTH for NEXT JS 13 #58852

Answered by icyJoseph
kemaltf asked this question in Help
Discussion options

You must be logged in to vote

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 function body logic to serve both kinds of requests.

So you can create a function named, whatever, for example, handler and export it as GET and POST.

const handler = () => {/* function body */}

export { handler as GET, handler as POST }

People who consume this module, and mainly the Next.js server compiler, would b…

Replies: 1 comment 3 replies

Comment options

You must be logged in to vote
3 replies
@kemaltf
Comment options

@kemaltf
Comment options

@dimaboychev
Comment options

Answer selected by kemaltf
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Help
Labels
None yet
3 participants