admin
This commit is contained in:
parent
090abb06f2
commit
b058dfaaec
2 changed files with 16 additions and 3 deletions
|
|
@ -24,8 +24,20 @@ export const adminApiClient = axios.create({
|
||||||
// Request interceptor to add auth token
|
// Request interceptor to add auth token
|
||||||
const addAuthToken = (config: any) => {
|
const addAuthToken = (config: any) => {
|
||||||
const token = localStorage.getItem('admin_token')
|
const token = localStorage.getItem('admin_token')
|
||||||
if (token) {
|
if (token && token.trim()) {
|
||||||
config.headers.Authorization = `Bearer ${token}`
|
// Ensure headers object exists
|
||||||
|
if (!config.headers) {
|
||||||
|
config.headers = {}
|
||||||
|
}
|
||||||
|
config.headers.Authorization = `Bearer ${token.trim()}`
|
||||||
|
} else {
|
||||||
|
// Log warning if token is missing (except for public auth endpoints)
|
||||||
|
const isPublicAuthEndpoint =
|
||||||
|
config.url?.includes('/admin/auth/request-code') ||
|
||||||
|
config.url?.includes('/admin/auth/verify-code')
|
||||||
|
if (!isPublicAuthEndpoint) {
|
||||||
|
console.warn('No admin token found in localStorage for request:', config.url)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return config
|
return config
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -10,6 +10,7 @@ const _publicAuthPaths = {
|
||||||
'/auth/telegram/claim-code', // Bot endpoint for claiming web codes
|
'/auth/telegram/claim-code', // Bot endpoint for claiming web codes
|
||||||
'/auth/refresh',
|
'/auth/refresh',
|
||||||
'/admin/auth/request-code', // Admin login code request (public)
|
'/admin/auth/request-code', // Admin login code request (public)
|
||||||
|
'/admin/auth/verify-code', // Admin login code verification (public)
|
||||||
'/tests',
|
'/tests',
|
||||||
'/test',
|
'/test',
|
||||||
};
|
};
|
||||||
|
|
@ -49,7 +50,7 @@ Middleware authorizeV2(UserManager userManager, JwtService jwtService) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check if this is a public auth endpoint - always allow for all HTTP methods
|
// Check if this is a public auth endpoint - always allow for all HTTP methods
|
||||||
if (normalizedPath.startsWith('/auth/')) {
|
if (normalizedPath.startsWith('/auth/') || normalizedPath.startsWith('/admin/auth/')) {
|
||||||
if (_publicAuthPaths.contains(normalizedPath)) {
|
if (_publicAuthPaths.contains(normalizedPath)) {
|
||||||
// Auth endpoints in public list are accessible without token
|
// Auth endpoints in public list are accessible without token
|
||||||
return await innerHandler(request);
|
return await innerHandler(request);
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue