Disable / Recover Account
Disabling account
WARNING
User must be logged in to call this method
WARNING
If your service does not allow users to signup, the users will not be able to disable their account.
For more information on how to allow/disallow users to signup from your service settings page, please refer to the Service Settings page.
If user choose to leave your service, they can disable their account. User's can disable their account by calling the disableAccount()
method. All data related to the account will be deleted after 90 days. User will be automatically logged out once their account has been disabled.
skapi.disableAccount().then(()=>{
// Account is disabled and user is logged out.
});
For more detailed information on all the parameters and options available with the disableAccount()
method, please refer to the API Reference below:
disableAccount(): Promise(string)
Recovering a Disabled Account
Disabled accounts can be reactivated within 90 days using the recoverAccount()
method. This method allows users to reactivate their disabled accounts under the following conditions:
- The account email must be verified.
- The
recoverAccount()
method must be called from thecatch
block of a failedlogin()
attempt using the disabled account.
The recoverAccount()
method sends an email to the account owner, containing a confirmation link (The same signup confirmation email) for account recovery.
Additionally, you can provide an optional string
argument to the recoverAccount()
method, which will redirect the user to the specified URL or relative path of your website upon successful account recovery.
<form onsubmit="skapi.login(event)
.then(u=>console.log('Login success.'))
.catch(err=>{
console.log(err.code); // USER_IS_DISABLED
if(err.code === 'USER_IS_DISABLED') {
// Send a recovery email to the user with a link.
// When the user click on the link, the user will be redirected when account recovery is successful.
let recover = confirm('Do you want to recover your account?')
if(recover) {
skapi.recoverAccount('/welcome/back/page').then(res=>{
console.log(res); // SUCCESS: Recovery e-mail has been sent.
});
}
}
)">
<input type="email" name="email" placeholder="E-Mail" required><br>
<input id="password" type="password" name="password" placeholder="Password" required><br>
<input type="submit" value="Login">
</form>
// user attempt to login
skapi.login({email: 'user@email.com', password: 'password'})
.then(u=>console.log('Login success.'))
.catch(err=>{
console.log(err.code); // USER_IS_DISABLED
if(err.code === 'USER_IS_DISABLED') {
// Send a recovery email to the user with a link.
// When the user click on the link, the user will be redirected when account recovery is successful.
let recover = window.confirm('Do you want to recover your account?')
if(recover) {
skapi.recoverAccount("/welcome/back/page").then(res=>{
console.log(res); // SUCCESS: Recovery e-mail has been sent.
});
}
}
});
In the example above, the recoverAccount()
method is called from the catch block of a failed login attempt using a disabled account.
If the login attempt fails with the error code "USER_IS_DISABLED"
, user can choose to recover their account.
The recoverAccount()
method is called to send a recovery email to the user. The recovery email contains a link, and when the user clicks on the link, they will be redirected to the relative path of the website URL: /welcome/back/page
upon successful account recovery.
For more detailed information on all the parameters and options available with the recoverAccount()
method, please refer to the API Reference below:
recoverAccount(redirect: boolean | string): Promise<string>
DANGER
User should know their password, and have their account email verified. Otherwise user's account cannot be recovered.