mirror of
https://github.com/webstudio-is/webstudio.git
synced 2026-10-30 16:47:54 +09:00
## Description https://fast-open.development.webstudio.is/error?development-error=0 https://fast-open.development.webstudio.is/error?development-error=1 https://fast-open.development.webstudio.is/error?development-error=2 https://fast-open.development.webstudio.is/error?development-error=3 https://fast-open.development.webstudio.is/error?development-error=4 https://fast-open.development.webstudio.is/error?development-error=5 ## Steps for reproduction 1. click button 2. expect xyz ## Code Review - [ ] hi @kof, I need you to do - conceptual review (architecture, feature-correctness) - detailed review (read every line) - test it on preview ## Before requesting a review - [ ] made a self-review - [ ] added inline comments where things may be not obvious (the "why", not "what") ## Before merging - [ ] tested locally and on preview environment (preview dev login: 5de6) - [ ] updated [test cases](https://github.com/webstudio-is/webstudio/blob/main/apps/builder/docs/test-cases.md) document - [ ] added tests - [ ] if any new env variables are added, added them to `.env` file
54 lines
1.8 KiB
TypeScript
54 lines
1.8 KiB
TypeScript
import { type LoaderFunctionArgs } from "@remix-run/server-runtime";
|
|
import { authenticator } from "~/services/auth.server";
|
|
import { dashboardPath, isDashboard, loginPath } from "~/shared/router-utils";
|
|
import { AUTH_PROVIDERS } from "~/shared/session";
|
|
import { clearReturnToCookie, returnToPath } from "~/services/cookie.server";
|
|
import { preventCrossOriginCookie } from "~/services/no-cross-origin-cookie";
|
|
import { redirect, setNoStoreToRedirect } from "~/services/no-store-redirect";
|
|
import { allowedDestinations } from "~/services/destinations.server";
|
|
|
|
export const loader = async ({ request }: LoaderFunctionArgs) => {
|
|
if (false === isDashboard(request)) {
|
|
throw new Response("Not Found", {
|
|
status: 404,
|
|
});
|
|
}
|
|
preventCrossOriginCookie(request);
|
|
|
|
allowedDestinations(request, ["document"]);
|
|
// CSRF token checks are not necessary for dashboard-only pages.
|
|
// All requests from the builder or canvas app are safeguarded either by preventCrossOriginCookie for fetch requests
|
|
// or by allowedDestinations for iframe requests.
|
|
|
|
const returnTo = (await returnToPath(request)) ?? dashboardPath();
|
|
|
|
try {
|
|
await authenticator.authenticate("github", request, {
|
|
successRedirect: returnTo,
|
|
throwOnError: true,
|
|
});
|
|
} catch (error) {
|
|
// all redirects are basically errors and in that case we don't want to catch it
|
|
if (error instanceof Response) {
|
|
return setNoStoreToRedirect(await clearReturnToCookie(request, error));
|
|
}
|
|
|
|
const message = error instanceof Error ? error?.message : "unknown error";
|
|
|
|
console.error({
|
|
error,
|
|
extras: {
|
|
loginMethod: AUTH_PROVIDERS.LOGIN_GITHUB,
|
|
},
|
|
});
|
|
|
|
return redirect(
|
|
loginPath({
|
|
error: AUTH_PROVIDERS.LOGIN_GITHUB,
|
|
message,
|
|
returnTo,
|
|
})
|
|
);
|
|
}
|
|
};
|