From the course: Next.js Ecommerce: Build a Shopping Platform from Scratch

Unlock this course with a free trial

Join today to access over 25,200 courses taught by industry experts.

NextAuth catch all API route

NextAuth catch all API route

All right, so when we use NextAuth, it sets up a bunch of hidden API routes for us to handle things like signing in, signing out, managing sessions. And these routes are automatically created when you configure NextAuth, and they're used behind the scenes to handle authentication. Now, we just have to create a single endpoint to basically hook those routes up. And when we do this, we're saying that any route that is slash API slash auth slash anything, then basically NextAuth just kind of takes over and does its thing. So it's very opinionated. We just set up all the configuration, which we did in the last video, and then NextAuth does everything behind the scenes. And what's great is you can add as many providers as you want, and they'll just work. So we need to create a new file. We're not using the pages directory. We're using the app directory. So we need app API auth and then brackets dot dot dot next auth. So the dots just means it's a catch-all route, so that if we go to auth…

Contents