feat(web): add public chat and thread API types and services

This commit is contained in:
CREDO23 2026-01-26 16:11:55 +02:00
parent aeb0deb21e
commit 9d7259aab9
5 changed files with 170 additions and 2 deletions

View file

@ -23,7 +23,10 @@ export type RequestOptions = {
class BaseApiService {
baseUrl: string;
noAuthEndpoints: string[] = ["/auth/jwt/login", "/auth/register", "/auth/refresh"]; // Add more endpoints as needed
noAuthEndpoints: string[] = ["/auth/jwt/login", "/auth/register", "/auth/refresh"];
// Prefixes that don't require auth (checked with startsWith)
noAuthPrefixes: string[] = ["/api/v1/public/"];
// Use a getter to always read fresh token from localStorage
// This ensures the token is always up-to-date after login/logout
@ -84,7 +87,10 @@ class BaseApiService {
}
// Validate the bearer token
if (!this.bearerToken && !this.noAuthEndpoints.includes(url)) {
const isNoAuthEndpoint =
this.noAuthEndpoints.includes(url) ||
this.noAuthPrefixes.some((prefix) => url.startsWith(prefix));
if (!this.bearerToken && !isNoAuthEndpoint) {
throw new AuthenticationError("You are not authenticated. Please login again.");
}