Angular
Angular is a TypeScript-based free and open-source web application framework. A component-based framework for building scalable web applications.

Let's Get your Angular 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 Angular 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. Initialise 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" style="height: 300px; width: 300px;"></div>
Copied!
Every added custom field should be accompanied by an 50px 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'
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
let 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
sawo.showForm()
Copied!
7. Below code-block can be used as a reference after you have completed setting up your project:
1
import { Component } from '@angular/core';
2
import Sawo from "sawo"
3
​
4
​
5
@Component({
6
selector: 'app-root',
7
templateUrl: './app.component.html',
8
styleUrls: ['./app.component.css']
9
})
10
​
11
export class AppComponent {
12
13
title = 'angular-sawo-chander';
14
Sawo: any;
15
isLoggedIn:any= false;
16
userPayload:any = {};
17
​
18
constructor() {}
19
​
20
ngOnInit(){
21
const sawoConfig = {
22
// should be same as the id of the container
23
containerID: "sawo-container",
24
// can be one of 'email' or 'phone_number_sms'
25
identifierType: "phone_number_sms",
26
// Add the API key
27
apiKey: "",
28
// Add a callback here to handle the payload sent by sdk
29
onSuccess: (payload: any) => {
30
this.userPayload = payload;
31
this.isLoggedIn = true;
32
}
33
};
34
// creating instance
35
this.Sawo = new Sawo(sawoConfig)
36
}
37
​
38
ngAfterViewInit() {
39
this.Sawo.showForm()
40
}
41
​
42
}
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 Login

Congratulations !! The SAWO API is now ready to be used in your Angular application 🀘.

You can also check out SAWO's Angular 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​

Last modified 1mo ago