mlauth-js
v1.1.1
Published
A javascript client for the mlAuth authentication service
Downloads
6
Maintainers
Readme
mlauth-js
The javascript client for mlAuth.
[built for the Planetscape x Hashnode Hackathon]
Quick Start
install
# npm
npm i mlauth-js
# pnpm
pnpm add mlauth-js
# yarn
yarn add mlauth-js
import
// ESM
import mlAuth from 'mlauth-js'
// CommonJS
const mlAuth = require('mlauth-js')
Start Authenticating Users
Initiate a new mlAuth instance
const client = new mlAuth({
client: APP_CLIENT_KEY,
secret: APP_SECRET_KEY
})
Make Login Requests (send magic login links to users)
const response = await client.login(EMAIL)
Authenticate magic links
Obtain the token passed as a query on the callbackUrl you added while creating your app, and pass it as the only argument of the verify method.
const response = await client.verify(TOKEN)
Both instance return Promises that resolve as follows:
- Successful requests, return an Object with a data and message properties.
// Example: { data: { // magic link details }, message: "Magic link created" }
- Failures, resolve with ohmyfetch's
FetchError
type. The error body is available onerror.data
.// Example: FetchError: 401 Not Authorized
Examples
Here are examples demonstrating how to use this package when authenticating users with mlAuth.
- mlauth-fe-demo - Vite + Vue.js
- mlauth-be-demo - NodeJs + Express