Authing DocsDocuments
Concept
workflow
Guides
Development Integration
Application integration
Concept
workflow
Guides
Development Integration
Application integration
Old Version
Development Integration
  • Single Sign-On (SSO)
  • Login component

    • React
    • Vue
    • Angular
    • Native JavaScript
    • Complete parameter list
  • JavaScript/Node.js

  • Java / Kotlin

  • Python

  • C#

  • PHP

  • Go

  • Ruby
  • Android

  • iOS

  • Flutter

  • React Native
  • WeChat Mini Program
  • WeChat webpage authorization
  • Framework Integration
  • Error code
  1. Development Integration
  2. /
  3. Login component
  4. /
  5. Native JavaScript

¶ Native JavaScript Login Component

Update Time: 2025-02-18 09:00:47
Edit

The Authing login component (Guard) is an embeddable login form that can be configured according to your needs and is recommended for single-page applications. It allows you to easily add various social login methods so that your users can log in seamlessly and have a consistent login experience on different platforms. Guard shields many implementation details of low-level authentication for developers, as well as cumbersome UI development.

Guard can be integrated into your Native JavaScript project. You can use this component to quickly implement the login authentication process.

¶ Quick start

¶ Installation

$ yarn add @authing/native-js-ui-components

# OR

$ npm install @authing/native-js-ui-components --save

¶ Initialization

Initialize in the native JavaScript project:

import { authingGuard } from "@authing/native-js-ui-components";
// import css file
import "@authing/native-js-ui-components/lib/index.min.css";

const guard = new authingGuard("AUTHING_APP_ID");

// Event monitoring
guard.on("load", authClient => console.log(authClient));
How to initialize in an HTML file?

¶ Import by CDN

<!-- JavaScript -->
<script src="https://cdn.jsdelivr.net/npm/@authing/native-js-ui-components"></script>

<!-- CSS -->
<link href="https://cdn.jsdelivr.net/npm/@authing/native-js-ui-components/lib/index.min.css" rel="stylesheet"></link>

¶ Initialize in Script code block

<script>
  var guard = new authingNativeJsUIComponents.authingGuard("AUTHING_APP_ID");

  // Event monitoring
  guard.on("load", authClient => console.log(authClient));
</script>

¶ Monitor login events

You can monitor login events through guard.on("login", callback):

guard.on("login", user => {
  console.log(user);
});
What should we do after understanding user information?

After obtaining the user information, you can get the user's identity credential (the token field ), which you can carry in subsequent requests sent by the client to the backend server token, for axios example :

const axios = require("axios");
axios
  .get({
    url: "https://yourdomain.com/api/v1/your/resources",
    headers: {
      Authorization: "Bearer ID_TOKEN"
    }
  })
  .then(res => {
    // custom codes
  });

The legitimacy of this needs to be checked in the back-end interface to verify the user's identity. For details of the verification method, see Verifying User Identity Credentials (token) . After identifying the user's identity, you may also need to perform permission management on the user to determine whether the user has permission to operate this API.

¶ Add social login

Pass in the socialConnections list in the initialization parameter config to specify the social logins that need to be displayed(all social logins configured by the applicationare displayed by default).

<script>
  var guard = new authingNativeJsUIComponents.authingGuard("AUTHING_APP_ID", {
    socialConnections: ["github"]
  });
</script>
View the list of supported social logins and access procedures

Authing currently supports 4 social logins around the world, such as GitHub, Apple, etc. The following is a complete list:

Social Identity ProviderScenesDocs
WeChat QR Code on PCWebDocumentation
WeChat MobileMobile AppDocumentation
WeChat Web PageWechat BrowserDocumentation
Wechat Official Accounts QR CodeWebDocumentation
Mini ProgramMini ProgramDocumentation
Mini Program QR Code on PCWebDocumentation
Pull-up Mini Program on AppMobile AppDocumentation
QQWebDocumentation
WeiboWebDocumentation
GitHubWebDocumentation
FacebookWebDocumentation
TwitterWebDocumentation
GoogleWebDocumentation
Apple (Web)WebDocumentation
Apple (Mobile)Mobile AppDocumentation
AlipayMobile AppDocumentation
SlackWebDocumentation
GiteeWebDocumentation
GitLabWebDocumentation
BaiduWebDocumentation
LinkedInWebDocumentation
NetEase YIDUNMobile AppDocumentation
QingCloudWebDocumentation
InstagramWebDocumentation

¶ Implement single sign-on

To use Guard for single sign-on, you need to set isSSO to true during initialization.

<script>
  var guard = new authingNativeJsUIComponents.authingGuard("AUTHING_APP_ID", {
    isSSO: true
  });
</script>

¶ Instance method

The Guard instance provides three methods:

Method nameMethod parametersFunction
on

evtName:Event name,Please check theevent list

Handler:Corresponding event processing function

Monitor an event
show-Display the form in modal mode
hide-Hide the form in modal mode

¶ Complete parameter

The Authing login component (Guard) provides many advanced configurations, such as customizing the UI and using specific login methods. See the complete parameter list.

¶ Event list

Event name

Event Introduction

Event parameter

Event parameter introduction

load

Authing appId authenticate success,loading complete

authClient

AuthenticationClient object,can directly operate login, register,details in authing-js-sdk

load-error

Authing appId authenticate failed,loading failed

error

Error information

login

User login success

user, authClient

user: user information authClient same as before

login-error

User login failed

error

Error information,including information such as missing/illegal fields or server errors

register

User login success

user, authClient

user: user information authClient same as before

register-error

User login failed

error

Error information,including information such as missing/illegal fields or server errors

pwd-email-send

Forgot password email sending success

-

-

pwd-email-send-error

Forgot password email sending failed

error

Error information

pwd-phone-send

Forgot password mobile verification code sending success

-

-

pwd-phone-send-error

Forgot password mobile verification code sending failed

error

Error information

pwd-reset

Reset password success

-

-

pwd-reset-error

Reset password failed

error

Error information

close

guard close event in modal mode

-

-

login-tab-change

Login tab switching event

activeTab

Tab after switching

register-tab-change

Register tab switching event

activeTab

Tab after switching

register-tab-change

Register tab switching event

activeTab

Tab after switching

register-info-completed

Register Supplemental Success Event

user, udfs, authClient

user: user information udfs: Supplementary custom field information

authClient same as before

register-info-completed-error

Register Supplemental Failure Event

error, udfs, authClient

error: error information udfs: Supplementary custom field information

authClient same as before

¶ Privatization deployment

The privatization deploymentscenario needs to specify the GraphQL endpoint of your privatized Authing service(without protocol header and Path).If you are not sure, you can contact the Authing IDaaS service administrator.

<script>
  var guard = new authingNativeJsUIComponents.authingGuard("AUTHING_APP_ID", {
    apiHost: "https://core.you-authing-service.com"
  });
</script>

¶ Online experience


¶ Get help

Join us on forum: #authing-chat (opens new window)

Prev: Angular Next: Complete parameter list
  • Quick start
  • Instance method
  • Complete parameter
  • Event list
  • Privatization deployment
  • Online experience
  • Get help

User identity management

Integrated third-party login
Mobile phone number flash check (opens new window)
Universal login form component
Custom authentication process

Enterprise internal management

Single Sign On
Multi-factor Authentication
Authority Management

Developers

Development Document
Framework Integration
Blog (opens new window)
GitHub (opens new window)
Community User Center (opens new window)

Company

400 888 2106
sales@authing.cn
16 / F, Block B, NORTH STAR CENTURY CENTER, Beijing(Total)
room 406, 4th floor, zone B, building 1, No. 200, Tianfu Fifth Street, Chengdu(branch)

Beijing ICP No.19051205-1

© Beijing Steamory Technology Co.