Tutorial: Deleting accounts

Serverless Authentication Deleting accounts

The Webcom API provides with two commands to delete user's accounts. Both these commands act equally for all authentication methods on the currently authenticated user. Thus, if no user is currently authenticated, both these commands fail.

As these operations are particularly sensible, they can also fail if the current user has signed in for a too long time (the error code TOKEN_TOO_OLD is then returned). In other words, one can delete an identity or an account of only freshly signed in users. When deleting an identity or an account, one must therefore plan to force the user to explicitly re-authenticate if s/he has signed in for a too long time.

The first command deletes a single identity from a user account, namely the identity used by the user to authenticate, without deleting neither the account itself nor the other identities bound to it. It is therefore used to remove an identity from an account that binds several identities.

Warning: if the deleted identity is the last one associated with the user's account, then the account is also deleted. Otherwise, it would result in a "ghost" Webcom account with no authentication means.

The second command deletes the whole user account, namely the one of the currently authenticated user, together with all identities bound to it.

In order to delete the Webcom account of the identity of the currently signed in user, simply use the following snippet (replace “<your-app>” with your actual application identifier):

var ref = new Webcom("<your-app>");
// Authenticate a user
ref.authWith...(...);
// Delete the account of the authenticated user
ref.removeAccount()
    .then(() => console.log("Account deleted!"))
    .catch(error => {
        if (error.code === "TOKEN_TOO_OLD") {
            console.log("The user must re-authenticate before deleting her/his account");
        } else {
            console.log("Failed deleting the user account!");
        }
    });
// or delete only the signed in identity from the account
ref.removeIdentity()
    .then(() => console.log("Identity deleted!"))
    .catch(error => {
        if (error.code === "TOKEN_TOO_OLD") {
            console.log("The user must re-authenticate before deleting her/his identity");
        } else {
            console.log("Failed deleting the user identity!");
        }
    });

Coming soon!
In the meanwhile, refer to the Android API reference

Coming soon!
In the meanwhile, refer to the iOS API reference