Issue with Metamask authentication When Manually Deleting Users

When trying to sign in from metamask (I started recently having an issue). When I sign in with metamask email is stored as empty for the user.

Error logs

2021-06-05T08:02:56.123Z - Error: Account already exists for this email address.
    at /moralis-server/lib/RestWrite.js:1442:17
    at runMicrotasks (<anonymous>)
    at processTicksAndRejections (internal/process/task_queues.js:95:5)

Server Url

https://svzayzygttuw.moralis.io:2053/server

I can also see this error in the console when in the Moralis dashboard

Access to XMLHttpRequest at 'https://svzayzygttuw.moralis.io:2053/server/schemas' 
from origin 'https://svzayzygttuw.moralis.io:2083' has been blocked by 
CORS policy: No 'Access-Control-Allow-Origin' header is present on 
the requested resource.
1 Like

You are trying to register a new user or this is when you try to login to an existing user?

Even with my User collection empty this happens. Even where there is an error it will create a user in the collection.

If I try to ā€œauthenticateā€ (from react-moralis authenticate function) it will keep throwing error, in the UI the user will still be isAuthenticated = false but I will have more ā€œUserā€ records in the collection

try with new server and tell us if it works
react-moralis is not really production ready, please let us know also if vanilla JS works or not

I managed to replicate the issue.

If you manually delete a ā€œUserā€ and donā€™t delete the user data in "Session, ā€œEthBalanceā€, ā€œ_EthAddressā€ it will fail the next time you try to sign in.

You need to do full cleanup of user data.

Ideally to fix the issue there would be a built in ā€œcascadeā€ mechanism when deleting users.

2 Likes

okok perfect thanks for investingating, we will fix this

@gianksp do all users stop working or only the specific user you manually remove?

Seems to be contained for the user deleted only.

1 Like

ah okok
in that case I donā€™t think we will do anything at this moment
instead of manually deleting a developer can delete via code and then afterDelete trigger will fire where developer can script delete logic

Maybe in the future we will find a better solution, for now we will just add to docs to delete Session and EthAddress if deleting manually

Great! I also think a good solution requires a bit of thought first and is not a blocker for the success of the platform. It will be enough with this topic resolved for future references.

1 Like

Added a note the Crypto Login docs about manually deleting users

https://docs.moralis.io/moralis-sdk/crypto-login#manually-deleting-users

4 Likes

Thanks a lot ! I ran into the same issue and your solution worked for me too! It took me quite a while though to find your post :slight_smile:

1 Like