Files
webstudio/apps/builder/app/routes/auth.dev.tsx
T
Bogdan Chadkin 33d3dbc546 refactor: prepare remix types (#3075)
Here replaced LoaderArgs and ActionArgs with LoaderFunctionArgs and
ActionFunctionArgs to simplify bump with remix v2 which changed named of
these types.
2024-03-31 22:45:30 +07:00

35 lines
983 B
TypeScript

import { type ActionFunctionArgs, redirect } from "@remix-run/server-runtime";
import { authenticator } from "~/services/auth.server";
import { loginPath } from "~/shared/router-utils";
import { AUTH_PROVIDERS } from "~/shared/session";
import { returnToPath } from "~/services/cookie.server";
export default function Dev() {
return null;
}
export const action = async ({ request }: ActionFunctionArgs) => {
const returnTo = await returnToPath(request);
try {
return await authenticator.authenticate("dev", request, {
successRedirect: returnTo,
throwOnError: true,
});
} catch (error: unknown) {
// all redirects are basically errors and in that case we don't want to catch it
if (error instanceof Response) {
return error;
}
if (error instanceof Error) {
return redirect(
loginPath({
error: AUTH_PROVIDERS.LOGIN_DEV,
message: error?.message,
returnTo,
})
);
}
}
};