@authguard.io/js-sdk
v0.4.0
Published
JS-SDK with clients for the use of authguard.io
Downloads
4
Readme
Authguard.io JS SDK
Set up your authguard.io app
Visit www.authguard.io and create an account. After successfully signing up, you can create your first app and start setting up your application
Create api token
Go to your administration area and create an Api token. This token is required for the communication between your application and your authguard.io app.
Installation
npm i @authguard.io/js-sdk
Getting started
Initialise Client
import { Client, createClient } from '@authguard.io/js-sdk'
const client = new Client(`testurl.authguard.app`, `api-token`)
// OR
const client = createClient(`testurl.authguard.app`, `api-token`)
Signup
Link
const response = await client.signupWithLink({
firstname: 'John',
lastname: 'Doe',
email: '[email protected]'
})
Password
const response = await client.signupWithPassword({
firstname: 'John',
lastname: 'Doe',
email: '[email protected]',
password: 'Pass123!'
})
Signin
Link
const response = await client.signinWithLink({
email: '[email protected]'
})
Verify email for sigin by link
const response = await client.signinVerify(
'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiI5YmIyYzA3NS1iYjMxLTRjN2MtYTVlMy03ZWY4YTQ2Y2VhNGQiLCJpYXQiOjE3MTE5MjAzODQsImV4cCI6MTcxMTkyMzk4NCwiaXNzIjoiaHR0cDpcL1wvYzc3LWF1dGhndWFyZC1hcHAudGVzdCJ9.fPhn1c9gKsvmJ0XQ-5vBl_7sadGYLVaCrElfkjQGHkU'
)
Password
const response = await client.signupWithPassword({
email: '[email protected]',
password: 'Pass123!'
})
Set access token
const { accessToken } = response
client.setAccessToken(accessToken)
User
Get current user data
const response = await client.currentUser()
Update basic information of current user
const response = await client.updateCurrentUser({
firstname: 'John',
lastname: 'Doe'
})
Update email address of current user
const response = await client.updateCurrentUserEmail({
email: '[email protected]'
})
Update password of current user
⚠️ This works only with password provider!
const response = await client.updateCurrentUserPassword({
email: 'Pass123!'
})
Destroy account of current user
const response = await client.deleteCurrentUser()