Skip to content

Commit

Permalink
refactor(devtools): updated authentication flow (#6098)
Browse files Browse the repository at this point in the history
  • Loading branch information
aliemir authored Jul 4, 2024
1 parent da30241 commit 8bc2c1c
Show file tree
Hide file tree
Showing 32 changed files with 388 additions and 473 deletions.
8 changes: 8 additions & 0 deletions .changeset/cuddly-wasps-boil.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
"@refinedev/devtools-server": patch
"@refinedev/devtools-ui": patch
---

refactor(devtools): updated flow for login callbacks

Previously, when the login flow had an error, the Devtools UI was displaying it in the secondary window, which was not user-friendly and lead to multiple clients to connect unnecessarily. This change updates the flow to display the error message in the main Devtools window.
7 changes: 7 additions & 0 deletions .changeset/curly-peas-swim.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"@refinedev/devtools-ui": patch
---

chore(devtools-ui): fix slider image loader

In the welcome page of the Devtools UI, feature slider was re-mounting every image at transition, causing polluted network tab in the browser even though the images were cached and loaded already. This change fixes the issue by loading the images only once and reusing them on transition.
7 changes: 7 additions & 0 deletions .changeset/cyan-paws-press.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"@refinedev/cli": patch
---

chore(cli): remove unused command

Previously `@refinedev/cli` had a `proxy` command that is no longer in use and not required in any of the projects. This change removes the command from the CLI without a fallback.
7 changes: 7 additions & 0 deletions .changeset/funny-schools-draw.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"@refinedev/devtools-shared": patch
---

chore(devtools-shared): add login callback events

Added new events to handle login errors on the main devtools window rather than external windows. This change is accompanied by new event handlers in the `@refinedev/devtools-ui` and `@refinedev/devtools-server` packages.
8 changes: 8 additions & 0 deletions .changeset/short-rabbits-flash.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
"@refinedev/devtools-shared": patch
"@refinedev/devtools": patch
---

chore(devtools): update devtools url fallback values

Updated fallback values for the Devtools URL and use single fallback value until its provided by the `@refinedev/devtools-server` when client is connected.
8 changes: 8 additions & 0 deletions .changeset/small-mangos-matter.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
"@refinedev/devtools-server": patch
"@refinedev/devtools-ui": patch
---

refactor(devtools): updated auth flow

Previously, a proxy in the Devtools Server was used as an auth server to handle sign-ins in the localhost (Devtools Server). This change updates the flow and moves the authentication flow to `https://auth.refine.dev` to handle sign-ins and sign-outs. Now the Devtools Server is only responsible for the connection between the auth server and the user interface while also managing the user's session.
7 changes: 7 additions & 0 deletions .changeset/spotty-turkeys-grab.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"@refinedev/devtools-server": patch
---

refactor(devtools-server): handle project id without polluting user console

When project ID is missing in the project, Devtools Server was returning with `400` and `404` status codes, which leads to unwanted logs in the user console. To avoid this, the server now returns a `200` status code with an error message in the response body. This change is accompanied by a new error handler in the `@refinedev/devtools-ui` package to handle the error message and display it in the user interface.
1 change: 0 additions & 1 deletion examples/data-provider-strapi-v4/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@
"@types/react-dom": "^18.0.0",
"@vitejs/plugin-react": "^4.2.1",
"cypress": "^13.6.3",
"http-proxy-middleware": "^2.0.6",
"typescript": "^5.4.2",
"vite": "^5.1.6"
}
Expand Down
1 change: 0 additions & 1 deletion examples/data-provider-strapi/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@
"@types/react": "^18.0.0",
"@types/react-dom": "^18.0.0",
"@vitejs/plugin-react": "^4.2.1",
"http-proxy-middleware": "^2.0.6",
"typescript": "^5.4.2",
"vite": "^5.1.6"
}
Expand Down
2 changes: 1 addition & 1 deletion examples/store/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
"body-scroll-lock": "^4.0.0-beta.0",
"clsx": "^1.1.1",
"cross-env": "^7.0.3",
"http-proxy-middleware": "^2.0.6",
"http-proxy-middleware": "^3.0.0",
"keen-slider": "^6.6.3",
"lodash": "^4.17.21",
"medusa-react": "^0.3.5",
Expand Down
1 change: 0 additions & 1 deletion packages/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@
"globby": "^11.1.0",
"gray-matter": "^4.0.3",
"handlebars": "^4.7.7",
"http-proxy-middleware": "^2.0.6",
"inquirer": "^8.2.5",
"inquirer-autocomplete-prompt": "^2.0.0",
"jscodeshift": "0.15.2",
Expand Down
2 changes: 0 additions & 2 deletions packages/cli/src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import figlet from "figlet";

import checkUpdates from "@commands/check-updates";
import createResource from "@commands/create-resource";
import proxy from "@commands/proxy";
import { build, dev, run, start } from "@commands/runner";
import swizzle from "@commands/swizzle";
import update from "@commands/update";
Expand Down Expand Up @@ -49,7 +48,6 @@ const bootstrap = () => {
run(program);
checkUpdates(program);
whoami(program);
proxy(program);
devtools(program);
add(program);

Expand Down
147 changes: 0 additions & 147 deletions packages/cli/src/commands/proxy/index.ts

This file was deleted.

3 changes: 1 addition & 2 deletions packages/devtools-server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@
"types": "node ../shared/generate-declarations.js"
},
"dependencies": {
"@ory/client": "^1.5.2",
"@refinedev/devtools-shared": "1.1.9",
"body-parser": "^1.20.2",
"boxen": "^5.1.2",
Expand All @@ -58,7 +57,7 @@
"fs-extra": "^10.1.0",
"globby": "^11.1.0",
"gray-matter": "^4.0.3",
"http-proxy-middleware": "^2.0.6",
"http-proxy-middleware": "^3.0.0",
"jscodeshift": "0.15.2",
"lodash": "^4.17.21",
"lodash-es": "^4.17.21",
Expand Down
8 changes: 8 additions & 0 deletions packages/devtools-server/src/constants.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,17 @@
export const DEFAULT_SERVER_PORT = 5001;
export const SERVER_PORT = DEFAULT_SERVER_PORT;

export const AUTH_SERVER_URL = __DEVELOPMENT__
? "https://develop.auth.refine.dev"
: "https://auth.refine.dev";

export const REFINE_API_URL = __DEVELOPMENT__
? "https://develop.cloud.refine.dev"
: "https://cloud2.refine.dev";

export const AUTH_TRIGGER_API_PATH = "/api/login";
export const AUTH_CALLBACK_API_PATH = "/api/login-callback";
export const AUTH_CALLBACK_UI_PATH = "/after-login";

export const FEED_MD_URL =
"https://raw.githubusercontent.com/refinedev/refine/master/packages/devtools-server/FEED.md";
13 changes: 13 additions & 0 deletions packages/devtools-server/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,19 @@ export const server = async ({
});
});

receive(
client as any,
DevtoolsEvent.DEVTOOLS_LOGIN_FAILURE,
({ error, code }) => {
ws.clients.forEach((c) => {
send(c as any, DevtoolsEvent.DEVTOOLS_DISPLAY_LOGIN_FAILURE, {
error,
code,
});
});
},
);

// close connected app if client disconnects
client.on("close", (_, reason) => {
if (__DEVELOPMENT__) {
Expand Down
12 changes: 9 additions & 3 deletions packages/devtools-server/src/serve-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,17 +131,23 @@ export const serveApi = (app: Express, db: Data) => {
});

app.get("/api/project-id/status", async (_, res) => {
const CODES = {
OK: 0,
NOT_FOUND: 1,
ERROR: 2,
};

const projectId = await getProjectIdFromPackageJson();

if (projectId) {
res.status(200).json({ projectId });
res.status(200).json({ projectId, status: CODES.OK });
return;
}
if (projectId === false) {
res.status(404).json({ projectId: null });
res.status(200).json({ projectId: null, status: CODES.NOT_FOUND });
return;
}
res.status(500).json({ projectId: null });
res.status(200).json({ projectId: null, status: CODES.ERROR });
return;
});

Expand Down
Loading

0 comments on commit 8bc2c1c

Please sign in to comment.