fix(auth): adjust secure cookie flag for HTTP/HTTPS and fallback Bearer token
This commit is contained in:
parent
0f22643707
commit
562c3f9ca1
@ -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', {
|
||||
try {
|
||||
await this.request('/auth/logout', {
|
||||
method: 'POST'
|
||||
});
|
||||
} finally {
|
||||
if (typeof sessionStorage !== 'undefined') {
|
||||
sessionStorage.removeItem('a2host_token');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
async getMe() {
|
||||
|
||||
@ -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);
|
||||
|
||||
Loading…
Reference in New Issue
Block a user