I’ve tried following numerous tutorials for this, and it seems like something that should be very straightforward. However, I am consistently getting either invalid_request or redirect_uri_mismatch error responses whenever I attempt to authenticate my test user with Google.
app/api/auth/[…nextauth]/route.ts:
import NextAuth from "next-auth";
import GoogleProvider from "next-auth/providers/google";
const handler = NextAuth({
providers: [
GoogleProvider({
clientId: process.env.GOOGLE_CLIENT_ID!,
clientSecret: process.env.GOOGLE_CLIENT_SECRET!,
})
]
});
export { handler as GET, handler as POST }
I remember how much trouble I had getting this working. It was very frustrating. I know what you are going through. In the end, I was copy/pasting code samples I found online and eventually something worked. I think there was something in my AuthOptions. But honestly I don’t remember anymore. I feel ya bro … but I don’t have any specific ideas for you at the moment.
Yeah I’ve posted this same question to Reddit and SO… I’m about ready to give up and move on to another project. It doesn’t seem like this should be giving me as much trouble as it is. I even downloaded Mosh’s version of the project to see if there was something in my code that causing the problem, and I’m still getting the redirect_uri_mismatch error.
You might try starting over and running through Mosh’s Google setup video again. Failing that, try Github Oauth instead. Google’s setup is a complicated mess of non-intuitive menus. The set up for Github so much simpler than Google’s.
Fill in the required fields and click Register Application
Then you’ll be able to create your GIthub ID and Client secret values which you can then add to your env file using the GITHUB_ID and GITHUB_SECRET keys.
Also, don’t forget to add the provider to your authOptions:
Thank you man! Using github is much easiser! I have tried a lot of ways but they didn’t work!
Now I can study the next lesson. Thank you again, it’s really helpful