Skip to main content

Documentation Index

Fetch the complete documentation index at: https://docs.discovr.media/llms.txt

Use this file to discover all available pages before exploring further.

Use the device code flow for TVs, set-top boxes, IoT devices, or any app where you want second-screen sign-in. User sees a short code and QR code on the device. They scan the QR or enter the code on their phone or web browser. SDK polls in the background until authenticated.

Getting started

1

Request device code

Call signInWithDeviceCode(). Returns user code (e.g., “B7K-29F”) and QR code.
2

Display to user

Show the user code and render the QR code on device. Tell user: “Sign in on your phone using this code or QR.”
3

Wait for sign-in

SDK polls automatically. Listen with onAuthStateChanged() (TypeScript) or authState / authStateStream (Kotlin/Swift) for completion.
4

Sign-in confirmed

Once user authorizes on their other device, SDK receives refresh token and notifies you.
5

Select profile & call API

Call selectProfile(), then use DiscovrClient methods as normal.

Code example

import { DiscovrClient } from "discovr";

const client = new DiscovrClient("your-client-id");

// Request device code
const { userCode, qrCode } = await client.signInWithDeviceCode();
console.log(`Code: ${userCode}`);
// Render qrCode in your UI

// SDK polls in background
client.onAuthStateChanged(({ signedIn }) => {
	if (signedIn) {
		console.log("User authenticated on other device!");
		// Now select profile
		selectProfile();
	}
});

How it works

Device code flow — QR code on TV, user scans with phone, SDK polls for completion
Step by step:
  1. Device calls signInWithDeviceCode()
  2. Discovr returns user code (e.g., “B7K-29F”) and QR code
  3. Device displays code and QR to user
  4. User scans QR with phone or goes to discovr.example.com/activate and enters code
  5. User signs in on their phone
  6. SDK on device detects sign-in (automatic polling)
  7. Refresh token is stored locally on device
SDK handles polling automatically in background. Just listen for auth state changes.
Great for second-screen UX: “Sign in on your phone while your content loads on TV.”

Handling sign-in errors

try {
	const { userCode, qrCode } = await client.signInWithDeviceCode();
	// Display to user

	client.onAuthStateChanged(({ signedIn }) => {
		if (signedIn) {
			// Continue with profile selection
		}
	});
} catch (err) {
	if (err.code === "NETWORK_ERROR") {
		console.log("Network error. Check connection.");
	} else {
		console.log("Device code request failed:", err.message);
	}
}
Device codes expire after 15 minutes without sign-in. Request a new code if sign-in takes longer.

Advanced: Manual HTTP implementation

If building a custom client without the SDK: signInWithDeviceCode · onAuthStateChanged · selectProfile
Next: Understand sessions and profiles