[BUG] - Redirects to api endpoint when Google calendar access is denied
Issue Summary
While installing Google Calendar app on cal.com, if we press cancel button on google oAuth screen, we are redirected to a page which says {"message":"`code` must be a string"}
Steps to Reproduce
- Go to App store on cal.com
- Select Google Calendar (Make sure it is already not installed)
- Click on Install App button on right side of screen
- Select your google account
- Click on Cancel button
Actual Results
{"message":"`code` must be a string"}
Expected Results
- Should redirect back to app store of cal.com with error saying, permission denied
Evidence
- Link: Error Link
- Screenshot:
I have fixed the bug, do check it out!!
@Quanta-Naut @sy425191
i have checked it and it still showing the error : {"message":"code must be a string"}
and redirected page is : https://app.cal.com/api/integrations/googlecalendar/callback?error=access_denied&state=%7B%22returnTo%22:%22https://app.cal.com/apps/installed/calendar?hl%3Dgoogle-calendar%22%7D
but if user does not give access to google calender it should redirect to url where it has started installing google calender which is : https://app.cal.com/apps/google-calendar
i have checked the code in callback.ts file path : packages\app-store\googlecalendar\api\callback.ts
async function getHandler(req: NextApiRequest, res: NextApiResponse) { const { code ,error} = req.query; const state = decodeOAuthState(req);
// Check if the user denied permission
if (error === "access_denied") {
// Redirect to a custom URL when access is denied
return res.redirect("https://app.cal.com/apps/google-calendar");
}
//this was the code running and showing :{"message":"`code` must be a string"}
if (typeof code !== "string") {
throw new HttpError({ statusCode: 400, message: "`code` must be a string" });
}
i have added this extra check to redirect to initial url if error === access_denied , but i am not able to check it on my developement environment and new to this so i am not so confident , i hope somebody find it helpful
Try this out Instead of checking for "access denied", Try
//if code is false, the user has canceled the auth
if (!code) {
return res.redirect("${WEBAPP_URL_FOR_OAUTH}/apps/google-calendar");
}
This worked well in my dev env.
@PeerRich I think the issue is resolved because I tried reproducing it yesterday. I was facing this same issue in the production and development web app, but today I tried to reproduce it in development to resolve this issue, and it worked fine. Then I tried a real web app cal.com even there, it was working fine.
I think you should close this issue.
Thanks.