nextauthjs / next-auth

Authentication for the Web.
https://authjs.dev
ISC License
24.25k stars 3.37k forks source link

Question: Use with serverless builds? #74

Closed alexpricedev closed 5 years ago

alexpricedev commented 5 years ago

Is it possible to use this with Now 2.0 and next with the target: 'serverless' builder? I've seen in the src that it boots up a new app (server) which I presume isn't ideal in a serverless paradigm? Thanks :)

agstover commented 5 years ago

The target: serverless builder only has to do with the NextJS app. This library mostly deals with building the back end express app which serves that NextJS app. The target: serverless just takes every page and turns it into a static file. So the real question I think is how to use this library with the new Lambda paradigm.

The source requires you to pass in an instantiated instance of Express which it then adds routes to. So I think technically you could use this w/Now V2 but you would have to do an entire server on a single Lambda which Zeit crew are saying is not great because of cold starts. I think if this library was to be re-written to work with the new serverless paradigm you'd have to have a library which would simply produce different handler functions for you to use.

So you would make your api/auth/callback.js file as part of your builds for example, and then in that file you could pull out `const {callback} = require('next-auth')(conifg) and then do expressApp.get('*', callback)

alexpricedev commented 5 years ago

Thanks for this! I'll close my ticket :)