Skip to content

JustAuthMe/node-jam-sdk

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

JustAuthMe Node SDK

Install

npm i node-jam-sdk

Usage :

1. Import

const { JamSDK } = require("node-jam-sdk");

Or using typescript :

import { JamSDK } from "node-jam-sdk"

2. Configure

const jam = new JamSDK("<appId>", "<redirectUrl>", "<apiSecret>");

3. Show login page to user :

You can generate the url to the login page using

jam.generateLoginUrl() 

If you're using React for your frontend, you can use the react-jam-button component.

4. Authenticate the user

When the users authenticate using the app, they will be redirected to your redirectUrl with an accessToken in the uri.

getUserInfos will return the UserData through a Promise (e.g: jam_id, email, firstname, lastname, etc...)

jam.getUserInfos(accessToken).then(value => {
    // log user in using userData
}).catch(error => {
    // handle error
})

Example with express :

const { JamSDK } = require("node-jam-sdk");

const jam = new JamSDK("<appId>", "<redirectUrl>", "<apiSecret>");
const express = require('express');
const app = express();

app.get('/auth-jam', function(req, res){
    const accessToken =  req.query.access_token;

    jam.getUserInfos(accessToken).then(userData => {
        // if userData.jam_id exists in your database, you have to login that user.
        // else : you have to save userData.jam_id into your database along with the data from userData (email etc)
    }).catch(error => {
        // handle error
    })

});

app.listen(3000);

Error handling :

The getUserInfos promise may reject. There are different types of error :

Error Reason
JamBadRequestError Access-Token and API Secret are required. Please contact [email protected].
JamUnauthorizedError Api Secret is invalid
JamNotFoundError No such Access-Token
JamInternalServerError This should not happen. Please contact [email protected] if it does.
JamUnknownError This should not happen. Please contact [email protected] if it does

About

NodeJS sdk for JustAuthMe services

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 3

  •  
  •  
  •