refactor: Use http client to authenticate typeform
This commit is contained in:
@@ -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,
|
||||
|
Reference in New Issue
Block a user