Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(devtools): failing auth status checks #6059

Merged
merged 9 commits into from
Jun 20, 2024
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 -w build --scope @refinedev/devtools-server",
"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
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
Loading