Openstatus www.openstatus.dev

fix: url protocol error (#1692)

* fix: url protocol error

* chore: error message

authored by

Maximilian Kaske and committed by
GitHub
fa3744a0 a7b8aad3

+25 -7
+19 -5
apps/status-page/src/app/(status-page)/[domain]/(auth)/login/actions.ts
··· 17 17 18 18 const queryClient = getQueryClient(); 19 19 // NOTE: throws an error if the email domain is not allowed 20 - await queryClient.fetchQuery( 21 - trpc.statusPage.validateEmailDomain.queryOptions({ slug: domain, email }), 22 - ); 20 + try { 21 + await queryClient.fetchQuery( 22 + trpc.statusPage.validateEmailDomain.queryOptions({ 23 + slug: domain, 24 + email, 25 + }), 26 + ); 27 + } catch (error) { 28 + console.error("[SignIn] Email validation failed", error); 29 + throw new Error( 30 + "Your email domain is not authorized to access this status page", 31 + ); 32 + } 23 33 24 34 await signIn("resend", { 25 35 email, ··· 28 38 } catch (e) { 29 39 // NOTE: https://github.com/nextauthjs/next-auth/discussions/9389 30 40 if (isRedirectError(e)) return; 31 - console.error(e); 41 + console.error("[SignIn] Error:", e); 32 42 if (e instanceof AuthError) { 33 43 throw new Error(`Authentication error: ${e.type}`); 34 44 } 35 - throw e; 45 + if (e instanceof Error) { 46 + // Re-throw the error with the original message 47 + throw e; 48 + } 49 + throw new Error("An unexpected error occurred during sign in"); 36 50 } 37 51 }
+2 -1
apps/status-page/src/components/forms/form-email.tsx
··· 1 1 "use client"; 2 2 3 - import { Form } from "@/components/ui/form"; 3 + import { Form, FormMessage } from "@/components/ui/form"; 4 4 import { 5 5 FormControl, 6 6 FormField, ··· 76 76 <FormControl> 77 77 <Input type="email" {...field} /> 78 78 </FormControl> 79 + <FormMessage /> 79 80 </FormItem> 80 81 )} 81 82 />
+4 -1
apps/status-page/src/lib/auth/index.ts
··· 23 23 24 24 if (!host) throw new AuthError("No host found"); 25 25 26 - const req = new Request(host, { headers: new Headers(_headers) }); 26 + const protocol = _headers.get("x-forwarded-proto") || "https"; 27 + const req = new Request(`${protocol}://${host}`, { 28 + headers: new Headers(_headers), 29 + }); 27 30 const { prefix } = getValidCustomDomain(req); 28 31 29 32 if (!prefix || !params.user.email) return false;