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:
parent
3a229c5b42
commit
71062a57be
@ -2,11 +2,7 @@
|
||||
|
||||
import { createBlobClient } from "@bytelyst/blob-client";
|
||||
import { PLATFORM_SERVICE_URL, PRODUCT_ID } from "@/lib/product-config";
|
||||
|
||||
function getAccessToken(): string | null {
|
||||
if (typeof window === "undefined") return null;
|
||||
return localStorage.getItem(`${PRODUCT_ID}_access_token`);
|
||||
}
|
||||
import { getAccessToken } from "@/lib/api-helpers";
|
||||
|
||||
let _blobClient: ReturnType<typeof createBlobClient> | null = null;
|
||||
function getBlobClient() {
|
||||
|
||||
@ -2,11 +2,7 @@
|
||||
|
||||
import { createBroadcastClient, type BroadcastClient } from "@bytelyst/broadcast-client";
|
||||
import { PLATFORM_SERVICE_URL, PRODUCT_ID } from "@/lib/product-config";
|
||||
|
||||
function getAccessToken(): string {
|
||||
if (typeof window === "undefined") return "";
|
||||
return localStorage.getItem(`${PRODUCT_ID}_access_token`) ?? "";
|
||||
}
|
||||
import { getAccessToken } from "@/lib/api-helpers";
|
||||
|
||||
let _client: BroadcastClient | null = null;
|
||||
export function getBroadcastClient(): BroadcastClient {
|
||||
@ -14,7 +10,7 @@ export function getBroadcastClient(): BroadcastClient {
|
||||
_client = createBroadcastClient({
|
||||
baseUrl: PLATFORM_SERVICE_URL,
|
||||
productId: PRODUCT_ID,
|
||||
getAuthToken: getAccessToken,
|
||||
getAuthToken: () => getAccessToken() ?? "",
|
||||
platform: "web",
|
||||
appVersion: "0.1.0",
|
||||
osVersion: typeof navigator !== "undefined" ? navigator.userAgent.slice(0, 40) : "unknown",
|
||||
|
||||
@ -2,15 +2,13 @@
|
||||
|
||||
import { createWebDiagnostics } from "@bytelyst/diagnostics-client";
|
||||
import { DIAGNOSTICS_URL, PRODUCT_ID } from "@/lib/product-config";
|
||||
import { getAccessToken } from "@/lib/api-helpers";
|
||||
|
||||
const { init: initDiagnostics, stop: stopDiagnostics } = createWebDiagnostics({
|
||||
productId: PRODUCT_ID,
|
||||
channel: "notes_web",
|
||||
serverUrl: DIAGNOSTICS_URL,
|
||||
getAuthToken: () => {
|
||||
if (typeof window === "undefined") return "";
|
||||
return localStorage.getItem(`${PRODUCT_ID}_access_token`) ?? "";
|
||||
},
|
||||
getAuthToken: () => getAccessToken() ?? "",
|
||||
});
|
||||
|
||||
export { initDiagnostics, stopDiagnostics };
|
||||
|
||||
@ -2,13 +2,9 @@
|
||||
|
||||
import { createExtractionClient, type ExtractionClient } from "@bytelyst/extraction";
|
||||
import { EXTRACTION_SERVICE_URL, PRODUCT_ID } from "@/lib/product-config";
|
||||
import { getAccessToken } from "@/lib/api-helpers";
|
||||
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;
|
||||
function getClient(): ExtractionClient {
|
||||
if (!_client) {
|
||||
|
||||
@ -2,6 +2,7 @@
|
||||
|
||||
import { createFeatureFlagClient } from "@bytelyst/feature-flag-client";
|
||||
import { PLATFORM_SERVICE_URL, PRODUCT_ID } from "@/lib/product-config";
|
||||
import { getAccessToken } from "@/lib/api-helpers";
|
||||
|
||||
let initialized = false;
|
||||
|
||||
@ -11,10 +12,7 @@ const featureFlagClient = createFeatureFlagClient({
|
||||
platform: "web",
|
||||
useStreaming: true,
|
||||
pollIntervalMs: 5 * 60 * 1000,
|
||||
getAccessToken: () =>
|
||||
typeof window !== "undefined"
|
||||
? localStorage.getItem("access_token")
|
||||
: null,
|
||||
getAccessToken,
|
||||
});
|
||||
|
||||
export async function initFeatureFlags(userId?: string) {
|
||||
|
||||
@ -2,11 +2,7 @@
|
||||
|
||||
import { createFeedbackClient, type FeedbackClient } from "@bytelyst/feedback-client";
|
||||
import { PLATFORM_SERVICE_URL, PRODUCT_ID } from "@/lib/product-config";
|
||||
|
||||
function getAccessToken(): string | null {
|
||||
if (typeof window === "undefined") return null;
|
||||
return localStorage.getItem(`${PRODUCT_ID}_access_token`);
|
||||
}
|
||||
import { getAccessToken } from "@/lib/api-helpers";
|
||||
|
||||
let _client: FeedbackClient | null = null;
|
||||
export function getFeedbackClient(): FeedbackClient {
|
||||
|
||||
@ -2,11 +2,7 @@
|
||||
|
||||
import { createPlatformClient, type PlatformClient } from "@bytelyst/platform-client";
|
||||
import { PLATFORM_SERVICE_URL, PRODUCT_ID } from "@/lib/product-config";
|
||||
|
||||
function getAccessToken(): string | null {
|
||||
if (typeof window === "undefined") return null;
|
||||
return localStorage.getItem(`${PRODUCT_ID}_access_token`);
|
||||
}
|
||||
import { getAccessToken } from "@/lib/api-helpers";
|
||||
|
||||
let _client: PlatformClient | null = null;
|
||||
function getClient(): PlatformClient {
|
||||
|
||||
@ -2,13 +2,11 @@
|
||||
|
||||
import { createPlatformClient } from "@bytelyst/platform-client";
|
||||
import { PLATFORM_SERVICE_URL, PRODUCT_ID } from "@/lib/product-config";
|
||||
import { getAccessToken } from "@/lib/api-helpers";
|
||||
|
||||
export const platformClient = createPlatformClient({
|
||||
baseUrl: PLATFORM_SERVICE_URL,
|
||||
productId: PRODUCT_ID,
|
||||
getAccessToken: () => {
|
||||
if (typeof window === "undefined") return null;
|
||||
return localStorage.getItem(`${PRODUCT_ID}_access_token`);
|
||||
},
|
||||
getAccessToken,
|
||||
refreshAccessToken: async () => false,
|
||||
});
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
"use client";
|
||||
|
||||
import { createNotesApiClient } from "@/lib/api-helpers";
|
||||
import { createNotesApiClient, getAccessToken } from "@/lib/api-helpers";
|
||||
import type {
|
||||
PromptTemplate,
|
||||
RunPromptInput,
|
||||
@ -57,7 +57,7 @@ export async function runPromptStream(
|
||||
): Promise<void> {
|
||||
const api = createNotesApiClient();
|
||||
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" };
|
||||
if (token) headers["Authorization"] = `Bearer ${token}`;
|
||||
|
||||
|
||||
@ -2,11 +2,7 @@
|
||||
|
||||
import { createSurveyClient, type SurveyClient } from "@bytelyst/survey-client";
|
||||
import { PLATFORM_SERVICE_URL, PRODUCT_ID } from "@/lib/product-config";
|
||||
|
||||
function getAccessToken(): string {
|
||||
if (typeof window === "undefined") return "";
|
||||
return localStorage.getItem(`${PRODUCT_ID}_access_token`) ?? "";
|
||||
}
|
||||
import { getAccessToken } from "@/lib/api-helpers";
|
||||
|
||||
let _client: SurveyClient | null = null;
|
||||
export function getSurveyClient(): SurveyClient {
|
||||
@ -14,7 +10,7 @@ export function getSurveyClient(): SurveyClient {
|
||||
_client = createSurveyClient({
|
||||
baseUrl: PLATFORM_SERVICE_URL,
|
||||
productId: PRODUCT_ID,
|
||||
getAuthToken: getAccessToken,
|
||||
getAuthToken: () => getAccessToken() ?? "",
|
||||
platform: "web",
|
||||
appVersion: "0.1.0",
|
||||
osVersion: typeof navigator !== "undefined" ? navigator.userAgent.slice(0, 40) : "unknown",
|
||||
|
||||
Loading…
Reference in New Issue
Block a user