fix: Air table callback (#1418)

This commit is contained in:
Dhruwang Jariwala
2023-10-23 17:56:34 +05:30
committed by GitHub
parent acb8dd0d0b
commit 6911151e98
2 changed files with 13 additions and 2 deletions

View File

@@ -58,7 +58,9 @@ export async function GET(req: NextRequest) {
try {
const key = await fetchAirtableAuthToken(formData);
if (!key) {
return NextResponse.json({ Error: "Failed to fetch Airtable auth token" }, { status: 500 });
}
const email = await getEmail(key.access_token);
await connectAirtable({

View File

@@ -91,8 +91,13 @@ export const fetchAirtableAuthToken = async (formData: Record<string, any>) => {
const tokenRes: unknown = await tokenReq.json();
const { access_token, expires_in, refresh_token } = ZIntegrationAirtableTokenSchema.parse(tokenRes);
const parsedToken = ZIntegrationAirtableTokenSchema.safeParse(tokenRes);
if (!parsedToken.success) {
throw new Error("invalid token format");
return;
}
const { access_token, refresh_token, expires_in } = parsedToken.data;
const expiry_date = new Date();
expiry_date.setSeconds(expiry_date.getSeconds() + expires_in);
@@ -126,6 +131,10 @@ export const getAirtableToken = async (environmentId: string) => {
client_id,
});
if (!newToken) {
throw new Error("Failed to create new token");
}
await createOrUpdateIntegration(environmentId, {
type: "airtable",
config: {