Next.js Discord

Discord Forum

package routes

Unanswered
Brambling posted this in #help-forum
Open in Discord
BramblingOP
Is thee a way to include routes in packages... i know i can do components but i want to have say a /login route that is provided by a auth library that i can reuse on multiple other apps?

10 Replies

@Brambling Is thee a way to include routes in packages... i know i can do components but i want to have say a /login route that is provided by a auth library that i can reuse on multiple other apps?
yea, you can use a component for that. For example a "LoginForm"-Component that serves this auth library stuff. If that does not suite your needs, you can still use an iframe. However: iframe, auth and cookies can be quite tricky
BramblingOP
but a component does not create the route /login and i need the login page because of needing two login buttons depending normal vs employee logins so two buttons.
and maybe i'm thinking about how to make a reusable auth library wrong.
also based on the answer maybe i am missunderstanding the concept of components
Asian black bear
Just do it like the previous version of next-auth did
import NextAuth from "next-auth"

const handler = NextAuth({
  ...
})

export { handler as GET, handler as POST }
In a similar fashion you can export a GET function and let consumers reexport it
Something like this
// app/foo/route.ts
export { GET } from 'my-library'
BramblingOP
so the think i guess i'm tring to avoid is the need to manually create the new route per app by creating the files and folders each time... maybe just having a scaffold setup script will solve this issue.
BramblingOP
but i guess i could use a postinstall setup script to automate that on install and that would do what i'm wanting i think...