diff --git a/app/authenticators/meilisearch.js b/app/authenticators/meilisearch.js index 1f00009..05d574a 100644 --- a/app/authenticators/meilisearch.js +++ b/app/authenticators/meilisearch.js @@ -1,9 +1,26 @@ import Base from 'ember-simple-auth/authenticators/base'; +// import query from '../utils/query'; -export default Base.extend({ - restore(data) {}, +function makeRequest({ url, key }) { + const headers = new Headers({ + 'Content-Type': 'application/json', + }); - authenticate(/*args*/) {}, + if (key) { + headers.append('Authorization', `Bearer ${key}`); + } - invalidate(data) {}, -}); + const req = new Request(new URL('/version', url), { headers }); + + return fetch(req).then(() => ({ url, key })); +} + +export default class MeilisearchAuthenticator extends Base { + restore({ url, key }) { + return makeRequest({ url, key }); + } + + authenticate(url, key) { + return makeRequest({ url, key }); + } +} diff --git a/app/controllers/login.js b/app/controllers/login.js index e7cf9b0..24d1758 100644 --- a/app/controllers/login.js +++ b/app/controllers/login.js @@ -4,35 +4,26 @@ import { action } from '@ember/object'; import { tracked } from '@glimmer/tracking'; export default class LoginController extends Controller { - @tracked errorMessage; @service session; + @tracked errorMessage; + @tracked url = 'http://127.0.0.1:7700'; + @tracked key; + @action async authenticate(e) { e.preventDefault(); - let { identification, password } = this; + + let { url, key } = this; + try { - await this.session.authenticate( - 'authenticator:oauth2', - identification, - password - ); + await this.session.authenticate('authenticator:meilisearch', url, key); } catch (error) { this.errorMessage = error.error || error; } - if (this.session.isAuthenticated) { - // What to do with all this success? - } - } - - @action - updateIdentification(e) { - this.identification = e.target.value; - } - - @action - updatePassword(e) { - this.password = e.target.value; + // if (this.session.isAuthenticated) { + // this.transitionToRoute('index'); + // } } } diff --git a/app/templates/login.hbs b/app/templates/login.hbs index c90daaf..0c61fc6 100644 --- a/app/templates/login.hbs +++ b/app/templates/login.hbs @@ -1,22 +1,42 @@ {{page-title 'Login'}} -
- - - - - - {{#if this.errorMessage}} -

{{this.errorMessage}}

- {{/if}} -
+
+
+
+
+ + + + + {{!--
+
+ + +
+
--}} + +
+
+