I’m working on one of the final exercises of the auth section of the Next.js course and having difficulty adding Github as an Oauth provider. Before I attempt to login I ensure that I go to Github and logout. I also clear all cookies on the next app site. After clicking “sign in in with github” I’m redirected to Gitub login page where I provide my credentials and 2FA code as usual. Afterwards I get redirected back to the the app login page where I see this error: “To confirm your identity, sign in with the same account you used originally.”
When I go back to github.com I’m logged in as expected, so the auth is working - just not the redirect.
I’ve gone through the process of adding a new Oauth app on Github (https://github.com/settings/developers), which gave me the client ID and client secret keys. My Github app settings are in the image above.
I then added GITHUB_ID and GITHUB_SECRET keys to .env and used them in /api/auth/[...nextauth]/route.ts:
I’ve also added another new email address to my github account and gave it login permission, but no dice. I’ve tried in an Incognito window and had same issue. Next server restart didn’t help either. Any ideas?
After a night’s sleep it occurred to me that the database entry made by next-auth after my first Google login might be blocking other logins. Now that I re-read the error message that seems obvious, but I didn’t think of that last night.
First I tested by trying to log in with a different Google account and, sure enough: same error. So I deleted all entries from the Account and User tables and tried logging in with Github again and - success.
It seems that, even though I was logging in to Github using a different email address, Oauth was sending my primary address, which was the same as the email address associated with the Google account that I logged in with initially.
I tried the same method as you did but It didn’t work in my case, Its still showing the same error when I tried to Sign-in using Google Auth and GitHub Auth. Also, When I try to Sign-in using Google or Github auth It just creates a entry in the mongodb database’s user table but nothing is created in the accounts table. If you find any other solution to this plaease inform here, It would be very helpful.
I’m not sure if it’ll work, but have you tried clearing the cookies and other storage for the page? Maybe there’s an old JSON web token stored in the browser.
Failing that…I used MySQL (instead of Mongo) when doing this lesson, so perhaps there’s a difference between how those two DBs store the auth info that’s causing the issue? As a test you might try completely deleting and then re initializing the database to see if that solves the problem.
Maybe do a mongodump first so you can restore it after testing, in case you have a lot of data you want to save.
Thanks so much for post on here! I was banging my head on my desk because i was so confused on why i was getting that same error … but i forgot that it’s the DB constraints we put that wouldn’t allow to have the same email. I did what you suggested, and it worked perfectly!