fix(auth): adjust secure cookie flag for HTTP/HTTPS and fallback Bearer token

This commit is contained in:
GeronimoGc 2026-11-20 07:27:38 -05:00
parent 0f22643707
commit 562c3f9ca1
2 changed files with 17 additions and 5 deletions

View File

@ -37,8 +37,10 @@ class ApiClient {
async request(endpoint, options = {}) {
const url = `${this.baseUrl}${endpoint.startsWith('/') ? endpoint : `/${endpoint}`}`;
const token = typeof sessionStorage !== 'undefined' ? sessionStorage.getItem('a2host_token') : null;
const headers = {
'Accept': 'application/json, application/problem+json',
...(token ? { 'Authorization': `Bearer ${token}` } : {}),
...(options.headers || {})
};
@ -95,16 +97,26 @@ class ApiClient {
// --- Auth Endpoints ---
async login(credentials) {
return this.request('/auth/login', {
const res = await this.request('/auth/login', {
method: 'POST',
body: credentials
});
if (res && res.token && typeof sessionStorage !== 'undefined') {
sessionStorage.setItem('a2host_token', res.token);
}
return res;
}
async logout() {
return this.request('/auth/logout', {
method: 'POST'
});
try {
await this.request('/auth/logout', {
method: 'POST'
});
} finally {
if (typeof sessionStorage !== 'undefined') {
sessionStorage.removeItem('a2host_token');
}
}
}
async getMe() {

View File

@ -41,7 +41,7 @@ export class AuthController {
sameSite: 'Strict',
priority: 'High',
maxAge: maxAgeSeconds,
secure: config.isProduction
secure: Boolean(req.secure || req.headers['x-forwarded-proto'] === 'https')
});
res.setHeader('Set-Cookie', cookieHeader);