NUXT
Nuxt.js is a free and open source JavaScript library based on Vue.js, Node.js, Webpack and Babel.js. Nuxt is inspired by Next.js, which is a framework of similar purpose, based on React.js.

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:
1
npm i sawo
Copied!
2. After installation is done, you have to import the Sawo class from the installed sawo package to the top of the file:
1
import Sawo from "sawo"
Copied!
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.
1
<div id="sawo-container"></div>
2
<style>
3
#sawo-container {
4
width: 400px;
5
height: 400px;
6
}
7
</style>
Copied!
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.
1
var config = {
2
// should be same as the id of the container created on 3rd step
3
containerID: "<container-ID>",
4
// can be one of 'email' or 'phone_number_sms' or 'both_email_phone'
5
identifierType: "phone_number_sms",
6
// Add the API key copied from 2nd step
7
apiKey: "",
8
// Add a callback here to handle the payload sent by sdk
9
onSuccess: (payload) => {},
10
};
Copied!
  • Then a SAWO instance has to be created using the code given below:
1
this.Sawo = new Sawo(config)
Copied!
  • The showForm method should be called thereafter as the showForm method is responsible for rendering the form in the given container.
1
this.Sawo.showForm()
Copied!
7. Below code-block can be used as a reference after you have completed setting up your project:
1
<template>
2
<div class="containerStyle">
3
<section>
4
<div id="sawo-container"></div>
5
</section>
6
</div>
7
</template>
8
9
<script>
10
import Sawo from 'sawo'
11
export default {
12
name: 'Sawo',
13
mounted() {
14
const config = {
15
// should be same as the id of the container
16
containerID: 'sawo-container',
17
// can be one of 'email' or 'phone_number_sms'
18
identifierType: 'email',
19
// Add the API key
20
apiKey: API_KEY,
21
// Add a callback here to handle the payload sent by sdk
22
onSuccess: (payload) => {
23
},
24
}
25
this.Sawo = new Sawo(config)
26
this.Sawo.showForm()
27
},
28
}
29
</script>
30
31
<style>
32
#sawo-container {
33
width: 400px;
34
height: 400px;
35
}
36
</style>
Copied!
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:
1
{
2
"user_id": "a0aca1a0-7460-4e8e-8e46-3baf2c92423d",
3
"verification_token" : "ADdHrvkgi407qNfnAyrIVqokm3OWdKUCdj8y"
4
}
Copied!
you can verify the incoming user. If the user is valid it would return a response code of 200 with the following payload:
1
{
2
"user_valid": true
3
}
Copied!
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
NUXT 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 Divya Sri Darimisetti