Files
frontend/app/adapters/application.js
Dainii 0b29bc2d44
Some checks failed
CI / Lint (push) Failing after 7m46s
CI / Test (push) Failing after 8m24s
small works
2025-04-04 18:21:37 +02:00

36 lines
912 B
JavaScript

import JSONAPIAdapter from '@ember-data/adapter/json-api';
import { computed } from '@ember/object';
import { inject as service } from '@ember/service';
export default class ApplicationAdapter extends JSONAPIAdapter {
@service session;
get namespace() {
if (this.session.isAuthenticated) {
return 'api/v1';
} else {
return 'api/v1/public';
}
}
@computed('session.{data.authenticated.access_token,isAuthenticated}')
get headers() {
let headers = {};
if (this.session.isAuthenticated) {
// OAuth 2
headers['Authorization'] =
`Bearer ${this.session.data.authenticated.access_token}`;
}
return headers;
}
handleResponse(status, headers, payload, requestData) {
if (status === 401 && this.session.isAuthenticated) {
this.session.invalidate();
}
return super.handleResponse(status, headers, payload, requestData);
}
}