1.0.0-beta.13 • Published 3 months ago

@jaaahn/hyper-id-client v1.0.0-beta.13

Weekly downloads
-
License
MIT
Repository
-
Last release
3 months ago

HyperID Client Library

This library is for internal use only.

Client

Initialize Auth instance

import { clientInstance } from "@jaaahn/hyper-id-client";

// Create new auth instance
let auth = new clientInstance({
    apiURL: "https://localhost:8080",
    webURL: "http://localhost:3000",
    publicKey: "your_app_public_key",
    includeTokenIn: ["list_of_baseURLs_to_your_first_party_server"],
});

// Add axios interceptors to inject access token in requests
import axios from "axios";
auth.addAxiosInterceptors(axios);

// Install HyperID to Vue
import router from "./router.js";
auth.installVue(router);

// Catch user updates
let removeUserListener = auth.addEventListener("userChanged", (user) => {
    console.log("user changed", user);

    // DEPRECATION NOTICE: This object includes an `app_data` key. Please use the readAppData() function as the userChanged event won't fire if appData is changed
});

// Catch auth status updates
let removeStatusListener = auth.addEventListener("statusChanged", (status) => {
    console.log("status changed", status);

    // Status syntax
    // {
    //     systemStatus: String; // "initializing" or "loggedOut" or "loggedIn"
    // }
});

// Remove listeners if no longer needed
removeUserListener();
removeStatusListener();

// Start HyperID
auth.startInitialization();

// Make the instance available to the rest of your application
export default auth;

Open login page

auth.authenticate();

Optional: Provide a route that is opened after login:

auth.authenticate("/my_profile");

Open HyperID account settings page

auth.openAccountSettings();

Logout

await auth.logout();

Get user info (also triggers onUserUpdate)

await auth.getUser();

DEPRECATION NOTICE: This object includes an app_data key. Please use the readAppData() function as the userChanged event won't fire if appData is changed

Read user's AppData

await auth.readAppData();

Write user's AppData

await auth.writeAppData(data);

The data object should be a dictionary containing key-value pairs.
Only strings can be stored as values. Any non-ASCII characters are automatically removed from keys.
If a key is set to null, it will be deleted from the DB. If an existing key is not mentioned, it won't be touched.

Warning: This does NOT perform escaping so make shure to have a XSS preventioning system implemented if storing user generated content

Server

Initialization

import { serverInstance } from "@jaaahn/hyper-id-client";

// Create new auth server instance
let auth = new serverInstance({
    apiURL: "http://localhost:8080",
    privateKey: "your_app_private_key",
});

Express verify session middleware

// Add the middleware to your routes
// It is important that you call the `auth.verifySession` function!

// A valid session is required
app.get("/myRoute", auth.verifySession(), (request, response) => {
    let { user } = request.hyperid;
});

// A valid session is NOT required; the user info will still be available if a user is logged in
app.get("/myRoute", auth.verifySession(false), (request, response) => {
    let { user } = request.hyperid;
});

Read user's AppData

await auth.readAppData(user_id);

Write user's AppData

await auth.writeAppData(user_id, data);

The data object should be a dictionary containing key-value pairs.
Only strings can be stored as values. Any non-ASCII characters are automatically removed from keys.
If a key is set to null, it will be deleted from the DB. If an existing key is not mentioned, it won't be touched.

Warning: This does NOT perform escaping so make shure to have a XSS preventioning system implemented if storing user generated content

Get info about app

await auth.getAppInfo();

Get a list of all users

await auth.getAllUsers();

Get one user

await auth.getOneUser(search);

Search by user_id or by email.

1.0.0-beta.13

3 months ago

1.0.0-beta.12

3 months ago

1.0.0-beta.3

9 months ago

1.0.0-beta.4

9 months ago

1.0.0-beta.5

9 months ago

1.0.0-beta.11

7 months ago

1.0.0-beta.10

8 months ago

1.0.0-beta.6

9 months ago

1.0.0-beta.7

9 months ago

1.0.0-beta.8

8 months ago

1.0.0-beta.9

8 months ago

1.0.0-beta.2

1 year ago

1.0.0-beta.1

1 year ago