release: @marketplaces/auth 0.1.0 (built from main)
This commit is contained in:
26
dist/telegram/admin-auth-headers.interceptor.js
vendored
Normal file
26
dist/telegram/admin-auth-headers.interceptor.js
vendored
Normal file
@@ -0,0 +1,26 @@
|
||||
import { inject } from '@angular/core';
|
||||
import { AdminAuthService } from './admin-auth.service';
|
||||
/** Backend paths that require an active AdminWebSessionID. Adjust to match your API surface if consuming this outside marketplaces. */
|
||||
const ADMIN_GATED_PATH_SEGMENTS = ['/admin/', '/backoffice/', '/builder/', '/media/'];
|
||||
/**
|
||||
* Attaches admin session/token headers only to admin API requests. Scoped to
|
||||
* admin-gated paths so it never touches customer requests and never reads
|
||||
* the customer AuthService's session.
|
||||
*/
|
||||
export const adminAuthHeadersInterceptor = (req, next) => {
|
||||
const isAdminRequest = ADMIN_GATED_PATH_SEGMENTS.some(segment => req.url.includes(segment));
|
||||
if (!isAdminRequest) {
|
||||
return next(req);
|
||||
}
|
||||
const adminAuth = inject(AdminAuthService);
|
||||
const session = adminAuth.session();
|
||||
const token = adminAuth.getAdminToken();
|
||||
let headers = req.headers;
|
||||
if (session?.sessionId) {
|
||||
headers = headers.set('AdminWebSessionID', session.sessionId);
|
||||
}
|
||||
if (token) {
|
||||
headers = headers.set('Authorization', `Bearer ${token}`);
|
||||
}
|
||||
return next(req.clone({ headers }));
|
||||
};
|
||||
Reference in New Issue
Block a user