diff --git a/Foxnouns.Backend/Controllers/Authentication/AuthController.cs b/Foxnouns.Backend/Controllers/Authentication/AuthController.cs index 53aa171..1a737eb 100644 --- a/Foxnouns.Backend/Controllers/Authentication/AuthController.cs +++ b/Foxnouns.Backend/Controllers/Authentication/AuthController.cs @@ -39,10 +39,10 @@ public class AuthController( + $"&prompt=none&state={state}" + $"&redirect_uri={HttpUtility.UrlEncode($"{config.BaseUrl}/auth/callback/discord")}"; - return Ok(new UrlsResponse(discord, null, null)); + return Ok(new UrlsResponse(config.EmailAuth.Enabled, discord, null, null)); } - private record UrlsResponse(string? Discord, string? Google, string? Tumblr); + private record UrlsResponse(bool EmailEnabled, string? Discord, string? Google, string? Tumblr); public record AuthResponse( UserRendererService.UserResponse User, diff --git a/Foxnouns.Backend/Controllers/Authentication/EmailAuthController.cs b/Foxnouns.Backend/Controllers/Authentication/EmailAuthController.cs index 937ab3a..7e3706e 100644 --- a/Foxnouns.Backend/Controllers/Authentication/EmailAuthController.cs +++ b/Foxnouns.Backend/Controllers/Authentication/EmailAuthController.cs @@ -100,6 +100,8 @@ public class EmailAuthController( [FromBody] CompleteRegistrationRequest req ) { + CheckRequirements(); + var email = await keyCacheService.GetKeyAsync($"email:{req.Ticket}"); if (email == null) throw new ApiError.BadRequest("Unknown ticket", "ticket", req.Ticket); @@ -185,6 +187,8 @@ public class EmailAuthController( [Authorize("*")] public async Task AddEmailAddressAsync([FromBody] AddEmailAddressRequest req) { + CheckRequirements(); + var emails = await db .AuthMethods.Where(m => m.UserId == CurrentUser!.Id && m.AuthType == AuthType.Email) .ToListAsync(); diff --git a/Foxnouns.Frontend/app/lib/api/auth.ts b/Foxnouns.Frontend/app/lib/api/auth.ts index a0d5bf1..0f8ce27 100644 --- a/Foxnouns.Frontend/app/lib/api/auth.ts +++ b/Foxnouns.Frontend/app/lib/api/auth.ts @@ -16,6 +16,7 @@ export type CallbackResponse = { }; export type AuthUrls = { + email_enabled: boolean; discord?: string; google?: string; tumblr?: string; diff --git a/Foxnouns.Frontend/app/routes/auth.log-in/route.tsx b/Foxnouns.Frontend/app/routes/auth.log-in/route.tsx index eadbaa9..aaffd80 100644 --- a/Foxnouns.Frontend/app/routes/auth.log-in/route.tsx +++ b/Foxnouns.Frontend/app/routes/auth.log-in/route.tsx @@ -11,7 +11,7 @@ import { useActionData, useLoaderData, } from "@remix-run/react"; -import { Form, Button, ButtonGroup, ListGroup, Row, Col } from "react-bootstrap"; +import { Form, Button, ButtonGroup, ListGroup } from "react-bootstrap"; import { useTranslation } from "react-i18next"; import i18n from "~/i18next.server"; import serverRequest, { getToken, writeCookie } from "~/lib/request.server"; @@ -78,33 +78,36 @@ export default function LoginPage() { return ( <> - - -

{t("log-in.form-title")}

- {actionData?.error && } - -
- - {t("log-in.email")} - - - - {t("log-in.password")} - - +
+ {!urls.email_enabled &&
} + {urls.email_enabled && ( +
+

{t("log-in.form-title")}

+ {actionData?.error && } + + + + {t("log-in.email")} + + + + {t("log-in.password")} + + - - - - - - - - + + + + + + +
+ )} +

{t("log-in.3rd-party.title")}

{t("log-in.3rd-party.desc")}

@@ -124,8 +127,9 @@ export default function LoginPage() { )} - - +
+ {!urls.email_enabled &&
} +
); } diff --git a/Foxnouns.Frontend/app/routes/settings.auth/route.tsx b/Foxnouns.Frontend/app/routes/settings.auth/route.tsx index a8ca303..125f413 100644 --- a/Foxnouns.Frontend/app/routes/settings.auth/route.tsx +++ b/Foxnouns.Frontend/app/routes/settings.auth/route.tsx @@ -1,10 +1,12 @@ import i18n from "~/i18next.server"; import { LoaderFunctionArgs, MetaFunction } from "@remix-run/node"; -import { Link, useRouteLoaderData } from "@remix-run/react"; +import { Link, useLoaderData, useRouteLoaderData } from "@remix-run/react"; import { Button, ListGroup } from "react-bootstrap"; import { loader as settingsLoader } from "~/routes/settings/route"; import { useTranslation } from "react-i18next"; import { AuthMethod, MeUser } from "~/lib/api/user"; +import serverRequest from "~/lib/request.server"; +import { AuthUrls } from "~/lib/api/auth"; export const meta: MetaFunction = ({ data }) => { return [{ title: `${data?.meta.title || "Authentication"} • pronouns.cc` }]; @@ -12,17 +14,16 @@ export const meta: MetaFunction = ({ data }) => { export const loader = async ({ request }: LoaderFunctionArgs) => { const t = await i18n.getFixedT(request); - return { meta: { title: t("settings.auth.title") } }; + const urls = await serverRequest("POST", "/auth/urls", { isInternal: true }); + + return { urls, meta: { title: t("settings.auth.title") } }; }; export default function AuthSettings() { + const { urls } = useLoaderData(); const { user } = useRouteLoaderData("routes/settings")!; - return ( -
- -
- ); + return
{urls.email_enabled && }
; } function EmailSettings({ user }: { user: MeUser }) {