Skip to content

Commit e0adc2b

Browse files
committed
display github login errors
1 parent dcc4cb1 commit e0adc2b

File tree

1 file changed

+22
-2
lines changed

1 file changed

+22
-2
lines changed

apps/webapp/app/routes/login._index/route.tsx

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,14 @@ import { redirect, typedjson, useTypedLoaderData } from "remix-typedjson";
66
import { LoginPageLayout } from "~/components/LoginPageLayout";
77
import { Button, LinkButton } from "~/components/primitives/Buttons";
88
import { Fieldset } from "~/components/primitives/Fieldset";
9+
import { FormError } from "~/components/primitives/FormError";
910
import { Header1 } from "~/components/primitives/Headers";
1011
import { Paragraph } from "~/components/primitives/Paragraph";
1112
import { TextLink } from "~/components/primitives/TextLink";
1213
import { isGithubAuthSupported } from "~/services/auth.server";
1314
import { commitSession, setRedirectTo } from "~/services/redirectTo.server";
1415
import { getUserId } from "~/services/session.server";
16+
import { getUserSession } from "~/services/sessionStorage.server";
1517
import { requestUrl } from "~/utils/requestUrl.server";
1618

1719
export const meta: MetaFunction = ({ matches }) => {
@@ -48,17 +50,34 @@ export async function loader({ request }: LoaderFunctionArgs) {
4850
const session = await setRedirectTo(request, redirectTo);
4951

5052
return typedjson(
51-
{ redirectTo, showGithubAuth: isGithubAuthSupported },
53+
{
54+
redirectTo,
55+
showGithubAuth: isGithubAuthSupported,
56+
authError: null,
57+
},
5258
{
5359
headers: {
5460
"Set-Cookie": await commitSession(session),
5561
},
5662
}
5763
);
5864
} else {
65+
const session = await getUserSession(request);
66+
const error = session.get("auth:error");
67+
68+
let authError: string | undefined;
69+
if (error) {
70+
if ("message" in error) {
71+
authError = error.message;
72+
} else {
73+
authError = JSON.stringify(error, null, 2);
74+
}
75+
}
76+
5977
return typedjson({
6078
redirectTo: null,
6179
showGithubAuth: isGithubAuthSupported,
80+
authError,
6281
});
6382
}
6483
}
@@ -81,7 +100,7 @@ export default function LoginPage() {
81100
Create an account or login
82101
</Paragraph>
83102
<Fieldset className="w-full">
84-
<div className="flex flex-col gap-y-2">
103+
<div className="flex flex-col items-center gap-y-2">
85104
{data.showGithubAuth && (
86105
<Button
87106
type="submit"
@@ -103,6 +122,7 @@ export default function LoginPage() {
103122
<EnvelopeIcon className="mr-2 size-5 text-text-bright" />
104123
Continue with Email
105124
</LinkButton>
125+
{data.authError && <FormError>{data.authError}</FormError>}
106126
</div>
107127
<Paragraph variant="extra-small" className="mt-2 text-center">
108128
By signing up you agree to our{" "}

0 commit comments

Comments
 (0)