vercel / next-learn

Learn Next.js Starter Code
https://next-learn-dashboard.vercel.sh/
MIT License
3.8k stars 1.93k forks source link

Chapter 15 - Missing Step to Create app/api/auth/[...nextauth]/route.ts #904

Open jeffmatts opened 3 weeks ago

jeffmatts commented 3 weeks ago

Let me first just say that this tutorial is amazing! I didn't experience any issues until chapter 15.

After first typing, then later pasting the code examples, I was receiving the following error with login and logout:

[auth][error] InvalidCallbackUrl: Invalid callback URL. Received: http://localhost:3000dashboard

Also, redirects and auth guards were not working.

After looking at some other examples, I realized that 'app/api/auth/[...nextauth]/route.ts' was missing. So I added the example code from https://authjs.dev/getting-started/installation?framework=Next.js.

import { handlers } from '@/auth';
export const { GET, POST } = handlers;

Once I added this, the error went away, and redirects and auth guards were working.