refactor: Use http client to authenticate typeform

This commit is contained in:
Faruk AYDIN
2022-07-16 00:54:55 +03:00
parent 903b0f52b9
commit 7cf1bfffbc
2 changed files with 13 additions and 5 deletions

View File

@@ -1,5 +1,6 @@
import Context from '../../types/express/context';
import App from '../../models/app';
import axios from 'axios';
type Params = {
input: {
@@ -22,11 +23,19 @@ const createAuthData = async (
const appClass = (await import(`../../apps/${connection.key}`)).default;
const appData = App.findOneByKey(connection.key);
if (!connection.formattedData) { return null; }
if (!connection.formattedData) {
return null;
}
const appInstance = new appClass(appData, connection.formattedData);
const authLink = await appInstance.authenticationClient.createAuthData();
try {
await axios.get(authLink.url);
} catch (error) {
throw new Error('Error occured while creating authorization URL!');
}
await connection.$query().patch({
formattedData: {
...connection.formattedData,