Login / Logout
Once a user has signed up, they can log in to your service using their email and password.
Login
Use the login()
method to log a user into your service.
If the login is not successful due to invalid password, or user may not have confirm their signup etc... the login()
method will throw an error.
When successful, it will respond with the UserProfile
object.
WARNING
If signup_confirmation
option was set to true
during signup()
, users will not be able to log in until they have confirmed their account.
INFO
When the user has successfully confirmed their signup and logged in, they will be sent a welcome email. You can also customize the email template for the signup confirmation email.
For more info on email templates, see Automated E-Mail.
Below is an example of a login form that uses the login()
method. When the user successfully logs in, they will be redirected to the welcome.html
page.
<form action='welcome.html' onsubmit="skapi.login(event).catch(err=>alert(err.message))">
<h2>Login</h2>
<hr>
<label>
Email<br>
<input type="email" name="email" placeholder="user@email.com" required>
</label><br><br>
<label>
Password<br>
<input id="password" type="password" name="password" placeholder="Your password" required>
</label><br><br>
<input type="submit" value="Login">
</form>
let parameters = {
email: 'user@email.com',
password: 'password'
}
skapi.login(parameters)
.then(user => window.href = 'welcome.html');
For more detailed information on all the parameters and options available with the login()
method, please refer to the API Reference below:
login(params): Promise<UserProfile>
Auto Login
By default, once user login to your website, their login session is maintained until they logout.
To ensure that users' sessions are destroyed when they leave your website, you can set options.autoLogin to false in the third argument when initializing Skapi.
const options = {
autoLogin: false, // set to true to maintain the user's session
};
//Set the third argument as options
const skapi = new Skapi('service_id', 'owner_id', options);
Logout
The logout()
method logs the user out from the service.
<form onsubmit='skapi.logout(event)' action='page_to_show_after_logout.html'>
<input type='submit' value='Logout'>
</form>
skapi.logout().then(res=>{
console.log(res); // 'SUCCESS: The user has been logged out.'
window.location.replace("page_to_show_after_logout.html");
});
Global Logout
You can let the users logout and invalidate all tokens across all the users devices by setting params.global
to true
.
<form onsubmit='skapi.logout(event)' action='page_to_show_after_logout.html'>
<input type='checkbox' name='global' checked>
<input type='submit' value='Logout'>
</form>
skapi.logout({global: true}).then(res=>{
console.log(res); // 'SUCCESS: The user has been logged out.'
window.location.replace("page_to_show_after_logout.html");
});
For more detailed information on all the parameters and options available with the logout()
method, please refer to the API Reference below: