chore: Extract authentication logic of the apps to their own classes
This commit is contained in:

committed by
Ömer Faruk Aydın

parent
6b1dee053f
commit
46321f19f4
38
packages/backend/src/apps/postgresql/authentication.ts
Normal file
38
packages/backend/src/apps/postgresql/authentication.ts
Normal file
@@ -0,0 +1,38 @@
|
||||
import { Client } from 'pg';
|
||||
import App from '../../models/app';
|
||||
|
||||
export default class Authentication {
|
||||
client: any
|
||||
connectionData: any
|
||||
appData: any
|
||||
|
||||
constructor(connectionData: any) {
|
||||
this.client = new Client({
|
||||
host: connectionData.host,
|
||||
port: connectionData.port,
|
||||
database: connectionData.database,
|
||||
user: connectionData.username,
|
||||
password: connectionData.password,
|
||||
})
|
||||
|
||||
this.connectionData = connectionData;
|
||||
this.appData = App.findOneByKey('postgresql');
|
||||
}
|
||||
|
||||
async verifyCredentials() {
|
||||
await this.client.connect()
|
||||
|
||||
return {
|
||||
screenName: this.connectionData.database
|
||||
}
|
||||
}
|
||||
|
||||
async isStillVerified() {
|
||||
try {
|
||||
await this.client.connect()
|
||||
return true;
|
||||
} catch(error) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,38 +1,9 @@
|
||||
import { Client } from 'pg';
|
||||
import App from '../../models/app';
|
||||
import Authentication from './authentication'
|
||||
|
||||
export default class PostgreSQL {
|
||||
client: any
|
||||
connectionData: any
|
||||
appData: any
|
||||
authenticationClient: any;
|
||||
|
||||
constructor(connectionData: any) {
|
||||
this.client = new Client({
|
||||
host: connectionData.host,
|
||||
port: connectionData.port,
|
||||
database: connectionData.database,
|
||||
user: connectionData.username,
|
||||
password: connectionData.password,
|
||||
})
|
||||
|
||||
this.connectionData = connectionData;
|
||||
this.appData = App.findOneByKey('postgresql');
|
||||
}
|
||||
|
||||
async verifyCredentials() {
|
||||
await this.client.connect()
|
||||
|
||||
return {
|
||||
screenName: this.connectionData.database
|
||||
}
|
||||
}
|
||||
|
||||
async isStillVerified() {
|
||||
try {
|
||||
await this.client.connect()
|
||||
return true;
|
||||
} catch(error) {
|
||||
return false
|
||||
}
|
||||
this.authenticationClient = new Authentication(connectionData);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user