How recoil.js is managing in react?

Recoil js is another state management library for React.

Though we already have Redux. Mobx, Context, but here we got a new light entry in the community.

Why I am saying light you will figure it out at the end of this blog.

Why Recoil

  • Firstly, it solves the global state management problems.
  • Easy to learn; there are no new major principles n logic to learn.
  • Quite Simple, it is similar like react.
  • Though I like redux, but it will not take that much time to learn.

Recoil concepts

There are two major concepts:

  1. Atoms
  2. Selectors

Something new? Don’t worry will understand this quickly.

Atoms

This is similar to how we use the useState hook in react. If you are new to react hooks, checkout react hooks guide.

e.g.:

const [age, setAge] = useState(0);

age : this will be used for state variable declaration. setAge :this will be used for state variable updations.

1. Let’s start with binding root app with Recoil

Now you need to make a few alterations in your app’s root level, like the below snippet.

RecoilRoot will behave like a global context provider that will share the global state to your app tree.

Now update your older code snippet.

ReactDOM.render( <AppPage />, document.getElementById(“root”))

to

import { RecoilRoot } from “recoil”;

ReactDOM.render( 

 <RecoilRoot>

    <AppPage />

 </RecoilRoot>, document.getElementById(“root”))

2. Set the Atom

Recoil calls this part as atom, where we set the global key, value.

import { atom } from “recoil”;

const age = atom({

  key: “age”, 

  default: 0  // default global value for age key

});

Now this atom will be accessible throughout the app.

3. use the atom

Now update your older code snippet.

const [age, setAge] = useState(0);

to

import { useRecoilState } from ‘recoil’

const [ageState, setAge] = useRecoilState(age);

For a Larger view, here is Full Code

import { atom,useRecoilState } from ‘recoil’

const age = atom({

  key: “age”, 

  default: 0  // default global value for age key

});

export const AgeCalculator = () => {

const [ageState, setAge] = useRecoilState(age);

}

Quite easy. Isn’t it? Now let’s move to another part selectors

Read this blog post to learn in detail about selectors and how recoil.js is managing react.

Installing multiple node js version on the same machine

You may need a previous version of the nodejs while working on several projects, and others need a new version of nodejs, or to check the new NodeJs functionality, you need to instal the newest version of the nodejjs While working on several projects of NodeJs.

As on the same machine, we can only install one version of the nodejs, so it’s very painful to uninstall and install the new node version as per your project requirements.

To overcome this problem, we can use the Node Version Manager (NVM). NVM allows installing multiple node js versions on the same machine and switching between the required node js version.

Installation of NVM

Windows

Download the latest version of NVM

https://github.com/coreybutler/nvm-windows/releases/latest

Download nvm-setup.zip and install on the windows

Verify Installation

nvm version

MacOs/Linux

Using curl

curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.38.0/install.sh | bash

Using Wget

wget -qO- https://raw.githubusercontent.com/nvm-sh/nvm/v0.38.0/install.sh | bash

Verify Installation

command -v nvm

Usage

Get a List of all available NodeJs versions

nvm  ls available //windows

nvm ls-remote //MacOs/Linux

Install latest NodeJs version

nvm install node

Install latest LTS Release

nvm install –lts

Install particular NodeJs version

Multiple NodeJs version can be installed using the below command.

nvm install 8.11.1 // to install the 8.11.1 version

nvm install 12.13.1 //to install the 12.13.1 version

UnInstall the multiple NodeJs version

nvm uninstall 8.11.1

Read this blog to learn more about installing multiple nodejs versions on the same machine.

React User Authentication with LoginRadius: A Guide

To authenticate react applications, this guide uses LoginRadius API, which gives react developers a more straightforward way to add user authentication to react applications. To handle a lot of authentication implementation information, LoginRadius offers a high-level API. Using security best practices, you can now protect your respond apps while writing less code.

This article focuses on helping developers learn how to integrate user authentication in the React application. To practice the following security principles, you can improve a starter React application:

  • Add user login and user login.
  • User information retrieval.
  • Attach a tab for sign-up.

In the React application, we can easily and quickly add authentication by using LoginRadius. If you already have a customized login/registration page ready, then I’ll guide you to the next step of adding authentication in react apps.

Configure LoginRadius for React Application

A new application was created for you when you signed up for LoginRadius. Form here, you get some essential information.

  1. API Key How to get API Key?
  2. Sott Work with Sott

Add following LoginRadius JS library into your application

<script type=”text/javascript” src=”https://auth.lrcontent.com/v2/LoginRadiusV2.js”></script>

Add Authentication when you have customized Login Page

Add Login to your react application

We will use API framework to call LoginRadius APIs for authentication. Create new file LoginPage.js and add the following code.

   import  React, { useState } from  “react”;

    const  lrconfig = {

    apiKey:  “*************************”, //LoginRadius API key

    };

    const  loginradius = {};

    if (window.LoginRadiusV2) {

      loginradius = new  window.LoginRadiusV2(lrconfig);

      loginradius.api.init(lrconfig);

    }

    const  LoginButton = () => {

      const  loginButtonHandler = () => {

      loginradius.api.login({emailid:  emailValue,

      password:  passwordValue},

      (successResponse)=>{

      //Here you will get the access Token of 

      console.log(successResponse);

      },

      (errors) => {

      console.log(errors);

      });

      }

      const [emailValue, updateEmailValue] = useState(“”);

      const [passwordValue, updatePasswordValue] = useState(“”);

      return (

      <React.Fragment>

      <input  type=”text”  value={emailValue}  onChange={(e)=>{updateEmailValue(e.target.value)}}  placeholder={“email”}/>

      <input  type=”password”  value={passwordValue}  onChange={(e)=>{updatePasswordValue(e.target.value)}}  placeholder={“Password”}  />

      <button  onClick={() =>  loginButtonHandler()}>Log In</button>

      </React.Fragment>

      );

      };

      export  default  LoginButton;

In above code , you will see the lrConfig object which has apikey that you will get from LoginRadius account. After calling loginradius.api.login you will get the response in which you will get the access Token through which you can get the user profile.

You can read more in detail about adding logout and signup to your react application in this React User Authentication Guide.

Tips and Ideas for Testing Login Screen

A login screen is a web page or web/mobile device entry page that needs user identification and authentication, regularly done by entering a combination of user and password. For any system/application the login process is the most necessary function, because it gives access to or part of the entire website/appliance. Checking the login screen also requires full coverage.

Mentioned below are few tips that can be referred for testing the login screen of any system/application.

UI/UX:

  • Tab Order – Check if there is a logical order for using the tab key
  • Focus on Username field – Check if, while landing on the page, the cursor is at the username field
  • Use of enter key – Check if Login button is activated on selecting enter
  • Accessibility – Check if all the fields on the page are correctly identified and labeled
  • Look & Feel – Check if the page looks fine, and everything is aligned correctly.
  • Content – Check if the content of the page is up to the mark. Are there any typos in the labels, controls of the screen?
  • Links – Check if the page contains any existing links, and are these links still valid.
  • Responsiveness – Check the responsiveness of the login screen in multiple sizes of computer monitors.

Refer to this blog to learn more about Security Checks and Functionality of Testing a Login Screen.

All About Nginx In 10 Minutes

NGINX is a Web and application server with an open source that can help you create a quicker, more flexible, safer, and reliable service. It features load balancing, proxy reversal, filtering, HTTP and mail servers. Some advanced features such as high performance and safety make the facilities a precious asset.

Nginx HTTP server has a highly customizable and outstanding logging facility. Nginx writes the information in the different severity levels debug, info, notice, warn, error, alert, and emerg to the logs. By default, the Nginx access log is located at /var/log/nginx/access.log and the error log is located at /var/log/nginx/error.log. Nginx logs file default path depends on the operating system and installation. You can override the default settings and change the format of logged messages by editing the NGINX configuration file /etc/nginx/nginx.conf .

The Purpose of Access Log

The NGINX logs all client requests just after the request is processed in the access logs. In access logs, You will see the files are accessed, how NGINX responded to a request, which browser a client is using, client IP addresses, and more in this section. The information from the access log can be used to evaluate traffic and monitor site use over time. If a user is submitting any suspicious requests, we can monitor using the access logs, and it helps us identify the application security vulnerabilities.

The Purpose of Error Log

Whenever NGINX encounters any problems, it will log them in the error log. It might possible an error in the configuration file, NGINX is not starting or has unexpectedly stopped or NGINX encounters any problems or if any error is coming from the upstream connection or connection time etc. it will log them in the error log.

These issues are categorized as debug, info, notice, warn, error. The default error log level is error and it is works globally. By default error log is located at logs/error.log. The error log directive overrides the setting inherited from the higher levels and can be defined at the http, stream, server, and location levels.

Read this blog to know more in detail about how to configure NGINX access log. 

React with Ref

In this article, We will discuss the manipulation of DOM elements with Ref directly with React.

React Framework builds your components and abstracts your code away from manipulation within the DOM but still leaves the door open for developers to access it. Reason are few cases where it might be necessary. That’s why React provides an escape hatch know as refs.

Refs are a function that use to access the DOM from components. You only need to attach a ref to the element in your application to provide access to it from anywhere within your component without making use of props and all.

We can also use Refs to direct access to React elements and use callbacks with them.

We should only use refs when the required interaction cannot be achieved using state and props.

Use Refs

We can use refs to do anything that needs to be manipulated in the DOM. Some good cases like focus, test selection, media playback, triggering mandatory animations, or integration with the third-party DOM library.

Note: We should avoid using refs because it removes the purpose of using React. For example, If you want to show and hide a popup component. We should use a boolean prop for it instead of manipulating dom.

Creating Refs

We can use React.createRef()method to create Refs, and then we can attach to a Dom element via the ref attribute after that, we can access and modify that element through the ref.

class App extends React.Component {

  constructor(props) {  

    super(props);  

    this.myRef = React.createRef();

  }

  render() {

    return <div ref={this.myRef} />; 

  }

}

In above code, We created this.myRef in the constructor by calling React.createRef() method.

Then in the render method , we attached the returned value to ref of the div element, a reference to the node becomes accessible at the current attribute of the ref.

We should not use ref attribute on function components because they do not have instances.

React will assign the current property with Dom element when component mount and assign null to it when component unmount.

ref updates happen before componentDidMount or componentDidUpdate methods.

We can pass refs as props to the component. Example:

function MyCustomTextInput ({ myInputRef }) {  

  return <input ref={myInputRef} />;  

}

class App extends React.Component {  

  constructor(props) {  

    super(props);  

    this.myInputRef = React.createRef();  

  } 

  componentDidMount() {  

    this.myInputRef.current.focus();  

  }

  render() {  

    return <MyCustomTextInput inputRef={this.myInputRef} />;  

  }

}

In above code, App passed its ref as props to MyCustomTextInput component.

You can read more in detail about call back ref in this tutorial about React with Ref.

Implement Authentication in Angular 2+ application using LoginRadius CLI in 5 mins

Hello Guys!!!, today we will be implemented the authentication in the Angular 2+ application within 5 mins using LoginRadius.

Configuring LoginRadius

To implement authentication in the angular app first let’s start with registering in the Loginradius and creating the application using LoginRadius CLI.

LoginRadius CLI Setup

Mac or Linux

  • Install the tap via:
    $ brew tap loginradius/tap
  • Then, you can install LR CLI via:
    $ brew install lr

Other Platforms

After installing the CLI, you can register into the LoginRadius via the below command.

$ lr register

This command will open the Loginradius in the browser to register yourself and create the app.

alt_text

Once you successfully register you will be able to see the below message on the browser, you can close the tab and come back to the CLI.

You are Successfully Authenticated, Kindly Close this browser window and go back to CLI.

Get Your Application API Credentials

Once you login/register using the CLI, You can now run the lr get config command to get your API credentials.

alt_text

Configuring Callback URLs

A callback URL is a URL in your application where LoginRadius redirects the user after they have authenticated. The callback URL for your app must be added to your Application Configuration. If this field is not set, users will be unable to log in to the application and get an error.

alt_text

To get the list of whitelisted domains, you can run lr get domain command from the cmd prompt. And to add a domain in the list using lr add domain command.

If you are following this tutorial, you should set the http://localhost as a whitelisted domain. Check the below image for how to add the domain using LoginRadius CLI.

alt_text

You can read more in detail about implementing authentication in Angular 2+ in this tutorial

How Git Local Repository Works

Let’s understand how git sets up a local repository Once we initialize or clone any git project that will set up a local project environment.

that whole environment will look like the below picture

git-local-environment

Project Folder: The main folder consists of a workspace and local repository

Work Directory: Inside Project Folder where we actually work,  we keep all files and perform many operations like addition, update, deletion of files

Local Repository: Here we don’t actually change anything, this is handled automatically by git. this consists staging area, commit history, stash area etc.

Let’s get into it step by step and see how we perform command or action and behind the scene, git do its own activity.

Step 1. Git clone and project:

3
4

Step 2. Explore what we got in repository

5
6

Step 3. Do some modification in a files

7
8

Step 4. Add this file in to staging (ready for commit)

9
10

Step 5. Commit the file

11
12

Step 6. Push the changes

13
14

Hope this makes clear how git handles things at the local repository.You can read more in detail about Git Local Repository in this article

Adding SSO To WordPress Site

Single sign-on (SSO) is a session and user authentication service that allows a user to access several applications with a collection of log-in credentials – such as a name and a password. To simplify the management of diverse usernames and passwords SSO can be used by companies, smaller organisations and individuals.

In a fundamental web service SSO the user authenticates a particular authentication certificate from a dedicated SSO policy server for a user on the application server. The user authenticates a user’s repository, for example, with a Lightweight Directory Access Protocol (LDAP) directory. For all user applications, the service authenticates the end user for all the applications the user has been given rights to and eliminates future password prompts for individual applications during the same session.

SSO for LoginRadius

Adding SSO to your existing web properties can be a challenge. LoginRadius WordPress Plugin is an out-of-box solution that replaces the WordPress default login form with the LoginRadius JS forms.

With minimal time and effort, you can add SSO to your existing sites leveraging LoginRadius WordPress Plugin and gain access to login data via our dashboard. This will help you to boost conversion and also reduce the time to onboard consumers.

We have detailed documentation on How to setup Login, Authentication and SSO for your WordPress site. You can also find this plugin on the wordpress marketplace.

You can read more in detail about installing SSO to your wordpress site in this article

Best Practices To Deliver Quality Software

QA Testing Process: How to Deliver Quality Software

As a quality analyst, we are responsible for running system test cycles and pushing releases every two weeks, to ensure that the system is updated to the latest patches and that everything on the live platform is free from error. Each release typically involves both amendments and corrections. In general, the team has 8-10 resources, like the developer and QA team, if we talk about resources.

Therefore, we should always be proactive about every release and avoid any stress during the release. Everything has to be managed properly when it comes to execution from the development end or testing from the QA end. For that purpose, we have to follow proper strategies to ensure that everything is getting tested and the release we approve meets the expected quality standards.

Break away from the conventional roles and obligations of QA

In two cases, we penetrated boundaries. Today, we are a unit confronting customers, because we are directly familiar with our customers with their problems, the problems they encounter with the programme or the highlights on the stage. In addition, we participate actively in the design discussions and/or any feedback that we get from the customers from our goal, to ensure that the customer’s vision takes us to the right direction. Our testing experience often helps to identify defects before performing any coding tasks, reducing additional time and reducing work. Thus, we can guarantee that all is done on the basis of the customer timeline and a quality outcome.

Read in detail about how to plan according to priorities and ensure the optimum environment for testing in this article about QA Testing Process