Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
128 changes: 86 additions & 42 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,44 +1,88 @@
# SAWO React Sample App
# SAWO React
React is a free and open-source front-end JavaScript library for building user interfaces or UI components. It is maintained by Facebook. Several useful applications can be built through this library.
# 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 React 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](https://dev.sawolabs.com/)
4.Once you create your project, you would need to set your project name and hostname.
1. For development in a local machine, the hostname should be set to 'localhost'.
2. For production, the hostname should be set to your domain.
5.Copy the API key from the project and keep it safe and secure.
6.Initialize SAWO and render the form according to the following steps:
1. 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>

```
2. 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'
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) => {},
};

```
3. Then a SAWO instance has to be created using the code given below:
```
let sawo = new Sawo(config)

```
4. 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'
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: 300px;"></div>
</div>
)
}

export default LoginPage

```
8. Once the SAWO SDK is successfully set up, a login form will be rendered in the provided container

This project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app).

## Deployment

This is project has been hosted in [Netlify](https://sawo-react-sample-app.netlify.app/)

## Available Scripts

In the project directory, you can run:

### `npm start`

Runs the app in the development mode.\
Open [http://localhost:3000](http://localhost:3000) to view it in the browser.

The page will reload if you make edits.\
You will also see any lint errors in the console.

### `npm test`

Launches the test runner in the interactive watch mode.\
See the section about [running tests](https://facebook.github.io/create-react-app/docs/running-tests) for more information.

### `npm run build`

Builds the app for production to the `build` folder.\
It correctly bundles React in production mode and optimizes the build for the best performance.

The build is minified and the filenames include the hashes.\
Your app is ready to be deployed!

See the section about [deployment](https://facebook.github.io/create-react-app/docs/deployment) for more information.

### `npm run eject`

**Note: this is a one-way operation. Once you `eject`, you can’t go back!**

If you aren’t satisfied with the build tool and configuration choices, you can `eject` at any time. This command will remove the single build dependency from your project.

Instead, it will copy all the configuration files and the transitive dependencies (webpack, Babel, ESLint, etc) right into your project so you have full control over them. All of the commands except `eject` will still work, but they will point to the copied scripts so you can tweak them. At this point you’re on your own.

You don’t have to ever use `eject`. The curated feature set is suitable for small and middle deployments, and you shouldn’t feel obligated to use this feature. However we understand that this tool wouldn’t be useful if you couldn’t customize it when you are ready for it.