mirror of
https://github.com/formbricks/formbricks.git
synced 2026-01-05 21:32:02 -06:00
fix: Air table callback (#1418)
This commit is contained in:
committed by
GitHub
parent
acb8dd0d0b
commit
6911151e98
@@ -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({
|
||||
|
||||
@@ -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: {
|
||||
|
||||
Reference in New Issue
Block a user