# Delete user if already exists

**URL:** <https://community.auth0.com/t/delete-user-if-already-exists/63822>\
**Category:** Get Help\
**Created:** [June 3, 2021, 3:16pm UTC](https://community.auth0.com/t/delete-user-if-already-exists/63822 "2021-06-03T15:16:19Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![francesco.venica](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/francesco.venica/32/13023_2.png) [@francesco.venica](https://community.auth0.com/u/francesco.venica)\
**Post date:** [June 3, 2021, 3:16pm UTC](https://community.auth0.com/t/delete-user-if-already-exists/63822/1 "2021-06-03T15:16:19Z")

</div>

Hello,

I’m working on an application where a user can invite another user to join the app, I’m able to invite him and verify the email without any problem, my issue is that if the user doesn’t accept the invitation and he try to login X days later (or even the same day) he get an error because the user already exists…My idea was to check if the user already exist in an hook or action and based on some value in the app\_metadata delete it just before create the new one…is it doable? are there any better way to achieve this?

many thanks  
Francesco

---

<div class="post-metadata">

**Author:** ![sgo](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/sgo/32/13789_2.png) [@sgo](https://community.auth0.com/u/sgo)\
**Post date:** [June 3, 2021, 4:45pm UTC](https://community.auth0.com/t/delete-user-if-already-exists/63822/2 "2021-06-03T16:45:18Z")

</div>

Hi @francesco.venica , if you want to do an invite flow I would recommend looking into the solution proposed here which utilises the password reset email to double up as an invitation email too:

> **[Send Email Invitations for Application Signup](https://auth0.com/docs/customize/email/send-email-invitations-for-application-signup)**
>
> Describes how to customize the signup process to invite users to signup for an account in the context of a specific Auth0 application.

This way the user could be created via the [Management API](https://auth0.com/docs/api/management/v2#!/Users/get_users), (e.g. your application could do a user search to check that the user existed or not, and if not, created the user), and then you can either [trigger the password reset email](https://auth0.com/docs/api/authentication#change-password), or alternatively create a [password reset ticket](https://auth0.com/docs/api/management/v2#!/Tickets/post_password_change) to send in a customised invitation email you send directly to the new user’s inbox.  
If you just trigger the password reset email, you will likely want to edit the template’s wording so it makes sense both as a password reset email and an invitation email to the end user.

---

<div class="post-metadata">

**Author:** ![francesco.venica](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/francesco.venica/32/13023_2.png) [@francesco.venica](https://community.auth0.com/u/francesco.venica)\
**Post date:** [June 4, 2021, 9:13am UTC](https://community.auth0.com/t/delete-user-if-already-exists/63822/3 "2021-06-04T09:13:19Z")

</div>

hi @sgo, the invitation flow is already in place and it is working fine, I’m using the password ticket to reset the password and validate the email. The issue is when the user decide to not accept the invitation.  
Example:

- John invite Alex
- Alex do not click on the invitation link
- The next day Alex try to register in the app without using the password reset link
- Alex get an error because the user already exits

my idea was (if possible) to delete the user (based on particular values in the app\_metadata) in a pre-register hook/action but I’m not 100% sure it is possible

Francesco

---

<div class="post-metadata">

**Author:** ![sgo](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/sgo/32/13789_2.png) [@sgo](https://community.auth0.com/u/sgo)\
**Post date:** [June 9, 2021, 8:17am UTC](https://community.auth0.com/t/delete-user-if-already-exists/63822/4 "2021-06-09T08:17:46Z")

</div>

I’m not sure if that would be possible as I don’t think they’d get as far as triggering the hooks, but if it did work it could also open up the possibility of a kind of account takeover/griefing if you have an automated deletion of existing accounts.

I would recommend either disabling sign-ups for the connection, so they couldn’t attempt to register themselves and get into the user already exists issue; you would have a backend process that actually created the user and then the invite gives them a link to reset the password so they can access it.

Or, allow sign ups and have your invite be a link to a page on your site that will automatically redirect the user to an /authorize request which is configured to show the sign-up page instead of the default login page.

Please see this community FAQ for how to take a user straight to the sign-up page instead of the login page:  
[https://community.auth0.com/t/how-do-i-redirect-users-directly-to-the-hosted-signup-page/42520](https://community.auth0.com/t/how-do-i-redirect-users-directly-to-the-hosted-signup-page/42520)

---

<div class="post-metadata">

**Author:** ![konrad.sopala](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/konrad.sopala/32/13516_2.png) [@konrad.sopala](https://community.auth0.com/u/konrad.sopala)\
**Post date:** [June 9, 2021, 11:44am UTC](https://community.auth0.com/t/delete-user-if-already-exists/63822/5 "2021-06-09T11:44:56Z")

</div>

Thanks for helping on this one Steve!

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/auth0/original/3X/b/5/b560f266932fcce5d57f09a6595bd50518cae3f3.jpeg) [@system](https://community.auth0.com/u/system)\
**Post date:** [June 24, 2021, 11:45am UTC](https://community.auth0.com/t/delete-user-if-already-exists/63822/6 "2021-06-24T11:45:00Z")

</div>

This topic was automatically closed 15 days after the last reply. New replies are no longer allowed.
