Skip to content

Commit

Permalink
fix(devtools): failing auth status checks (#6059)
Browse files Browse the repository at this point in the history
  • Loading branch information
aliemir committed Jun 20, 2024
1 parent df4f614 commit ad42665
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 5 deletions.
10 changes: 10 additions & 0 deletions .changeset/hip-ears-shave.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
"@refinedev/devtools-server": patch
"@refinedev/devtools-ui": patch
---

fix(devtools-server): missing header check on auth requests

Devtools was failing to determine the auth status and always end up redirecting to the login page regardless of the actual auth status. This was due to the missing check on the auth request that was causing all valid responses treated as unauthenticated.

Resolves [#6047](https://github.com/refinedev/refine/issues/6047)
10 changes: 10 additions & 0 deletions .changeset/wet-pianos-arrive.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
"@refinedev/cli": patch
"@refinedev/devtools": patch
---

fix(devtools): failing authentication checks

Devtools was failing on determining the auth status and always ended up redirecting to the login page or the onboarding step regardless of the actual authentication status.

Resolves [#6047](https://github.com/refinedev/refine/issues/6047)
2 changes: 1 addition & 1 deletion packages/devtools-server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
"build": "pnpm build:client && tsup && node ../shared/generate-declarations.js",
"build:client": "NODE_ENV=production tsc && vite build --config src/client/vite.config.ts",
"dev": "pnpm dev:client & tsup --watch",
"dev:client": "vite build --watch --force --config src/client/vite.config.ts",
"dev:client": "vite build --watch --config src/client/vite.config.ts",
"prepare": "pnpm build",
"publint": "publint --strict=true --level=suggestion",
"start:server": "node dist/cli.cjs",
Expand Down
1 change: 1 addition & 0 deletions packages/devtools-server/src/serve-proxy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@ export const serveProxy = async (app: Express) => {
if (proxyRes.statusCode === 401) {
res.writeHead(200, {
...proxyRes.headers,
"Refine-Is-Authenticated": "false",
"Access-Control-Expose-Headers": `Refine-Is-Authenticated, ${proxyRes.headers["Access-Control-Expose-Headers"]}`,
});
} else {
Expand Down
1 change: 1 addition & 0 deletions packages/devtools-ui/src/components/header-auth-status.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ export const HeaderAuthStatus = () => {
<Gravatar
email={me?.email ?? ""}
size={32}
protocol="https://"
style={{ borderRadius: "50%" }}
/>
<div
Expand Down
7 changes: 5 additions & 2 deletions packages/devtools-ui/src/utils/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,11 @@ import { ory } from "./ory";
export const isAuthenticated = async () => {
try {
const response = await ory.toSession();
const headerAuth = Boolean(response.headers["Refine-Is-Authenticated"]);
return headerAuth;
const authenticatedHeader = response.headers["refine-is-authenticated"];
if (authenticatedHeader === "false") {
return false;
}
return true;
} catch (error: any) {
return false;
}
Expand Down
8 changes: 6 additions & 2 deletions packages/devtools-ui/src/utils/me.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,13 @@ export const getMe = async () => {
try {
const response = await fetch("/api/.refine/users/me");

const data = (await response.json()) as MeResponse;
if (response.ok) {
const data = (await response.json()) as MeResponse;

return data;
return data;
}

return null;
} catch (_) {
//
}
Expand Down

0 comments on commit ad42665

Please sign in to comment.