Skip to main content

What you will build

Preferences follow a verified device rather than only its session cookie. This is an illustrative application policy, not a default rule that ShieldLabs applies to every customer.

Run the starting application

You need Node.js 22 or later. The starter runs without ShieldLabs keys; the final version needs a registered HTTPS hostname and matching keys. Clone the public tutorial repository, then start this standalone application:
Open http://127.0.0.1:3000. The starter has no ShieldLabs dependency or identification check. Its own SQLite state is separate from every other tutorial.

Add the integration

Stop the starter server. Follow these changes, then run the complete implementation from the final branch.
1

1. Prepare the keys and HTTPS hostname

The .env copied from starter contains no key entries yet. Add the two lines below with this domain’s real values:
Register the app’s hostname in Integration > Domains. Put its matching Public Key and Private API Key in the private personalization/.env as SHIELDLABS_PUBLIC_KEY and SHIELDLABS_API_KEY. Serve this app through HTTPS on that registered hostname. The Private API Key stays on the server; a customer key does not automatically authorize localhost.
2

2. Identify the action in the browser

The public/index.html page loads the locally served JS SDK. In public/index.js, each action takes a fresh Request ID and sends it with the action:
Only the Request ID goes to the server; the browser does not supply the risk result.
3

3. Verify the identification on the server

server/shieldlabs.js uses @shieldlabs-ai/node and the Private API Key to find that exact Request ID in History. The action route passes it to server/sessions.js, where verifyIdentification(requestId) rejects missing, stale, replayed, automated or unusable checks before this scenario’s rule is applied.
4

4. Apply the returning device rule

This excerpt from server/sessions.js shows the decision’s core:
server/sessions.js verifies one fresh identification when starting a device session. Subsequent sample search and saved-product requests use that server-side session; they do not spend a new identification on every click.
5

5. Run the completed application

From the repository root, compare the two versions and start the final app:
A fresh clone has the remote origin/final ref even before its local final branch exists. Open the completed app through the registered HTTPS hostname. The Node server listens on 127.0.0.1:3000 behind your reverse proxy.

Follow the integration code

The completed source is in the personalization application. Read these files in order:
  1. Browser helper: loads the installed SDK, serializes checks and returns a request ID.
  2. Server verification: reads real History, checks the matching ID, rereads delayed results and rejects unusable or replayed checks.
  3. Scenario decision: applies this app’s rule using the verified identification and stores its sample state.
The finished application keeps its browser, server and SQLite state inside this folder. The tests use synthetic History responses; the normal server does not manufacture a successful identification.

Try the completed application

  1. Start a device session and search for a sample product. Save or view a product using the app’s controls.
  2. Start another session on the same observed device and revisit the store. The sample can use its remembered, non-sensitive activity for personalization.
  3. Do not use this tutorial to store sensitive browsing or purchasing preferences.
Use Reset demo DB with DEMO_ALLOW_RESET=1 to repeat the exercise. These controls are for a disposable demonstration, not production authorization.

Check your result

In DevTools Network, inspect the /api/session request and copy its requestId. Look up the session-start Request ID in History. The local session row must use its verified Device ID; subsequent searches do not need a new Request ID until a new session is started. Run npm run check and npm test from personalization to exercise failure cases locally without making more identifications. For a real run, obtain fresh request IDs in the browser and confirm their Device IDs and signals in History. If identification returns HTTP 429, stop and check your account limits before retrying. A cookie change does not prove that the Device ID changed: compare the History rows.

Adapt it to your product

This example is a starting point, not a production-ready authorization system. Bind each action to an authenticated session where appropriate, authorize administration screens, persist state and atomically consume request IDs across all server instances. Review legitimate shared-device behavior before applying a device-based restriction. See Acting on results.