mirror of
https://github.com/webstudio-is/webstudio.git
synced 2026-11-03 10:37:48 +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
55 lines
1.7 KiB
TypeScript
55 lines
1.7 KiB
TypeScript
import { type ActionFunctionArgs } 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";
|
|
|
|
export default function GH() {
|
|
return null;
|
|
}
|
|
|
|
export const action = async ({ request }: ActionFunctionArgs) => {
|
|
if (false === isDashboard(request)) {
|
|
throw new Response("Not Found", {
|
|
status: 404,
|
|
});
|
|
}
|
|
|
|
preventCrossOriginCookie(request);
|
|
// CSRF token checks are not necessary for dashboard-only pages.
|
|
// All POST requests from the builder or canvas app are safeguarded by preventCrossOriginCookie
|
|
|
|
const returnTo = (await returnToPath(request)) ?? dashboardPath();
|
|
|
|
try {
|
|
return 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: message,
|
|
returnTo,
|
|
})
|
|
);
|
|
}
|
|
};
|