Files
frontend/app/adapters/application.js
Dainii feef600052
Some checks failed
CI / Lint (push) Failing after 14m49s
CI / Test (push) Failing after 7m55s
work on jwt auth
2025-01-08 16:49:27 +01:00

27 lines
688 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;
namespace = 'api/v1';
@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) {
if (status === 401 && this.session.isAuthenticated) {
this.session.invalidate();
}
}
}