0

I'm doing the first step into Nextjs and I'm stacked in defining the authentication part. I understand that Nextjs tipically rely on NextAuth for authentication. My first thogth was to enable provider like google but I don't understand how to avoid new user registration. The application I'm thinking need to have a login to protect routes but not the registration part. Basically I need to decide on my own who can access.

In realty I started working on an express backend that rely on session cookie and MongoDb (no jwt involved) but now I'm a bit confused on how to proceed.

Is there a way to avoid registering new user with providers? What is your suggestions?

Many thanks

6
  • Have you tried passport.js ?
    – hurricane
    Commented Mar 29, 2022 at 17:31
  • No, in realty I spent few time reading over NextAuth. Never used Passport. May I ask you what is the benefit in using Passport?
    – b81
    Commented Mar 29, 2022 at 17:44
  • You don't need to build everything from start. It also has different providers like google, facebook etc.
    – hurricane
    Commented Mar 29, 2022 at 18:06
  • Okcthanks. I'll give it try
    – b81
    Commented Mar 29, 2022 at 18:16
  • Can you elaborate on why you would want to avoid new user registration? Commented Jun 28, 2022 at 9:41

1 Answer 1

2

Authentication in a Nextjs application is just like any another react application. Although NextAuth is great, but you don't have to rely on it if you don't want to.

Picture a Nextjs app like a basic react application. Same goes for authentication. Nothing specific to Nextjs in this one.

You can keep auth related data in cookies/headers and write a middleware, use it getServerSideProps call for all the pages you want to protect, to redirect the user to login page if the session has expired/or is invalid.

You can create custom integrations with identity platforms which would allow you to have an option to whether or not create an account for a user once you have received the data from the particular identity platform.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.