feats: configurable login methods

This commit is contained in:
oiov
2025-06-13 17:35:19 +08:00
parent 6ede43b9fb
commit 8f44b8ae11
12 changed files with 94 additions and 40 deletions
+59 -2
View File
@@ -8,8 +8,11 @@ import useSWR from "swr";
import { fetcher } from "@/lib/utils";
import { Button } from "@/components/ui/button";
import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card";
import { Input } from "@/components/ui/input";
import { Skeleton } from "@/components/ui/skeleton";
import {
Collapsible,
CollapsibleContent,
CollapsibleTrigger,
} from "@/components/ui/collapsible";
import { Switch } from "@/components/ui/switch";
import { Textarea } from "@/components/ui/textarea";
import { Icons } from "@/components/shared/icons";
@@ -80,6 +83,59 @@ export default function AppConfigs({}: {}) {
/>
)}
</div>
<Collapsible>
<CollapsibleTrigger className="flex w-full items-center justify-between">
<div className="space-y-1 text-start leading-none">
<p className="font-medium">{t("Login Methods")}</p>
<p className="text-xs text-muted-foreground">
{t("Select the login methods that users can use to log in")}
</p>
</div>
<Icons.chevronDown className="ml-2 size-4" />
</CollapsibleTrigger>
<CollapsibleContent className="mt-2 space-y-3 rounded-md bg-neutral-100 p-3">
{configs && (
<>
<div className="flex items-center justify-between gap-3">
<p className="text-sm">GitHub OAuth</p>
<Switch
defaultChecked={configs.enable_github_oauth}
onCheckedChange={(v) =>
handleChange(v, "enable_github_oauth", "BOOLEAN")
}
/>
</div>
<div className="flex items-center justify-between gap-3">
<p className="text-sm">Google OAuth</p>
<Switch
defaultChecked={configs.enable_google_oauth}
onCheckedChange={(v) =>
handleChange(v, "enable_google_oauth", "BOOLEAN")
}
/>
</div>
<div className="flex items-center justify-between gap-3">
<p className="text-sm">LinuxDo OAuth</p>
<Switch
defaultChecked={configs.enable_liunxdo_oauth}
onCheckedChange={(v) =>
handleChange(v, "enable_liunxdo_oauth", "BOOLEAN")
}
/>
</div>
<div className="flex items-center justify-between gap-3">
<p className="text-sm">{t("Resend Email")}</p>
<Switch
defaultChecked={configs.enable_resend_email_login}
onCheckedChange={(v) =>
handleChange(v, "enable_resend_email_login", "BOOLEAN")
}
/>
</div>
</>
)}
</CollapsibleContent>
</Collapsible>
<div className="flex items-center justify-between space-x-2">
<div className="space-y-1 leading-none">
<p className="font-medium">{t("Subdomain Apply Mode")}</p>
@@ -98,6 +154,7 @@ export default function AppConfigs({}: {}) {
/>
)}
</div>
<div className="flex flex-col items-start justify-start gap-3">
<div className="space-y-1 leading-none">
<p className="font-medium">{t("Notification")}</p>
+4
View File
@@ -19,6 +19,10 @@ export async function GET(req: NextRequest) {
"enable_user_registration",
"enable_subdomain_apply",
"system_notification",
"enable_github_oauth",
"enable_google_oauth",
"enable_liunxdo_oauth",
"enable_resend_email_login",
]);
return Response.json(configs, { status: 200 });
+16 -22
View File
@@ -1,31 +1,25 @@
import { env } from "@/env.mjs";
import { getConfigValue } from "@/lib/dto/system-config";
import { getMultipleConfigs } from "@/lib/dto/system-config";
export const dynamic = "force-dynamic";
export async function GET(req: Request) {
try {
const registration = await getConfigValue<boolean>(
const configs = await getMultipleConfigs([
"enable_user_registration",
);
if (process.env.VERCEL) {
return Response.json({
google: !!(env.GOOGLE_CLIENT_ID && env.GOOGLE_CLIENT_SECRET),
github: !!(env.GITHUB_ID && env.GITHUB_SECRET),
linuxdo: !!(env.LinuxDo_CLIENT_ID && env.LinuxDo_CLIENT_SECRET),
resend: !!(env.RESEND_API_KEY && env.RESEND_FROM_EMAIL),
registration,
});
} else {
// TODO: (docker) cannot get env on docker environment
return Response.json({
google: true,
github: true,
linuxdo: true,
resend: true,
registration,
});
}
"enable_subdomain_apply",
"system_notification",
"enable_github_oauth",
"enable_google_oauth",
"enable_liunxdo_oauth",
"enable_resend_email_login",
]);
return Response.json({
google: configs.enable_google_oauth,
github: configs.enable_github_oauth,
linuxdo: configs.enable_liunxdo_oauth,
resend: configs.enable_resend_email_login,
registration: configs.enable_user_registration,
});
} catch (error) {
console.log("[Error]", error);
}
+1 -1
View File
@@ -3,7 +3,7 @@
"short_name": "WR.DO",
"description": "Shorten links with analytics, manage emails and control subdomains—all on one platform.",
"appid": "com.wr.do",
"versionName": "1.0.0",
"versionName": "1.0.1",
"versionCode": "1",
"start_url": "/",
"orientation": "portrait",
+1 -8
View File
@@ -1,12 +1,6 @@
"use client";
import {
Dispatch,
SetStateAction,
useEffect,
useState,
useTransition,
} from "react";
import { Dispatch, SetStateAction, useState, useTransition } from "react";
import Link from "next/link";
import { zodResolver } from "@hookform/resolvers/zod";
import { User } from "@prisma/client";
@@ -14,7 +8,6 @@ import { useTranslations } from "next-intl";
import { useForm } from "react-hook-form";
import { toast } from "sonner";
import { getZoneDetail } from "@/lib/cloudflare";
import { DomainFormData } from "@/lib/dto/domains";
import { cn } from "@/lib/utils";
import { createDomainSchema } from "@/lib/validations/domain";
+1 -1
View File
@@ -17,7 +17,7 @@ import useSWR from "swr";
import { CreateDNSRecord, RecordType } from "@/lib/cloudflare";
import { UserRecordFormData } from "@/lib/dto/cloudflare-dns-record";
import { RECORD_TYPE_ENUMS, TTL_ENUMS } from "@/lib/enums";
import { TTL_ENUMS } from "@/lib/enums";
import { fetcher } from "@/lib/utils";
import { createRecordSchema } from "@/lib/validations/record";
import { Button } from "@/components/ui/button";
+4 -1
View File
@@ -463,6 +463,9 @@
"Subdomain Apply Mode": "Subdomain Apply Mode",
"Enable subdomain apply mode, each submission requires administrator review": "Enable subdomain apply mode, each submission requires administrator review",
"Notification": "系统通知",
"Set system notification, this will be displayed in the header": "Set system notification, this will be displayed in the header"
"Set system notification, this will be displayed in the header": "Set system notification, this will be displayed in the header",
"Login Methods": "Login Methods",
"Select the login methods that users can use to log in": "Select the login methods that users can use to log in",
"Resend Email": "Resend Email"
}
}
+4 -1
View File
@@ -463,6 +463,9 @@
"Subdomain Apply Mode": "子域名申请模式",
"Enable subdomain apply mode, each submission requires administrator review": "启用子域名申请模式,每次提交需要管理员审核",
"Notification": "系统通知",
"Set system notification, this will be displayed in the header": "设置系统通知,将在网页顶部显示"
"Set system notification, this will be displayed in the header": "设置系统通知,将在网页顶部显示",
"Login Methods": "登录方式",
"Select the login methods that users can use to log in": "选择用户可以使用的登录方式",
"Resend Email": "Resend 邮箱登录"
}
}
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "wr.do",
"version": "1.0.0",
"version": "1.0.1",
"author": {
"name": "oiov",
"url": "https://github.com/oiov"
+1 -1
View File
@@ -3,7 +3,7 @@
"short_name": "WR.DO",
"description": "Shorten links with analytics, manage emails and control subdomains—all on one platform.",
"appid": "com.wr.do",
"versionName": "1.0.0",
"versionName": "1.0.1",
"versionCode": "1",
"start_url": "/",
"orientation": "portrait",
+1 -1
View File
@@ -3,7 +3,7 @@
"short_name": "WR.DO",
"description": "Shorten links with analytics, manage emails and control subdomains—all on one platform.",
"appid": "com.wr.do",
"versionName": "1.0.0",
"versionName": "1.0.1",
"versionCode": "1",
"start_url": "/",
"orientation": "portrait",
+1 -1
View File
File diff suppressed because one or more lines are too long