Adding Email-Password Login to your Application
Protekt allows you to add email-password authentication to any application in an instant. This guide will help you configure email login in the Protekt dashboard and add email-password authentication in your application.
Prerequisites
Before proceeding, it's important to make sure you've done a few things first. These are:
- Sign-up for a free Protekt account and access the Protekt dashboard to create an application. Learn about our dashboard configuration from the configuration guide.
- Obtain your Client ID and Domain from the application settings.
- A basic understanding of your development stack (e.g., JavaScript, React.js, Vue.js, etc.) and installations of your tech stack dependencies.
1. Enable Email-Password Login in the Dashboard
Before integrating the email-password login in your application, enable it from the dashboard and specify the required details. To enable email login in the Protekt dashboard:
- Log in to the Protekt dashboard.
- Navigate to Authentication > Methods.
- Toggle the Email + Password button to enabled. Further instruction on password configuration will appear.
- Set the minimum length of the password according to your requirements.
- Set the password complexity by checking the required options. The available options are Must have a capital letter and Must have a special character.
- Click on More Password Settings to set the password reset rules.
- Set the number of days after which the user has to reset the password.
- Click Okay.
2. Configure the Email Templates
Protekt helps you in delivering system emails like welcome, verification, and password-reset emails. To configure such email templates:
- Go to Authentication > Email Settings.
- Use the Protekt-provided templates by default or customize your own template.
- To use the default templates:
- Select the template for each purpose according to your liking.
- To use a customized template:
- Apply the HTML, CSS, and JS code snippets as required in the respective fields.
- Click Apply.
- If you are using a custom email provider, ensure that the SMTP settings are verified by clicking on the SMTP Configuration collapsible. To do that:
- Enter the SMTP Host (e.g., smtp.gmail.com).
- Ensure the Port for the configuration (587 for TLS, 465 for SSL).
- Enter your Username (usually your email address).
- Enter the Password/App Password given for the email provider (or SMTP token from your provider).
- Specify the From Address (the email address from which the users will receive, e.g., noreply@yourapp.com).
- Click Save.
- Click Send Test Email to verify the applied settings.
- Enter your email address. Protekt will try to send an email to your email address.
- If you receive the email, the applied settings are verified
.
- Click Save Template.
Note: More details on the configuration of email templates can be found in Email Templates.
3. Integrate Email-Password Login in your Application
After verifying all of the above settings and configuration, it's time to integrate the email-password login into your application. Try out the methods below to integrate it through your preferred tech stacks.
-
Install the Protekt JS SDK
Protekt provides a JavaScript SDK to simplify the process of integrating Protekt authentication with your application. Install the SDK by executing the following command in your terminal.
-
Create the Protekt Client
Create a new Protekt client provided by the SDK and provide the Client ID and Domain that you obtained earlier. The following code snippet will help you do that:
-
Add Signup to your Application
After the client setup is done, you need to set up the signup mechanism for new users in your application. To do this, use the
auth.signupWithEmail()method to create a new user account with email and password. The following code block helps you do that. -
Add Login for Existing Users in your Application
Once the signup mechanism is added, the login mechanism needs to be added for the existing users in the application. Use the
auth.loginWithEmail()method to authenticate an existing user. The code snippet below will help you add that. -
Add SignOut to your Application
Finally, once the sign-up/login for a user is completed, it's time to put the sign-out mechanism in place, through which a user will sign out or log out from the application. The auth.logout() method will help in doing that. The following code snippets show how to use that method.
-
Install the Protekt React SDK
Protekt provides a React.js SDK to simplify the process of integrating Protekt authentication with your application. Install the SDK by executing the following command in your terminal.
-
Create the Protekt Client
Create a new Protekt client provided by the SDK and provide the Client ID and Domain that you obtained earlier. The following code snippet will help you do that:
-
Add Signup to your Application
After the client setup is done, you need to set up the signup mechanism for new users in your application. To do this, use the
auth.signupWithEmail()method to create a new user account with email and password. The following code block helps you do that. -
Add Login for Existing Users in your Application
Once the signup mechanism is added, the login mechanism needs to be added for the existing users in the application. Use the
auth.loginWithEmail()method to authenticate an existing user. The below code snippet will help you add that. -
Add Signout to your Application
Finally, once the sign-up/login for a user is completed, it's time to put the sign-out mechanism in place, through which a user will sign out or log out from the application. The auth.logout() method will help in doing that. The following code snippets show how to use that method.
-
Install the Protekt Angular SDK
Protekt provides a Angular.js SDK to simplify the process of integrating Protekt authentication with your application. Install the SDK by executing the following command in your terminal.
-
Create the Protekt Client
Create a new Protekt client provided by the SDK and provide the Client ID and Domain that you obtained earlier. The following code snippet will help you do that:
-
Add Signup in your Application
After the client setup is done, you need to set up the signup mechanism for new users in your application. To do this, use the
auth.signupWithEmail()method to create a new user account with email and password. The following code block helps you do that. -
Add Login for Existing Users in your Application
Once the signup mechanism is added, the login mechanism needs to be added for the existing users in the application. Use the
auth.loginWithEmail()method to authenticate an existing user. The below code snippet will help you add that. -
Add Signout to your Application
Finally, once the sign-up/login for a user is completed, it's time to put the sign-out mechanism in place, through which a user will sign out or log out from the application. The auth.logout() method will help in doing that. The following code snippets show how to use that method.
More integrations
For more detailed integration with different tech stacks, check out our integration guides.
Next Steps
Congratulations! You have made it this far. This means that you have successfully integrated the Protekt email-password authentication in your application. The journey doesn't end here.
To learn more about what you can do with Protekt, check out the below features and resources: