work on jwt auth
Some checks failed
CI / Lint (push) Failing after 14m49s
CI / Test (push) Failing after 7m55s

This commit is contained in:
2025-01-08 16:49:27 +01:00
parent cf15e3beb3
commit feef600052
14 changed files with 103 additions and 18 deletions

View File

@@ -5,6 +5,8 @@ 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 = {};
@@ -15,4 +17,10 @@ export default class ApplicationAdapter extends JSONAPIAdapter {
return headers;
}
handleResponse(status) {
if (status === 401 && this.session.isAuthenticated) {
this.session.invalidate();
}
}
}

View File

@@ -1,14 +1,8 @@
import RSVP from 'rsvp';
import fetch from 'fetch';
import {
run, later, cancel
} from '@ember/runloop';
import {
isEmpty
} from '@ember/utils';
import {
warn
} from '@ember/debug';
import { run, later, cancel } from '@ember/runloop';
import { isEmpty } from '@ember/utils';
import { warn } from '@ember/debug';
import BaseAuthenticator from 'ember-simple-auth/authenticators/base';
export default BaseAuthenticator.extend({
@@ -248,7 +242,7 @@ export default BaseAuthenticator.extend({
const serverRefreshTokenEndpoint = this.get('serverRefreshTokenEndpoint');
return new RSVP.Promise((resolve, reject) => {
this.makeRequest(serverRefreshTokenEndpoint, data)
this.makeRequest(serverRefreshTokenEndpoint, data, { Authorization:data["access_token"] })
.then((response) => {
return this._validateTokenAndScheduleRefresh(response);
})

9
app/models/edition.js Normal file
View File

@@ -0,0 +1,9 @@
import Model, { attr } from "@ember-data/model";
export default class EditionModel extends Model {
@attr name;
@attr theme;
@attr status;
@attr startDate;
@attr endDate;
}

7
app/models/person.js Normal file
View File

@@ -0,0 +1,7 @@
import Model, { attr } from "@ember-data/model";
export default class PersonModel extends Model {
@attr("string") firstname;
@attr("string") lastname;
@attr("date") birthday;
}

6
app/models/venue.js Normal file
View File

@@ -0,0 +1,6 @@
import Model, { attr } from "@ember-data/model";
export default class VenueModel extends Model {
@attr name;
@attr location;
}

View File

@@ -8,4 +8,10 @@ export default class Router extends EmberRouter {
Router.map(function() {
this.route('login');
this.route('authenticated', { path: '' }, function() {
// all routes that require the session to be authenticated
this.route('index', { path: '' });
this.route('editions');
this.route('venues');
});
});

10
app/routes/application.js Normal file
View File

@@ -0,0 +1,10 @@
import Route from '@ember/routing/route';
import { inject } from '@ember/service';
export default class ApplicationRoute extends Route {
@inject session;
async beforeModel() {
await this.session.setup();
}
}

View File

@@ -0,0 +1,10 @@
import Route from '../authenticated';
import { service } from '@ember/service';
export default class EditionsRoute extends Route {
@service store;
model() {
return this.store.findAll('edition');
}
}

View File

@@ -0,0 +1,10 @@
import Route from '../authenticated';
import { service } from '@ember/service';
export default class VenuesRoute extends Route {
@service store;
model() {
return this.store.findAll('venue');
}
}

10
app/routes/login.js Normal file
View File

@@ -0,0 +1,10 @@
import Route from '@ember/routing/route';
import { inject as service } from '@ember/service';
export default class LoginRoute extends Route {
@service session;
beforeModel(transition) {
this.get('session').prohibitAuthentication('index');
}
}

View File

@@ -0,0 +1,5 @@
{{#each @model as |edition|}}
<div>
{{edition.name}}
</div>
{{/each}}

View File

@@ -0,0 +1,5 @@
<h3>Liste des pages</h3>
<ul>
<li><LinkTo @route="authenticated.editions">Editions</LinkTo></li>
</ul>

View File

@@ -21,11 +21,11 @@ module.exports = function (environment) {
};
if (environment === 'development') {
// ENV.APP.LOG_RESOLVER = true;
// ENV.APP.LOG_ACTIVE_GENERATION = true;
// ENV.APP.LOG_TRANSITIONS = true;
// ENV.APP.LOG_TRANSITIONS_INTERNAL = true;
// ENV.APP.LOG_VIEW_LOOKUPS = true;
ENV.APP.LOG_RESOLVER = true;
ENV.APP.LOG_ACTIVE_GENERATION = true;
ENV.APP.LOG_TRANSITIONS = true;
ENV.APP.LOG_TRANSITIONS_INTERNAL = true;
ENV.APP.LOG_VIEW_LOOKUPS = true;
}
if (environment === 'test') {
@@ -44,5 +44,10 @@ module.exports = function (environment) {
// here you can enable a production-specific feature
}
ENV['ember-simple-auth'] = {
routeAfterAuthentication: 'authenticated.index',
routeAfterInvalidation: 'login',
};
return ENV;
};

6
package-lock.json generated
View File

@@ -1921,9 +1921,9 @@
}
},
"node_modules/@ember-data/model/node_modules/inflection": {
"version": "3.0.1",
"resolved": "https://registry.npmjs.org/inflection/-/inflection-3.0.1.tgz",
"integrity": "sha512-EpyF+TLa3xZPClbkp9pDJZtJFYPHouWuFYsfAQI8AfjnaPVOpmRV6GSzCs+QGelj2eZ7oQllcK23aI1vHhPVVg==",
"version": "3.0.2",
"resolved": "https://registry.npmjs.org/inflection/-/inflection-3.0.2.tgz",
"integrity": "sha512-+Bg3+kg+J6JUWn8J6bzFmOWkTQ6L/NHfDRSYU+EVvuKHDxUDHAXgqixHfVlzuBQaPOTac8hn43aPhMNk6rMe3g==",
"dev": true,
"engines": {
"node": ">=18.0.0"