NEXT
Next.js is an Open-Source Development Framework for building Server-side and Client-side rendered React applications, so that users can view and interact with.

Let's Get your NEXT App running with SAWO

Requirements

Node [Version 12.x+ ] , Node Package Manager (NPM) [Version 6.x+]

Steps

1. The first step to getting started with SAWO API integration into your NEXT web page is to install the sawo package as given below:
npm i sawo
2. After installation is done, you have to import the Sawo class from the installed sawo package to the top of the file:
import Sawo from "sawo"
3. To use SAWO Login you would need an API key which can be obtained by creating a project in the sawo dashboard.
4. Once you create your project, you would need to set your project name and hostname. 4.1. For development in a local machine, the hostname should be set to 'localhost'.
If using ''localhost" as hostname is not working for you, try "127.0.0.1"
🤓
4.2. For production, the hostname should be set to your domain.
If you are adding your domain do not add 'https://', ''http://', 'www' or even trailing backslash. Example: https://dev.sawolabs.com/ should be kept as dev.sawolabs.com
5. Copy the API key from the project and keep it safe and secure.
The best practice to store your API key is to store values in .env so that they are not exposed.
6. Initialize SAWO and render the form according to the following steps:
  • As part of this step, a container has to be created for the SAWO component. This has to be done on your project’s source file.
<div id="sawo-container" style={{height:"300px", width:"400px"}}></div>
Every added custom field should be accompanied by an65px increase in the component height.
  • Some configurations have to be checked as given below. The code given below should help in the same.
var config = {
// should be same as the id of the container created on 3rd step
containerID: "<container-ID>",
// can be one of 'email' or 'phone_number_sms' or 'both_email_phone'
identifierType: "phone_number_sms",
// Add the API key copied from 2nd step
apiKey: "",
// Add a callback here to handle the payload sent by sdk
onSuccess: (payload) => {},
};
  • Then a SAWO instance has to be created using the code given below:
let sawo = new Sawo(config)
  • The showForm method should be called thereafter as the showForm method is responsible for rendering the form in the given container.
sawo.showForm()
7. Below code-block can be used as a reference after you have completed setting up your project:
import React, { useEffect } from 'react'
import Sawo from 'sawo'
const LoginPage = () => {
useEffect(() => {
var config = {
// should be same as the id of the container created on 3rd step
containerID: '<container-ID>',
// can be one of 'email' or 'phone_number_sms' or 'both_email_phone'
identifierType: 'phone_number_sms',
// Add the API key copied from 5th step
apiKey: '',
// Add a callback here to handle the payload sent by sdk
onSuccess: payload => {
// you can use this payload for your purpose
},
}
let sawo = new Sawo(config)
sawo.showForm()
}, [])
return (
<div>
<div id="sawo-container" style={{height:"300px", width:"400px"}}></div>
</div>
)
}
export default LoginPage
8. Once the SAWO SDK is successfully set up, a login form will be rendered in the provided container as displayed in the picture below:
Final Render of SAWO SDK
User verification
Using custom POST-endpoint https://api.sawolabs.com/api/v1/userverify/ and with the following key-value pair as body:
{
"user_id": "a0aca1a0-7460-4e8e-8e46-3baf2c92423d",
"verification_token" : "ADdHrvkgi407qNfnAyrIVqokm3OWdKUCdj8y"
}
you can verify the incoming user. If the user is valid it would return a response code of 200 with the following payload:
{
"user_valid": true
}
For more go to the User Verification Page.
Congratulations !! The SAWO API is now ready to be used in your NEXT application 🤘.

You can also check out SAWO's
NEXT Sample Code and Deployed App.

It's okay, we get it! You got Stuck!
😞
Feel free to contact us on #ask-for-help on our Discord

Doc was created by Shreya.