Skip to content

Commit

Permalink
fix(devtools): prevent 401 errors from polluting user console
Browse files Browse the repository at this point in the history
  • Loading branch information
aliemir committed May 8, 2024
1 parent 9d9f375 commit 86f2797
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
11 changes: 10 additions & 1 deletion packages/devtools-server/src/serve-proxy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,16 @@ export const serveProxy = async (app: Express) => {
saveAuth(token, jwt);
})(proxyRes, req, res);
}
res.writeHead(proxyRes.statusCode || 500, proxyRes.headers);

if (proxyRes.statusCode === 401) {
res.writeHead(200, {
...proxyRes.headers,
"Access-Control-Expose-Headers": `Refine-Is-Authenticated, ${proxyRes.headers["Access-Control-Expose-Headers"]}`,
});
} else {
res.writeHead(proxyRes.statusCode || 500, proxyRes.headers);
}

proxyRes.pipe(res, { end: true });
},
});
Expand Down
5 changes: 3 additions & 2 deletions packages/devtools-ui/src/utils/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ import { ory } from "./ory";

export const isAuthenticated = async () => {
try {
await ory.toSession();
return true;
const response = await ory.toSession();
const headerAuth = Boolean(response.headers["Refine-Is-Authenticated"]);
return headerAuth;
} catch (error: any) {
return false;
}
Expand Down

0 comments on commit 86f2797

Please sign in to comment.