Passage-JS

Client SDK

Passage-JS is our JavaScript library that is a building block for all Passkey Complete authentication, user, and session management.

If you're looking for a pre-built UI that handles everything for you elegantly check out our UI library Passage Elements or Passage React (opens in a new tab). If you have custom requirements or use cases that don't fit within an element then you can use Passage-JS to build your own custome authentication user experience.

Setup

Via NPM

Install the @passageidentity/passage-js (opens in a new tab) package via NPM.

npm install @passageidentity/passage-js

Then you can import Passage-JS into your code as follows:

import { Passage } from '@passageidentity/passage-js';
 
const passage = new Passage('YOUR APP ID');
const publicUserInfo = await passage.app.userExists('test@passage.id');
if (publicUserInfo === null) {
    //register
    await passage.passkey.register('test@passage.id');
} else {
    //login
    await passage.passkey.login('test@passage.id');
}

Via CDN

Include the PassageJS library on your website as follows:

<script type="module">
    import { Passage } from 'https://cdn.passage.id/passage-js/v4.x/passage-js.js';
 
    const passage = new Passage('YOUR_APP_ID');
</script>

You can also specify a minor build of passage-js by replacing v4.x in the CDN path with the desired version number such as v4.0.x. All CDN builds are auto-updated with any patches.

With Token Store

The base Passage constructor takes an optional config parameter that allows you to define your own token store. If you would like to define custom methods for where to get, set, or clear auth related tokens you should use this pattern. See the Token Store Reference for more details.

import { TokenStore } from '@passageidentity/passage-js';
 
export class MyTokenStore extends TokenStore {
    getAuthToken() {
        const jwt = localStorage.getItem('passage_jwt');
        return Promise.resolve(JSON.parse(jwt));
    }
    setTokens(authResult) {
        const passageToken = authResult.auth_token;
        localStorage.setItem('passage_jwt', passageToken);
        return Promise.resolve();
    }
}
import { Passage } from '@passageidentity/passage-js';
import { MyTokenStore } from 'tokenStore.js';
const tokenStore = new MyTokenStore();
 
const passage = new Passage('YOUR APP ID', { tokenStore });

API Reference

The full API reference for Passage-JS can be found in the README of the NPM package @passageidentity/passage-js (opens in a new tab).