From 31f31db9de07caee574cd24e052d9f53f00b8b73 Mon Sep 17 00:00:00 2001 From: Amaury Date: Tue, 28 May 2024 00:11:40 +0200 Subject: [PATCH] Upgrade (#10) * Upgrade Ember-data --- .eslintignore | 1 + .husky/_/pre-push | 56 + .husky/_/prepare-commit-msg | 56 + .husky/pre-commit | 7 - README.md | 5 - app/adapters/application.ts | 72 - app/adapters/user.ts | 25 - app/handlers/users.ts | 16 +- app/models/document.ts | 7 +- app/models/user.ts | 26 +- app/modifiers/errors-scroll-up.ts | 1 - app/routes/application.ts | 6 + app/serializers/application.ts | 31 - app/services/auth-handler.ts | 17 + app/services/changesets/changeset-service.ts | 6 - app/services/changesets/register.ts | 46 +- app/services/current-user.ts | 27 +- app/services/error-handler.ts | 2 +- app/services/head-data.ts | 8 - app/services/request-manager.ts | 24 + app/services/safe-store.ts | 15 + app/services/session.ts | 7 - app/services/store.js | 47 +- app/templates/register.gts | 13 +- ...{missing-message.ts => missing-message.js} | 2 +- app/utils/result-utils.ts | 23 + config/ember-cli-update.json | 2 +- lefthook.yml | 31 + package.json | 137 +- pnpm-lock.yaml | 7107 ++++++----------- public/mockServiceWorker.js | 2 +- tests/acceptance/register/main-test.ts | 2 + tests/acceptance/workers/login.ts | 5 +- tests/acceptance/workers/register.ts | 47 +- tests/helpers/index.ts | 6 + tests/unit/adapters/application-test.ts | 23 - .../services/changesets/register/mocks.ts | 12 +- .../changesets/register/register-test.ts | 17 +- tsconfig.json | 39 +- types/global.d.ts | 2 - 40 files changed, 3108 insertions(+), 4870 deletions(-) create mode 100755 .husky/_/pre-push create mode 100755 .husky/_/prepare-commit-msg delete mode 100755 .husky/pre-commit delete mode 100644 app/adapters/application.ts delete mode 100644 app/adapters/user.ts delete mode 100644 app/serializers/application.ts create mode 100644 app/services/auth-handler.ts delete mode 100644 app/services/changesets/changeset-service.ts create mode 100644 app/services/request-manager.ts create mode 100644 app/services/safe-store.ts rename app/utils/intl/{missing-message.ts => missing-message.js} (81%) create mode 100644 app/utils/result-utils.ts create mode 100644 lefthook.yml delete mode 100644 tests/unit/adapters/application-test.ts diff --git a/.eslintignore b/.eslintignore index 9385391..768fab3 100644 --- a/.eslintignore +++ b/.eslintignore @@ -2,6 +2,7 @@ /blueprints/*/files/ # compiled output +/declarations/ /dist/ # misc diff --git a/.husky/_/pre-push b/.husky/_/pre-push new file mode 100755 index 0000000..3b35b96 --- /dev/null +++ b/.husky/_/pre-push @@ -0,0 +1,56 @@ +#!/bin/sh + +if [ "$LEFTHOOK_VERBOSE" = "1" -o "$LEFTHOOK_VERBOSE" = "true" ]; then + set -x +fi + +if [ "$LEFTHOOK" = "0" ]; then + exit 0 +fi + +call_lefthook() +{ + dir="$(git rev-parse --show-toplevel)" + osArch=$(uname | tr '[:upper:]' '[:lower:]') + cpuArch=$(uname -m | sed 's/aarch64/arm64/') + + if test -n "$LEFTHOOK_BIN" + then + "$LEFTHOOK_BIN" "$@" + elif lefthook -h >/dev/null 2>&1 + then + lefthook "$@" + elif test -f "$dir/node_modules/lefthook/bin/index.js" + then + "$dir/node_modules/lefthook/bin/index.js" "$@" + elif test -f "$dir/node_modules/@evilmartians/lefthook/bin/lefthook_${osArch}_${cpuArch}/lefthook" + then + "$dir/node_modules/@evilmartians/lefthook/bin/lefthook_${osArch}_${cpuArch}/lefthook" "$@" + elif test -f "$dir/node_modules/@evilmartians/lefthook-installer/bin/lefthook_${osArch}_${cpuArch}/lefthook" + then + "$dir/node_modules/@evilmartians/lefthook-installer/bin/lefthook_${osArch}_${cpuArch}/lefthook" "$@" + + elif bundle exec lefthook -h >/dev/null 2>&1 + then + bundle exec lefthook "$@" + elif yarn lefthook -h >/dev/null 2>&1 + then + yarn lefthook "$@" + elif pnpm lefthook -h >/dev/null 2>&1 + then + pnpm lefthook "$@" + elif swift package plugin lefthook >/dev/null 2>&1 + then + swift package --disable-sandbox plugin lefthook "$@" + elif command -v mint >/dev/null 2>&1 + then + mint run csjones/lefthook-plugin "$@" + elif command -v npx >/dev/null 2>&1 + then + npx lefthook "$@" + else + echo "Can't find lefthook in PATH" + fi +} + +call_lefthook run "pre-push" "$@" diff --git a/.husky/_/prepare-commit-msg b/.husky/_/prepare-commit-msg new file mode 100755 index 0000000..2485ceb --- /dev/null +++ b/.husky/_/prepare-commit-msg @@ -0,0 +1,56 @@ +#!/bin/sh + +if [ "$LEFTHOOK_VERBOSE" = "1" -o "$LEFTHOOK_VERBOSE" = "true" ]; then + set -x +fi + +if [ "$LEFTHOOK" = "0" ]; then + exit 0 +fi + +call_lefthook() +{ + dir="$(git rev-parse --show-toplevel)" + osArch=$(uname | tr '[:upper:]' '[:lower:]') + cpuArch=$(uname -m | sed 's/aarch64/arm64/') + + if test -n "$LEFTHOOK_BIN" + then + "$LEFTHOOK_BIN" "$@" + elif lefthook -h >/dev/null 2>&1 + then + lefthook "$@" + elif test -f "$dir/node_modules/lefthook/bin/index.js" + then + "$dir/node_modules/lefthook/bin/index.js" "$@" + elif test -f "$dir/node_modules/@evilmartians/lefthook/bin/lefthook_${osArch}_${cpuArch}/lefthook" + then + "$dir/node_modules/@evilmartians/lefthook/bin/lefthook_${osArch}_${cpuArch}/lefthook" "$@" + elif test -f "$dir/node_modules/@evilmartians/lefthook-installer/bin/lefthook_${osArch}_${cpuArch}/lefthook" + then + "$dir/node_modules/@evilmartians/lefthook-installer/bin/lefthook_${osArch}_${cpuArch}/lefthook" "$@" + + elif bundle exec lefthook -h >/dev/null 2>&1 + then + bundle exec lefthook "$@" + elif yarn lefthook -h >/dev/null 2>&1 + then + yarn lefthook "$@" + elif pnpm lefthook -h >/dev/null 2>&1 + then + pnpm lefthook "$@" + elif swift package plugin lefthook >/dev/null 2>&1 + then + swift package --disable-sandbox plugin lefthook "$@" + elif command -v mint >/dev/null 2>&1 + then + mint run csjones/lefthook-plugin "$@" + elif command -v npx >/dev/null 2>&1 + then + npx lefthook "$@" + else + echo "Can't find lefthook in PATH" + fi +} + +call_lefthook run "prepare-commit-msg" "$@" diff --git a/.husky/pre-commit b/.husky/pre-commit deleted file mode 100755 index 7b08d54..0000000 --- a/.husky/pre-commit +++ /dev/null @@ -1,7 +0,0 @@ -#!/bin/sh -. "$(dirname "$0")/_/husky.sh" - -pnpm run lint -pnpm run test:duplication -pnpm run test:ember --filter '!Acceptance' -# pnpm run verify-coverage 'dry-run' \ No newline at end of file diff --git a/README.md b/README.md index 1a01d7f..62b360d 100644 --- a/README.md +++ b/README.md @@ -112,11 +112,6 @@ Testing mocks are split in the `tests` folders. - `pnpm lint` - `pnpm lint:fix` -### Duplication - -- `pnpm test:duplication` - - ### Building - `ember build` (development) diff --git a/app/adapters/application.ts b/app/adapters/application.ts deleted file mode 100644 index 09aa041..0000000 --- a/app/adapters/application.ts +++ /dev/null @@ -1,72 +0,0 @@ -import { service } from '@ember/service'; -import JSONAPIAdapter from '@ember-data/adapter/json-api'; - -import config from '../config/environment'; - -import type SessionService from 'ember-boilerplate/services/session'; -import type FlashMessageService from 'ember-cli-flash/services/flash-messages'; - -export default class ApplicationAdapter extends JSONAPIAdapter { - @service declare session: SessionService; - @service declare flashMessages: FlashMessageService; - - get host() { - return config.host; - } - namespace = config.namespace; - - get headers(): Record { - const headers = { - Accept: 'application/vnd.api+json', - 'Content-Type': 'application/vnd.api+json', - Authorization: '', - }; - - if (this.session.isAuthenticated) { - headers[ - 'Authorization' - ] = `Bearer ${this.session.data.authenticated.accessToken}`; - } - - return headers; - } - - async handleResponse( - status: number, - headers: Record, - payload: Record, - requestData: Record - ) { - if (status === 401 && this.session.isAuthenticated) { - this.flashMessages.danger(`Unauthorized action`); - await this.session.invalidate(); - } else { - if (status > 500) { - // Internal - this.flashMessages.danger(`Fatal error : ${payload}`); - } else if (status > 400) { - // Bad request - } - } - - return super.handleResponse(status, headers, payload, requestData); - } - - urlForQueryRecord( - query: Record, - modelName: string | number - ): string { - const id = query['id'] as string | number; - - delete query['id']; - - return this.buildURL(modelName, id, null, 'findRecord', query); - } -} - -// DO NOT DELETE: this is how TypeScript knows how to look up your adapters. -declare module 'ember-data/types/registries/adapter' { - export default interface AdapterRegistry { - application: ApplicationAdapter; - } -} diff --git a/app/adapters/user.ts b/app/adapters/user.ts deleted file mode 100644 index a4c74de..0000000 --- a/app/adapters/user.ts +++ /dev/null @@ -1,25 +0,0 @@ -import JSONAPIAdapter from '../adapters/application'; - -export default class User extends JSONAPIAdapter { - urlForQueryRecord( - query: Record, - modelName: string | number - ) { - if (query['profile']) { - delete query['profile']; - - const url = `${this.host}/${this.namespace}/users/profile`; - - return url; - } - - return super.urlForQueryRecord(query, modelName); - } -} - -// DO NOT DELETE: this is how TypeScript knows how to look up your adapters. -declare module 'ember-data/types/registries/adapter' { - export default interface AdapterRegistry { - user: User; - } -} diff --git a/app/handlers/users.ts b/app/handlers/users.ts index f05ec18..d0fef75 100644 --- a/app/handlers/users.ts +++ b/app/handlers/users.ts @@ -13,15 +13,12 @@ export const usersHandlers= [ http.get('http://localhost:8080/api/v1/users/profile', () => { return HttpResponse.json({ data: { - type: 'users', id: '1', - attributes: { - email: '', - firstName: '', - lastName: '', - phone: '', - role: '', - }, + email: '', + firstName: '', + lastName: '', + phone: '', + role: '', }, }); }), @@ -33,8 +30,7 @@ export const usersHandlers= [ http.post('http://localhost:8080/api/v1/users', () => { return HttpResponse.json({ data: { - type: 'users', - attributes: {} + } }); }) diff --git a/app/models/document.ts b/app/models/document.ts index caac5ea..ac0be0f 100644 --- a/app/models/document.ts +++ b/app/models/document.ts @@ -1,6 +1,7 @@ import Model, { attr, belongsTo } from '@ember-data/model'; import type UserModel from './user'; +import { ResourceType } from '@warp-drive/core-types/symbols'; export default class DocumentModel extends Model { @attr() declare filename: string; @@ -15,10 +16,6 @@ export default class DocumentModel extends Model { async: false, inverse: 'documents', }) declare user: UserModel; -} -declare module 'ember-data/types/registries/model' { - export default interface ModelRegistry { - document: DocumentModel; - } + [ResourceType] = 'document' as const; } diff --git a/app/models/user.ts b/app/models/user.ts index 6cadfba..931941a 100644 --- a/app/models/user.ts +++ b/app/models/user.ts @@ -1,22 +1,18 @@ -import Model, { attr, hasMany, type SyncHasMany } from '@ember-data/model'; - +import Model, { attr, hasMany } from '@ember-data/model'; import type DocumentModel from './document'; +import { ResourceType } from '@warp-drive/core-types/symbols'; export default class UserModel extends Model { - @attr() declare email: string; - @attr() declare firstName: string; - @attr() declare lastName: string; - @attr() declare phone: string; - @attr() declare role: string; - @attr() declare password: string; - @hasMany('document', { + @attr('string') declare email: string; + @attr('string') declare firstName: string; + @attr('string') declare lastName: string; + @attr('string') declare phone: string; + @attr('string') declare role: string; + @attr('string') declare password: string; + @hasMany('document', { async: false, inverse: 'user', - }) declare documents: SyncHasMany; -} + }) declare documents: DocumentModel[]; -declare module 'ember-data/types/registries/model' { - export default interface ModelRegistry { - user: UserModel; - } + [ResourceType] = 'user' as const; } diff --git a/app/modifiers/errors-scroll-up.ts b/app/modifiers/errors-scroll-up.ts index 45dadf9..3e53407 100644 --- a/app/modifiers/errors-scroll-up.ts +++ b/app/modifiers/errors-scroll-up.ts @@ -1,4 +1,3 @@ -import { later } from '@ember/runloop'; import { runTask } from 'ember-lifeline'; import type { ValidationError } from 'ember-immer-changeset'; diff --git a/app/routes/application.ts b/app/routes/application.ts index b1b1806..0d56573 100644 --- a/app/routes/application.ts +++ b/app/routes/application.ts @@ -1,3 +1,4 @@ +import { setBuildURLConfig } from '@ember-data/request-utils'; import { registerDestructor } from '@ember/destroyable'; import Route from '@ember/routing/route'; import { service } from '@ember/service'; @@ -9,6 +10,11 @@ import type CurrentUserService from 'ember-boilerplate/services/current-user'; import type { IntlService } from 'ember-intl'; import type SessionService from 'ember-simple-auth/services/session'; +setBuildURLConfig({ + host: config.host, + namespace: config.namespace, +}); + export default class Application extends Route { @service declare session: SessionService; @service declare currentUser: CurrentUserService; diff --git a/app/serializers/application.ts b/app/serializers/application.ts deleted file mode 100644 index d6e81cd..0000000 --- a/app/serializers/application.ts +++ /dev/null @@ -1,31 +0,0 @@ -import JSONAPISerializer from '@ember-data/serializer/json-api'; - -import type { Snapshot } from '@ember-data/store'; - -export default class Application extends JSONAPISerializer { - serializeAttribute( - snapshot: Snapshot, - json: Record, - key: string, - attributes: Record - ) { - if (snapshot.record.get('isNew') || snapshot.changedAttributes()[key]) { - super.serializeAttribute(snapshot, json, key, attributes); - } - } - - keyForAttribute(key: string) { - return key; - } - - keyForRelationship(key: string) { - return key; - } -} - -// DO NOT DELETE: this is how TypeScript knows how to look up your serializers. -declare module 'ember-data/types/registries/serializer' { - export default interface SerializerRegistry { - application: Application; - } -} diff --git a/app/services/auth-handler.ts b/app/services/auth-handler.ts new file mode 100644 index 0000000..22722e5 --- /dev/null +++ b/app/services/auth-handler.ts @@ -0,0 +1,17 @@ +import {service} from "@ember/service"; +import type SessionService from "./session"; +import type { NextFn, RequestContext } from "@ember-data/request"; + +export default class AuthHandler { + @service declare session: SessionService; + + request(context: RequestContext, next: NextFn) { + const headers = new Headers(context.request.headers); + headers.append( + 'Authorization', + `Bearer ${this.session.data.authenticated.accessToken}`, + ); + + return next(Object.assign({}, context.request, { headers })); + } +} diff --git a/app/services/changesets/changeset-service.ts b/app/services/changesets/changeset-service.ts deleted file mode 100644 index bf61df3..0000000 --- a/app/services/changesets/changeset-service.ts +++ /dev/null @@ -1,6 +0,0 @@ -import type { Changeset } from 'ember-immer-changeset'; -import type { Promisable } from 'type-fest'; - -export interface ChangesetService { - save(changeset: T): Promisable; -} diff --git a/app/services/changesets/register.ts b/app/services/changesets/register.ts index 8cef921..9d99cde 100644 --- a/app/services/changesets/register.ts +++ b/app/services/changesets/register.ts @@ -1,39 +1,45 @@ import Service from '@ember/service'; import { service } from '@ember/service'; - -import type { ChangesetService } from './changeset-service'; -import type StoreService from '@ember-data/store'; import type { RegisterChangeset } from 'ember-boilerplate/changesets/register'; +import { Result, type Err } from 'true-myth/result'; +import type Store from '@ember-data/store'; import type UserModel from 'ember-boilerplate/models/user'; +import type SafeStore from '../safe-store'; +import { createRecord } from '@ember-data/json-api/request'; +import type { Document } from '@ember-data/store/-private/document'; export default class RegisterChangesetService extends Service - implements ChangesetService { - @service declare store: StoreService; + @service declare safeStore: SafeStore; + @service declare store: Store; - async save(changeset: RegisterChangeset): Promise { + async save(changeset: RegisterChangeset): Promise> { changeset.execute(); const changesetData = changeset.data; - const user = this.store.createRecord('user', { - lastName: changesetData.lastName, - firstName: changesetData.firstName, - phone: changesetData.phone, - email: changesetData.email, - password: changesetData.password, - role: 'user', + let user = this.store.createRecord('user', { + ...changesetData, }); - await user.save(); + let response = await this.safeStore.request>(createRecord(user) as never); - return user; - } -} + if (response.isErr) { + changeset.unexecute(); + for (const iterator of response.error.errors) { + changeset.addError({ + key: iterator.source.pointer, + message: iterator.detail, + value: changeset.get(iterator.source.pointer.split('/')[1]), + originalValue: changeset.get(iterator.source.pointer.split('/')[1]), + }) + } + return response as Err; + } + + await changeset.save(); -declare module '@ember/service' { - interface Registry { - 'changesets/register': RegisterChangesetService; + return response.map((user) => user.content.data!); } } diff --git a/app/services/current-user.ts b/app/services/current-user.ts index a5d26a2..0bacc6d 100644 --- a/app/services/current-user.ts +++ b/app/services/current-user.ts @@ -3,31 +3,30 @@ import Service from '@ember/service'; import { service } from '@ember/service'; import type SessionService from './session'; -import type Store from '@ember-data/store'; -import type FetchService from '@triptyk/ember-utils/services/fetch'; +import type RequestManager from '@ember-data/request'; import type UserModel from 'ember-boilerplate/models/user'; +import type SafeStore from './safe-store'; +import { findRecord } from '@ember-data/json-api/request'; +import { Maybe } from 'true-myth'; export default class CurrentUserService extends Service { @service declare session: SessionService; - @service declare store: Store; - @service declare fetch: FetchService; + @service declare requestManager: RequestManager; + @service declare safeStore: SafeStore; - @tracked public user?: UserModel; + @tracked public user: Maybe = Maybe.nothing(); async load() { if (this.session.isAuthenticated) { - let user = await this.store.queryRecord('user', { profile: true }); + let userResponse = await this.safeStore.request(findRecord('user', 'profile')) - this.user = user; + if (userResponse.isErr) { + return null; + } + + this.user = Maybe.just(userResponse.value.content.data); } return this.user; } } - -// DO NOT DELETE: this is how TypeScript knows how to look up your services. -declare module '@ember/service' { - interface Registry { - 'current-user': CurrentUserService; - } -} diff --git a/app/services/error-handler.ts b/app/services/error-handler.ts index d203c76..be17113 100644 --- a/app/services/error-handler.ts +++ b/app/services/error-handler.ts @@ -11,7 +11,7 @@ export interface TranslatedErrors { export default class ErrorHandlerService extends Service { @service declare flashMessages: FlashMessageService; - public handle(changeset: Changeset, errors: Error[] | string) { + public handle(errors: Error[] | string) { this.flashMessages.danger(`${errors}`); } } diff --git a/app/services/head-data.ts b/app/services/head-data.ts index b717ecb..c0b86a9 100644 --- a/app/services/head-data.ts +++ b/app/services/head-data.ts @@ -11,11 +11,3 @@ export default class HeadDataService extends Service { return config.applicationName; } } - -// DO NOT DELETE: this is how TypeScript knows how to look up your services. -declare module '@ember/service' { - // eslint-disable-next-line no-unused-vars - interface Registry { - 'head-data': HeadDataService; - } -} diff --git a/app/services/request-manager.ts b/app/services/request-manager.ts new file mode 100644 index 0000000..85bb218 --- /dev/null +++ b/app/services/request-manager.ts @@ -0,0 +1,24 @@ +import RequestManager, { type Handler,type NextFn,type RequestContext,type RequestInfo } from "@ember-data/request"; +import { setOwner } from "@ember/owner"; +import { getOwner } from "@ember/owner"; +import AuthHandler from "./auth-handler"; +import Fetch from "@ember-data/request/fetch"; + +const TestHandler: Handler = { + async request(context: RequestContext, next: NextFn) { + console.log('TestHandler.request', context.request); + const result = await next(Object.assign({}, context.request)); + console.log('TestHandler.response after fetch', result.response); + return result; + }, +}; + + +export default class extends RequestManager { + constructor(args: {}) { + super(args); + const authHandler = new AuthHandler(); + setOwner(authHandler, getOwner(this)!); + this.use([authHandler,TestHandler, Fetch]); + } +} diff --git a/app/services/safe-store.ts b/app/services/safe-store.ts new file mode 100644 index 0000000..7f8bde2 --- /dev/null +++ b/app/services/safe-store.ts @@ -0,0 +1,15 @@ +import type { Future, StructuredDataDocument } from "@ember-data/request"; +import type { StoreRequestInput } from "@ember-data/store"; +import type Store from "@ember-data/store"; +import {service} from "@ember/service"; +import Service from "@ember/service"; +import { toResult } from "ember-boilerplate/utils/result-utils"; +import type Result from "true-myth/result"; + +export default class SafeStore extends Service { + @service declare store: Store; + + request(requestConfig: StoreRequestInput): Promise, AggregateError>> { + return toResult(this.store.request(requestConfig), [AggregateError]); + } +} diff --git a/app/services/session.ts b/app/services/session.ts index eba7e93..981249d 100644 --- a/app/services/session.ts +++ b/app/services/session.ts @@ -23,10 +23,3 @@ export default class SessionService extends BaseSessionService { } } } - -// DO NOT DELETE: this is how TypeScript knows how to look up your services. -declare module '@ember/service' { - interface Registry { - session: SessionService; - } -} diff --git a/app/services/store.js b/app/services/store.js index f672664..7c8b681 100644 --- a/app/services/store.js +++ b/app/services/store.js @@ -1,44 +1,7 @@ -import JSONAPICache from '@ember-data/json-api'; -import { LegacyNetworkHandler } from '@ember-data/legacy-compat'; -import { FetchManager } from '@ember-data/legacy-compat/-private'; -import { buildSchema, instantiateRecord, modelFor, teardownRecord } from '@ember-data/model/hooks'; -import RequestManager from '@ember-data/request'; -import Fetch from '@ember-data/request/fetch'; -import BaseStore, { CacheHandler, recordIdentifierFor } from '@ember-data/store'; +// eslint-disable-next-line ember/use-ember-data-rfc-395-imports +import Store from 'ember-data/store'; +import { service } from '@ember/service'; -export default class Store extends BaseStore { - constructor(args) { - super(args); - this.requestManager = new RequestManager(); - this.requestManager.use([LegacyNetworkHandler, Fetch]); - this.requestManager.useCache(CacheHandler); - this.registerSchema(buildSchema(this)); - } - - createCache(storeWrapper) { - return new JSONAPICache(storeWrapper); - } - - instantiateRecord( - identifier, - createRecordArgs - ) { - return instantiateRecord.call(this, identifier, createRecordArgs); - } - - teardownRecord(record) { - teardownRecord.call(this, record); - } - - modelFor(type) { - return modelFor.call(this, type) || super.modelFor(type); - } - - serializeRecord(record, options) { - if (!this._fetchManager) { - this._fetchManager = new FetchManager(this); - } - - return this._fetchManager.createSnapshot(recordIdentifierFor(record)).serialize(options); - } +export default class AppStore extends Store { + @service requestManager; } diff --git a/app/templates/register.gts b/app/templates/register.gts index c40787f..95b64aa 100644 --- a/app/templates/register.gts +++ b/app/templates/register.gts @@ -41,14 +41,15 @@ class RegisterRouteComponent extends Component @action async saveRegister(changeset: RegisterChangeset) { - try { - await this.register.save(changeset); - this.flashMessages.success('components.pages.register.success_message'); - } catch (e: any) { - const error = await e; + const user = await this.register.save(changeset); - this.errorHandler.handle(changeset, error.errors); + if (user.isErr) { + console.log(user.error.message); + + return this.errorHandler.handle(user.error.message); } + + return this.flashMessages.success('components.pages.register.success_message'); }