@socian/socian-auth-node-sdk
TypeScript icon, indicating that this package has built-in type declarations

1.8.0 • Public • Published

Socian Auth Server - SDK - Node

npm install npm run build

Installation

npm i @socian/socian-auth-node-sdk

or

yarn add @socian/socian-auth-node-sdk

Examples

// Sign In Example
import SocianAuthSDKClient from '@socian/socian-auth-node-sdk';

class MyClass {
	async runSignIn() {
		const authClientConfig = {
			"app_id": "socian-consumerbuzz-client_app_id_E3WDTFR77ZD7Q0J7",
			"app_secret": "socian-consumerbuzz-client_app_id_OMRHHVTAOD6A3EUG",
		}

		const authClient =   new SocianAuthSDKClient(authClientConfig)

		const credentials = {
			"email": "srhasan@socian.ai",
			"password": "password"
		}

		await authClient.signIn("credential", credentials)
		const authUser = await authClient.fetchUser()

		console.log('##### Socian Auth Server - SignIn Response #####')

		console.log({
			'intentId': authClient.getIntentId(),
			'intentObject': authClient.getIntentObject(),
			'loggedIn': authClient.getLoggedIn(),
			'authUser': authUser
		})

		if(authClient.getLoggedIn()){
			console.log("You are signed in - ", authUser?.name)
		}else{
			console.log("Sign In Failed - ", authUser?.name)
		}
	}
}

(new MyClass).runSignIn()
// Sign Up Example

import SocianAuthSDKClient from '@socian/socian-auth-node-sdk';

class MyClass {
	// ...
    
	async runSignUp() {
		try{
			const authClientConfig = {
				"app_id": "socian-consumerbuzz-client_app_id_E3WDTFR77ZD7Q0J7",
				"app_secret": "socian-consumerbuzz-client_app_id_OMRHHVTAOD6A3EUG",
			}

			const authClient =   new SocianAuthSDKClient(authClientConfig)

			const randomId = this.generateId(1, 500)
			const newUserFormData = {
				"name": `AUTH SDK USER - ${randomId}`,
				"email": `auth-skd-user-${randomId}@socian.ai`,
				"password": "password"
			}

			await authClient.signUp("credential", newUserFormData)
			const newUserData = authClient.getNewUser()

			console.log('##### Socian Auth Server - Sign Up Response #####')

			console.log({
				'intentId': authClient.getIntentId(),
				'authUserEmail': newUserData?.email,
				'newUserData': newUserData
			})

			if(authClient.getNewUser()){
				console.log("Your account has been created - ", newUserData?.name)
			}else{
				console.log("Sign Up Failed.")
			}
		}catch(error) {
			console.error('Sign up Error:')
			console.error(error)
		}
	}

	generateId(min, max) {
		return Math.floor(Math.random() * (max - min + 1)) + min;
	}
}

(new MyClass).runSignUp()

Readme

Keywords

none

Package Sidebar

Install

npm i @socian/socian-auth-node-sdk

Weekly Downloads

1

Version

1.8.0

License

ISC

Unpacked Size

16.3 kB

Total Files

19

Last publish

Collaborators

  • srhasan
  • tamzid
  • mustafa23
  • tanvirsourov