Skip to content

1Byte-Software/dun-js

Repository files navigation

Getting started

Installation

Before you start, make sure you have a fresh version of Node.js installed. The current Long Term Support (LTS) release is an ideal starting point.

# Run this command in your project root folder.
# yarn
yarn add dun-js

# npm
npm install --save dun-js

Then you can simply import or require the module.

// ES module
import { AuthClient } from 'dun-js';
const authClient = new AuthClient(/* configOptions */);
// CommonJS
var AuthClient = require('dun-js').AuthClient;
var authClient = new AuthClient(/* configOptions */);

Usage guide

Example Client

const config = {
  mode: 'development',
  brandUrl: 'jframework.io',
};

const authClient = new AuthClient(config);

Usage with Typescript

Type definitions are provided implicitly through the types entry in package.json. Types can also be referenced explicitly by importing them.

import { AuthClient, DunConfig } from 'dun-js';

const config: DunConfig = {
  mode: 'development',
  brandUrl: 'jframework.io',
};

const authClient: AuthClient = new AuthClient(config);

Using API

You can easily utilize the API by importing it and then invoking its methods.

Example:

import { ISignInPayload, signInAPI } from 'dun-js';

const payload: ISignInPayload = {
  username: formValues.username,
  password: formValues.password,
};

const response = await signInAPI(payload);

Configuration reference

Configuration options

These options can be included when instantiating DUN Auth JS (new AuthClient(config)).

brandUrl

⚠️ This option is required

The url for your DUN brand.

mode

The default environment for your application is set to 'production'. To switch to a development environment, set the environment to 'development'.

Methods

setAuthKey()

Upon logging in, you will receive an authKey from the server. Use the following method to set the authKey in the request header.

Example:

authClient.setAuthKey(authKey);

setHeaders()

If you want to set headers for all APIs, use this method.

Example:

const userHeaders = {
  UrlRequest: window.location.href,
};

authClient.setHeaders(userHeaders);

API Reference

About

Package javascript for DUN Protocol

Resources

Stars

Watchers

Forks

Packages

No packages published