feat(ntfy): add auth support
This commit is contained in:
39
packages/backend/src/apps/ntfy/auth/index.ts
Normal file
39
packages/backend/src/apps/ntfy/auth/index.ts
Normal file
@@ -0,0 +1,39 @@
|
||||
import verifyCredentials from './verify-credentials';
|
||||
import isStillVerified from './is-still-verified';
|
||||
|
||||
export default {
|
||||
fields: [
|
||||
{
|
||||
key: 'serverUrl',
|
||||
label: 'Server URL',
|
||||
type: 'string' as const,
|
||||
required: true,
|
||||
readOnly: false,
|
||||
value: 'https://ntfy.sh',
|
||||
placeholder: null,
|
||||
description: 'ntfy server to use.',
|
||||
clickToCopy: false,
|
||||
},
|
||||
{
|
||||
key: 'username',
|
||||
label: 'Username',
|
||||
type: 'string' as const,
|
||||
required: false,
|
||||
readOnly: false,
|
||||
placeholder: null,
|
||||
clickToCopy: false,
|
||||
},
|
||||
{
|
||||
key: 'password',
|
||||
label: 'Password',
|
||||
type: 'string' as const,
|
||||
required: false,
|
||||
readOnly: false,
|
||||
placeholder: null,
|
||||
clickToCopy: false,
|
||||
},
|
||||
],
|
||||
|
||||
verifyCredentials,
|
||||
isStillVerified,
|
||||
};
|
||||
9
packages/backend/src/apps/ntfy/auth/is-still-verified.ts
Normal file
9
packages/backend/src/apps/ntfy/auth/is-still-verified.ts
Normal file
@@ -0,0 +1,9 @@
|
||||
import { IGlobalVariable } from '@automatisch/types';
|
||||
import verifyCredentials from './verify-credentials';
|
||||
|
||||
const isStillVerified = async ($: IGlobalVariable) => {
|
||||
await verifyCredentials($);
|
||||
return true;
|
||||
};
|
||||
|
||||
export default isStillVerified;
|
||||
16
packages/backend/src/apps/ntfy/auth/verify-credentials.ts
Normal file
16
packages/backend/src/apps/ntfy/auth/verify-credentials.ts
Normal file
@@ -0,0 +1,16 @@
|
||||
import { IGlobalVariable } from '@automatisch/types';
|
||||
|
||||
const verifyCredentials = async ($: IGlobalVariable) => {
|
||||
await $.http.post('/', { topic: 'automatisch' });
|
||||
let screenName = $.auth.data.serverUrl;
|
||||
|
||||
if ($.auth.data.username) {
|
||||
screenName = `${$.auth.data.username} @ ${screenName}`
|
||||
}
|
||||
|
||||
await $.auth.set({
|
||||
screenName,
|
||||
});
|
||||
};
|
||||
|
||||
export default verifyCredentials;
|
||||
Reference in New Issue
Block a user