fix(web): fix auth token key inconsistency and DRY getAccessToken()

feature-flags.ts and prompt-client.ts used bare 'access_token' key
instead of PRODUCT_ID-prefixed key — auth tokens were never sent.

Consolidates 10 web lib files to import the shared getAccessToken()
from api-helpers.ts instead of each redefining their own copy.
This commit is contained in:
saravanakumardb1 2026-04-13 09:59:18 -07:00
parent 3a229c5b42
commit 71062a57be
10 changed files with 16 additions and 46 deletions

View File

@ -2,11 +2,7 @@
import { createBlobClient } from "@bytelyst/blob-client"; import { createBlobClient } from "@bytelyst/blob-client";
import { PLATFORM_SERVICE_URL, PRODUCT_ID } from "@/lib/product-config"; import { PLATFORM_SERVICE_URL, PRODUCT_ID } from "@/lib/product-config";
import { getAccessToken } from "@/lib/api-helpers";
function getAccessToken(): string | null {
if (typeof window === "undefined") return null;
return localStorage.getItem(`${PRODUCT_ID}_access_token`);
}
let _blobClient: ReturnType<typeof createBlobClient> | null = null; let _blobClient: ReturnType<typeof createBlobClient> | null = null;
function getBlobClient() { function getBlobClient() {

View File

@ -2,11 +2,7 @@
import { createBroadcastClient, type BroadcastClient } from "@bytelyst/broadcast-client"; import { createBroadcastClient, type BroadcastClient } from "@bytelyst/broadcast-client";
import { PLATFORM_SERVICE_URL, PRODUCT_ID } from "@/lib/product-config"; import { PLATFORM_SERVICE_URL, PRODUCT_ID } from "@/lib/product-config";
import { getAccessToken } from "@/lib/api-helpers";
function getAccessToken(): string {
if (typeof window === "undefined") return "";
return localStorage.getItem(`${PRODUCT_ID}_access_token`) ?? "";
}
let _client: BroadcastClient | null = null; let _client: BroadcastClient | null = null;
export function getBroadcastClient(): BroadcastClient { export function getBroadcastClient(): BroadcastClient {
@ -14,7 +10,7 @@ export function getBroadcastClient(): BroadcastClient {
_client = createBroadcastClient({ _client = createBroadcastClient({
baseUrl: PLATFORM_SERVICE_URL, baseUrl: PLATFORM_SERVICE_URL,
productId: PRODUCT_ID, productId: PRODUCT_ID,
getAuthToken: getAccessToken, getAuthToken: () => getAccessToken() ?? "",
platform: "web", platform: "web",
appVersion: "0.1.0", appVersion: "0.1.0",
osVersion: typeof navigator !== "undefined" ? navigator.userAgent.slice(0, 40) : "unknown", osVersion: typeof navigator !== "undefined" ? navigator.userAgent.slice(0, 40) : "unknown",

View File

@ -2,15 +2,13 @@
import { createWebDiagnostics } from "@bytelyst/diagnostics-client"; import { createWebDiagnostics } from "@bytelyst/diagnostics-client";
import { DIAGNOSTICS_URL, PRODUCT_ID } from "@/lib/product-config"; import { DIAGNOSTICS_URL, PRODUCT_ID } from "@/lib/product-config";
import { getAccessToken } from "@/lib/api-helpers";
const { init: initDiagnostics, stop: stopDiagnostics } = createWebDiagnostics({ const { init: initDiagnostics, stop: stopDiagnostics } = createWebDiagnostics({
productId: PRODUCT_ID, productId: PRODUCT_ID,
channel: "notes_web", channel: "notes_web",
serverUrl: DIAGNOSTICS_URL, serverUrl: DIAGNOSTICS_URL,
getAuthToken: () => { getAuthToken: () => getAccessToken() ?? "",
if (typeof window === "undefined") return "";
return localStorage.getItem(`${PRODUCT_ID}_access_token`) ?? "";
},
}); });
export { initDiagnostics, stopDiagnostics }; export { initDiagnostics, stopDiagnostics };

View File

@ -2,13 +2,9 @@
import { createExtractionClient, type ExtractionClient } from "@bytelyst/extraction"; import { createExtractionClient, type ExtractionClient } from "@bytelyst/extraction";
import { EXTRACTION_SERVICE_URL, PRODUCT_ID } from "@/lib/product-config"; import { EXTRACTION_SERVICE_URL, PRODUCT_ID } from "@/lib/product-config";
import { getAccessToken } from "@/lib/api-helpers";
import type { NoteTask } from "@/lib/types"; import type { NoteTask } from "@/lib/types";
function getAccessToken(): string | null {
if (typeof window === "undefined") return null;
return localStorage.getItem(`${PRODUCT_ID}_access_token`);
}
let _client: ExtractionClient | null = null; let _client: ExtractionClient | null = null;
function getClient(): ExtractionClient { function getClient(): ExtractionClient {
if (!_client) { if (!_client) {

View File

@ -2,6 +2,7 @@
import { createFeatureFlagClient } from "@bytelyst/feature-flag-client"; import { createFeatureFlagClient } from "@bytelyst/feature-flag-client";
import { PLATFORM_SERVICE_URL, PRODUCT_ID } from "@/lib/product-config"; import { PLATFORM_SERVICE_URL, PRODUCT_ID } from "@/lib/product-config";
import { getAccessToken } from "@/lib/api-helpers";
let initialized = false; let initialized = false;
@ -11,10 +12,7 @@ const featureFlagClient = createFeatureFlagClient({
platform: "web", platform: "web",
useStreaming: true, useStreaming: true,
pollIntervalMs: 5 * 60 * 1000, pollIntervalMs: 5 * 60 * 1000,
getAccessToken: () => getAccessToken,
typeof window !== "undefined"
? localStorage.getItem("access_token")
: null,
}); });
export async function initFeatureFlags(userId?: string) { export async function initFeatureFlags(userId?: string) {

View File

@ -2,11 +2,7 @@
import { createFeedbackClient, type FeedbackClient } from "@bytelyst/feedback-client"; import { createFeedbackClient, type FeedbackClient } from "@bytelyst/feedback-client";
import { PLATFORM_SERVICE_URL, PRODUCT_ID } from "@/lib/product-config"; import { PLATFORM_SERVICE_URL, PRODUCT_ID } from "@/lib/product-config";
import { getAccessToken } from "@/lib/api-helpers";
function getAccessToken(): string | null {
if (typeof window === "undefined") return null;
return localStorage.getItem(`${PRODUCT_ID}_access_token`);
}
let _client: FeedbackClient | null = null; let _client: FeedbackClient | null = null;
export function getFeedbackClient(): FeedbackClient { export function getFeedbackClient(): FeedbackClient {

View File

@ -2,11 +2,7 @@
import { createPlatformClient, type PlatformClient } from "@bytelyst/platform-client"; import { createPlatformClient, type PlatformClient } from "@bytelyst/platform-client";
import { PLATFORM_SERVICE_URL, PRODUCT_ID } from "@/lib/product-config"; import { PLATFORM_SERVICE_URL, PRODUCT_ID } from "@/lib/product-config";
import { getAccessToken } from "@/lib/api-helpers";
function getAccessToken(): string | null {
if (typeof window === "undefined") return null;
return localStorage.getItem(`${PRODUCT_ID}_access_token`);
}
let _client: PlatformClient | null = null; let _client: PlatformClient | null = null;
function getClient(): PlatformClient { function getClient(): PlatformClient {

View File

@ -2,13 +2,11 @@
import { createPlatformClient } from "@bytelyst/platform-client"; import { createPlatformClient } from "@bytelyst/platform-client";
import { PLATFORM_SERVICE_URL, PRODUCT_ID } from "@/lib/product-config"; import { PLATFORM_SERVICE_URL, PRODUCT_ID } from "@/lib/product-config";
import { getAccessToken } from "@/lib/api-helpers";
export const platformClient = createPlatformClient({ export const platformClient = createPlatformClient({
baseUrl: PLATFORM_SERVICE_URL, baseUrl: PLATFORM_SERVICE_URL,
productId: PRODUCT_ID, productId: PRODUCT_ID,
getAccessToken: () => { getAccessToken,
if (typeof window === "undefined") return null;
return localStorage.getItem(`${PRODUCT_ID}_access_token`);
},
refreshAccessToken: async () => false, refreshAccessToken: async () => false,
}); });

View File

@ -1,6 +1,6 @@
"use client"; "use client";
import { createNotesApiClient } from "@/lib/api-helpers"; import { createNotesApiClient, getAccessToken } from "@/lib/api-helpers";
import type { import type {
PromptTemplate, PromptTemplate,
RunPromptInput, RunPromptInput,
@ -57,7 +57,7 @@ export async function runPromptStream(
): Promise<void> { ): Promise<void> {
const api = createNotesApiClient(); const api = createNotesApiClient();
const baseUrl = (api as unknown as { baseUrl?: string }).baseUrl ?? ""; const baseUrl = (api as unknown as { baseUrl?: string }).baseUrl ?? "";
const token = typeof window !== "undefined" ? localStorage.getItem("access_token") : null; const token = getAccessToken();
const headers: Record<string, string> = { "Content-Type": "application/json" }; const headers: Record<string, string> = { "Content-Type": "application/json" };
if (token) headers["Authorization"] = `Bearer ${token}`; if (token) headers["Authorization"] = `Bearer ${token}`;

View File

@ -2,11 +2,7 @@
import { createSurveyClient, type SurveyClient } from "@bytelyst/survey-client"; import { createSurveyClient, type SurveyClient } from "@bytelyst/survey-client";
import { PLATFORM_SERVICE_URL, PRODUCT_ID } from "@/lib/product-config"; import { PLATFORM_SERVICE_URL, PRODUCT_ID } from "@/lib/product-config";
import { getAccessToken } from "@/lib/api-helpers";
function getAccessToken(): string {
if (typeof window === "undefined") return "";
return localStorage.getItem(`${PRODUCT_ID}_access_token`) ?? "";
}
let _client: SurveyClient | null = null; let _client: SurveyClient | null = null;
export function getSurveyClient(): SurveyClient { export function getSurveyClient(): SurveyClient {
@ -14,7 +10,7 @@ export function getSurveyClient(): SurveyClient {
_client = createSurveyClient({ _client = createSurveyClient({
baseUrl: PLATFORM_SERVICE_URL, baseUrl: PLATFORM_SERVICE_URL,
productId: PRODUCT_ID, productId: PRODUCT_ID,
getAuthToken: getAccessToken, getAuthToken: () => getAccessToken() ?? "",
platform: "web", platform: "web",
appVersion: "0.1.0", appVersion: "0.1.0",
osVersion: typeof navigator !== "undefined" ? navigator.userAgent.slice(0, 40) : "unknown", osVersion: typeof navigator !== "undefined" ? navigator.userAgent.slice(0, 40) : "unknown",