From c4394228f28f355cda7b13fe2e378fb2dcce858f Mon Sep 17 00:00:00 2001 From: Faruk AYDIN Date: Sun, 22 Oct 2023 23:03:16 +0200 Subject: [PATCH] fix(placetel): Authenticate in case valid user without device --- .../apps/pushover/auth/verify-credentials.ts | 20 ++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/packages/backend/src/apps/pushover/auth/verify-credentials.ts b/packages/backend/src/apps/pushover/auth/verify-credentials.ts index 2eabac57..3dd9440d 100644 --- a/packages/backend/src/apps/pushover/auth/verify-credentials.ts +++ b/packages/backend/src/apps/pushover/auth/verify-credentials.ts @@ -1,11 +1,21 @@ import { IGlobalVariable } from '@automatisch/types'; +import HttpError from '../../../errors/http'; const verifyCredentials = async ($: IGlobalVariable) => { - await $.http.post(`/1/messages.json`, { - token: $.auth.data.apiToken as string, - user: $.auth.data.userKey as string, - message: 'hello world', - }); + try { + await $.http.post(`/1/users/validate.json`, { + token: $.auth.data.apiToken as string, + user: $.auth.data.userKey as string, + }); + } catch (error) { + const noDeviceError = 'user is valid but has no active devices'; + const hasNoDeviceError = + error.response?.data?.errors?.includes(noDeviceError); + + if (!hasNoDeviceError) { + throw new HttpError(error); + } + } await $.auth.set({ screenName: $.auth.data.screenName,