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 - Next.js Tutorial
From the course: Next.js Ecommerce: Build a Shopping Platform from Scratch
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…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
Contents
-
-
-
-
-
(Locked)
Section intro2m 57s
-
(Locked)
Prisma user-related models9m 45s
-
(Locked)
Seed user data7m
-
(Locked)
NextAuth setup17m 31s
-
(Locked)
NextAuth catch all API route4m 12s
-
(Locked)
Sign-in and sign-out server actions8m 27s
-
(Locked)
Auth layout and sign-in page6m 58s
-
(Locked)
Credentials sign-in form6m 39s
-
(Locked)
Hook up sign-in form9m 28s
-
(Locked)
Callback URL redirect4m 26s
-
(Locked)
User button and sign-out11m 48s
-
(Locked)
Signup Zod schema and action8m 15s
-
(Locked)
Sign-up page and form7m 35s
-
(Locked)
Sign-up error handling12m 40s
-
(Locked)
Customize token with JWT callback8m 19s
-
(Locked)
-
-
-
-
-
-
-
-
-
-
-
-
-