-
-
Notifications
You must be signed in to change notification settings - Fork 3.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Integration with an existing project #296
Comments
So I think I understand your situation, thanks for the explanation which seems clear. This error message is triggered when someone has an account (e.g. via email sign in, or sign in with an OAuth provider) but then tries to sign in with a DIFFERENT provider where they have specified the same email address on their account. It is quite common for sites to automatically link accounts in this scenario, but that is not secure and most authentication services don't do it - and NextAuth.js doesn't do it either. It is possible to link accounts securely, but you already need to be signed in to the account you want to link to. As well as being secure, this helps reduce instances of people accidentally creating two different accounts with the same service. So, this feature is working as intended, they should read the error message, and sign in with the same provider they used before (that is in the SolutionsThese are the options that are probably most relevant:
There are no one answer if you have an existing database of users, you'll need to decide what works best for you. NextAuth.js tries hard to to be opinionated about table structure, and provide a good base set of models that should work for a lot of people and try to stick to common conventions for each database (be that an SQL DB or a Document DB), so it's great if you are starting from scratch as it's sensible and easy to extend, but existing apps can be much more complex. If you have an existing database then Option 1 is probably a good choice for now and avoids a lot of work. You can always try migrating users over later if you decide you like NextAuth.js and it's worth re-considering how you store your user data in future. |
Thank you so much for the detailed response, you've given me a lot to think about in terms of how I've previously implemented OAuth as well as my database structure and security going forward. I think I'm going to try solution 1 and see how that works out for me, much appreciated! |
I'm glad I could help! We don't have any tutorials that show ways to use the callbacks yet - if you have any questions as to how best to approach this please do reach out. |
Hi, did you solve this? Can you show me how ? Thank you |
Anyone facing this issue and using mongodb to store users - check your 'user' and 'accounts' collections have the same number of fields. This is a bug caused when nextauth creates a new account field for an existing user. To fix it, find the account ID in 'accounts' collection that has no corresponding document in the 'users' collection and delete it. You can do this with an aggregate function in atlas for simplicity. |
I'm getting the same error message but it's a completely new project. I have no data in the database |
Did you guys have the implementation ? |
Problem happened after i delete some users from table Here how i fix
Account.tsx
|
I sort of experienced the same issue. I had two authentication providers set on NextAuth, one with Github and another a custom CAS provider. On my local development I created a new user on the CAS server in order to test things out. Mistakenly or not I used the name as the user of my Github account. Next time I tried to login, I got a message "To confirm your identity, sign in with the same account you used originally." Just to verify the same name was the issue,, I deleted the records on the User, Account, and Session tables pertaining to the new CAS user. Then I was able to login. Note: Deleting the records does not solve the problem, but I wanted to confirm that was the issue. |
Hi @ShivamMetricoid , Try to use allowDangerousEmailAccountLinking: true flag in Google Provider. |
Thanks @karan0805 for your prompt assistance, it works. |
Your question
Is it possible to to integrate next-auth with a project that already has users? When trying to login with an oauth provider as a user who's already registered in the database I get
which I assume is because there are no sessions in the database as that user but because I'm migrating an existing project, there are no existing sessions for any user. Is there a way to get this working or am I approaching it wrong?
I tweaked my existing
users
table to fit the expected model and addedaccounts
andsessions
tables, I'm not sure if that is the correct way to get it working for an existing project though.Documentation feedback
Documentation refers to searching through online documentation, code comments and issue history. The example project refers to next-auth-example.
The text was updated successfully, but these errors were encountered: