Hi everyone,
I am building a React + Express app and deploying it using the Monday CLI (mapps code:push).
I am currently implementing the OAuth flow, but I am stuck in a tedious manual loop regarding the Redirect URI.
The Scenario:
-
Frontend: I initiate the OAuth flow using
window.location.originto build the redirect URI dynamically. -
Backend: In my callback function, I use an environment variable (
MONDAY_VERSION_URL) to validate theredirect_uriduring the token exchange.
The Code:
Frontend (Initiating Auth):
JavaScript
const startOAuth = async () => {
const { data: context } = await monday.get("context");
const currentOrigin = window.location.origin; // This changes on every deploy
const redirectUri = `${currentOrigin}/oauth/callback`;
const authUrl = `https://auth.monday.com/oauth2/authorize?client_id=${
context.app.clientId
}&redirect_uri=${encodeURIComponent(redirectUri)}`;
monday.execute("openLinkInTab", { url: authUrl });
};
Backend (Callback):
TypeScript
export async function oauthCallback(req: Request, res: Response) {
// ... check code ...
// I have to manually update this Env Var after every push
const currentRedirectUri = envManager.get("MONDAY_VERSION_URL");
const response = await fetch("https://auth.monday.com/oauth2/token", {
// ...
body: new URLSearchParams({
// ...
redirect_uri: `${currentRedirectUri}/oauth/callback`,
}),
});
// ... save token ...
}
The Problem: Every time I run mapps code:push, Monday generates a new unique Version URL (e.g., https://random-uuid-v1.monday.app).
This forces me to do the following steps every single time I deploy a change:
-
Run
mapps code:push. -
Copy the new Version URL.
-
Go to Monday App Management -> OAuth and add this new URL to the Redirect URIs list.
-
Update my
MONDAY_VERSION_URLenvironment variable in the code/server.
My Question: Is there a standard way to handle this workflow?
-
Is there a way to use a "fixed" URL for the Redirect URI even when deploying new versions?
-
Or should I be handling the
redirect_urilogic differently so I don't have to update the App Settings and Env Vars on every push?
Any advice on how to streamline this deployment process would be appreciated!