next-auth icon indicating copy to clipboard operation
next-auth copied to clipboard

feat: add `isNewUser` arg on the signIn callback

Open kahveciderin opened this issue 2 years ago • 10 comments

This PR implements the isNewUser field on the signIn callback, to allow for the rejection of a potential sign up.

☕️ Reasoning

Sometimes we might want to reject the signIn event if the user doesn't already have an account.

🧢 Checklist

  • [x] Documentation
  • [ ] Tests
  • [x] Ready to be merged

🎫 Affected issues

Fixes #8272

kahveciderin avatar Sep 03 '23 00:09 kahveciderin

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
auth-docs ✅ Ready (Inspect) Visit Preview 💬 Add feedback Sep 3, 2023 10:02am
1 Ignored Deployment
Name Status Preview Comments Updated (UTC)
next-auth-docs ⬜️ Ignored (Inspect) Visit Preview Sep 3, 2023 10:02am

vercel[bot] avatar Sep 03 '23 00:09 vercel[bot]

@kahveciderin is attempting to deploy a commit to the authjs Team on Vercel.

A member of the Team first needs to authorize it.

vercel[bot] avatar Sep 03 '23 00:09 vercel[bot]

As far as I understand, the "Credentials" provider is intended to support use cases where one has an existing system one needs to authenticate users against, so a user cannot be a new user when using the Credentials provider, thus I've now added isNewUser: false to the signIn callback when signing in with the credentials provider to reflect that.

kahveciderin avatar Sep 03 '23 09:09 kahveciderin

I have exported the "input validation" lines to an external helper function, because the same thing with the callbackHandler was being validated in the new checkIfUserIsNew function. Also, I simplified the checkIfUserIsNew function's logic by first checking the email no matter what provider is used, and it checks if the account exists only after establishing that the email doesn't exist and the user is using oauth.

kahveciderin avatar Sep 03 '23 09:09 kahveciderin

I think I forgot to stage my last changes, will be pushing them now.

kahveciderin avatar Sep 03 '23 09:09 kahveciderin

This PR should now be ready to merge, would be happy to get some reviews.

kahveciderin avatar Sep 03 '23 10:09 kahveciderin

What's going on with this? Will it be merged?

april83c avatar Mar 17 '24 17:03 april83c

Please merge this work

bilalmohib avatar Apr 06 '24 07:04 bilalmohib

push

ehenoma avatar Jun 05 '24 09:06 ehenoma

merge when

siddharthd0 avatar Jul 07 '24 02:07 siddharthd0

Another bump here! Thanks

garshythoel avatar Nov 01 '24 19:11 garshythoel

It looks like this issue did not receive any activity for 60 days. It will be closed in 7 days if no further activity occurs. If you think your issue is still relevant, commenting will keep it open. Thanks!

stale[bot] avatar Jan 21 '25 23:01 stale[bot]

To keep things tidy, we are closing this issue for now. If you think your issue is still relevant, leave a comment and we might reopen it. Thanks!

stale[bot] avatar Feb 01 '25 00:02 stale[bot]