Skip to content

armgit / macro

Public Imported from GitHub
0

Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.

feat(devx): playwright auto auth (#1056)

Will Hutchinson475ea22a6cc1
diff --git a/js/app/AGENTS.md b/js/app/AGENTS.md
index 60973b51a0..df72287465 100644
--- a/js/app/AGENTS.md
+++ b/js/app/AGENTS.md
@@ -17,9 +17,44 @@
- You can use the playwright MCP to debug and verify UI changes and general app behavior.
- Delegate to the user to run the app locally and authenticate.
- The app will likely run on `localhost:3000/app`
+- When asked to navigate to "the app" with Playwright, go to `/app/component/unified-list` to avoid the signup flow.
+- **Before navigating with Playwright**, always generate an access token first using `bun scripts/generate-access-token.ts` or prompt the user to authenticate. Never navigate without authentication set up.
- You can use `console.trace` to debug state and changes in the ui and logic.
- When building out UI features, use playwright to verify UI behavior.
+### Playwright Authentication
+The app uses cookie-based authentication (`credentials: 'include'`) since `ENABLE_BEARER_TOKEN_AUTH` is false. For Playwright testing, intercept requests and add the Authorization header.
+
+**Steps to authenticate in Playwright:**
+1. Run `bun scripts/generate-access-token.ts` to get an access token (requires `.env` with `REFRESH_TOKEN` and `FUSIONAUTH_DOMAIN`)
+2. Use `browser_run_code` to set up request interception **before** navigating:
+ ```javascript
+ async (page) => {
+ const token = "YOUR_ACCESS_TOKEN_HERE";
+ await page.route('**/*.macro.com/**', async (route) => {
+ const headers = {
+ ...route.request().headers(),
+ 'Authorization': `Bearer ${token}`
+ };
+ await route.continue({ headers });
+ });
+ }
+ ```
+3. Navigate to `http://localhost:3000/app/component/unified-list` - you will likely be redirected to `/app/signup` initially
+4. **Force navigate again** to `http://localhost:3000/app/component/unified-list` using `browser_run_code`:
+ ```javascript
+ async (page) => {
+ await page.goto('http://localhost:3000/app/component/unified-list', { waitUntil: 'domcontentloaded' });
+ return page.url();
+ }
+ ```
+ This second navigation will work because the route interception is now active and auth requests succeed.
+5. Always dismiss/disallow browser notification prompts by default unless otherwise specified
+
+**Why this is needed:** The app checks authentication via API calls to `.macro.com` endpoints using `credentials: 'include'`. Without valid cookies or an auth header, `useIsAuthenticated()` returns false and the `Soup` component redirects to `/` → `/signup`. The initial redirect happens before route interception can authenticate the first requests, but forcing a second navigation resolves this.
+
+**Note:** WebSocket connections (for real-time features) won't be authenticated with this approach since Playwright's route interception only works for HTTP/HTTPS. This is fine for most UI testing scenarios.
+
## Code Styles
1. Avoid using `blockSignals`, `blockMemos`, `blockResources` etc... They are deprecated.
2. Primitive UI components should be pure, and prefer composition over props vs complex global state or context.
diff --git a/js/app/README.md b/js/app/README.md
index 4f89e5d0ca..951f27f373 100644
--- a/js/app/README.md
+++ b/js/app/README.md
@@ -12,6 +12,8 @@ If you have the [nix](https://nixos.org/learn/) package manager installed on you
`nix develop`
+## Using Claude/Playwright
+To setup the authentication please make sure you create a `.env` file with **REFRESH_TOKEN** environment variable set to your dev macro refresh token. This can be found in your cookies.
## Tauri 🤝 Macro
diff --git a/js/app/scripts/generate-access-token.ts b/js/app/scripts/generate-access-token.ts
new file mode 100644
index 0000000000..80be868a44
--- /dev/null
+++ b/js/app/scripts/generate-access-token.ts
@@ -0,0 +1,44 @@
+import { config } from "dotenv";
+
+// Load environment variables from .env file
+config();
+
+const FUSIONAUTH_DOMAIN = process.env.FUSIONAUTH_DOMAIN ?? "https://fusionauth-dev.macro.com";
+
+async function generateAccessToken(): Promise<string> {
+ const refreshToken = process.env.REFRESH_TOKEN;
+
+ if (!refreshToken) {
+ throw new Error("REFRESH_TOKEN environment variable is not set");
+ }
+
+ const response = await fetch(`${FUSIONAUTH_DOMAIN}/api/jwt/refresh`, {
+ method: "POST",
+ headers: {
+ "Content-Type": "application/json",
+ },
+ body: JSON.stringify({
+ token: "garbage", // we only need to pass in a valid refresh token to FA
+ refreshToken: refreshToken,
+ }),
+ });
+
+ if (!response.ok) {
+ const errorText = await response.text();
+ throw new Error(
+ `Failed to generate access token: ${response.status} ${response.statusText}\n${errorText}`
+ );
+ }
+
+ const data = await response.json();
+
+ if (!data.token) {
+ throw new Error("Response did not contain a token");
+ }
+
+ return data.token;
+}
+
+const token = await generateAccessToken();
+console.log("Access Token:");
+console.log(token);