mirror of
https://github.com/webstudio-is/webstudio.git
synced 2026-11-09 22:14:29 +09:00
27 lines
894 B
TypeScript
27 lines
894 B
TypeScript
import { LoaderFunction, redirect } from "@remix-run/node";
|
|
import config from "~/config";
|
|
import { authenticator } from "~/services/auth.server";
|
|
import { ensureUserCookie } from "~/shared/session";
|
|
import { AUTH_PROVIDERS } from "~/shared/session/useLoginErrorMessage";
|
|
|
|
export const loader: LoaderFunction = async ({ request }) => {
|
|
const { userId } = await ensureUserCookie(request);
|
|
const url = new URL(request.url);
|
|
const error = url.searchParams.get("error");
|
|
const error_description = url.searchParams.get("error_description");
|
|
if (error) {
|
|
return redirect(
|
|
`${config.loginPath}?error=${AUTH_PROVIDERS.LOGIN_GITHUB}&message=${
|
|
error_description || error
|
|
}`
|
|
);
|
|
}
|
|
return authenticator.authenticate("github", request, {
|
|
context: {
|
|
userId,
|
|
},
|
|
successRedirect: config.dashboardPath,
|
|
failureRedirect: config.loginPath,
|
|
});
|
|
};
|