feat : update
This commit is contained in:
@@ -198,6 +198,9 @@ export function AccountForm({
|
||||
<Card className="w-full max-w-sm">
|
||||
<CardHeader>
|
||||
<CardTitle>{register ? "สมัครสมาชิก" : "เข้าสู่ระบบ"}</CardTitle>
|
||||
{oidcEnabled && <p className="text-sm text-muted-foreground">
|
||||
{oidcOnly ? "ใช้ Sudloh Account แล้วกลับมายัง Buzz Guide หลังเข้าสู่ระบบ" : "ใช้ Sudloh Account หรือบัญชี Buzz Guide ของคุณ"}
|
||||
</p>}
|
||||
</CardHeader>
|
||||
<CardContent className="flex flex-col gap-4">
|
||||
{oidcEnabled && <Button type="button" variant="outline" disabled={busy} onClick={() => void signInWithSudloh()}>
|
||||
@@ -302,7 +305,7 @@ export function AccountForm({
|
||||
สมัครสมาชิก
|
||||
</Button>
|
||||
<Button variant="link" size="sm" className="px-0" nativeButton={false}
|
||||
render={<Link href="/auth/forgot-password" />}>
|
||||
render={<Link href={`/auth/forgot-password${nextPath === "/" ? "" : `?next=${encodeURIComponent(nextPath)}`}`} />}>
|
||||
ลืมรหัสผ่าน?
|
||||
</Button>
|
||||
</div>}
|
||||
|
||||
@@ -11,8 +11,8 @@ import { authClient } from "@/lib/auth/client";
|
||||
|
||||
type Mode = "forgot" | "reset";
|
||||
|
||||
export function EmailActionForm({ mode, token = "", invalidToken = false }: {
|
||||
mode: Mode; token?: string; invalidToken?: boolean;
|
||||
export function EmailActionForm({ mode, token = "", invalidToken = false, nextPath = "/", oidcEnabled = false, oidcOnly = false }: {
|
||||
mode: Mode; token?: string; invalidToken?: boolean; nextPath?: string; oidcEnabled?: boolean; oidcOnly?: boolean;
|
||||
}) {
|
||||
const [busy, setBusy] = useState(false);
|
||||
const [error, setError] = useState("");
|
||||
@@ -27,7 +27,8 @@ export function EmailActionForm({ mode, token = "", invalidToken = false }: {
|
||||
setError("");
|
||||
try {
|
||||
if (mode === "forgot") {
|
||||
const result = await authClient.requestPasswordReset({ email: address, redirectTo: "/auth/password-reset" });
|
||||
const returnQuery = nextPath === "/" ? "" : `?next=${encodeURIComponent(nextPath)}`;
|
||||
const result = await authClient.requestPasswordReset({ email: address, redirectTo: `/auth/password-reset${returnQuery}` });
|
||||
if (result.error) throw new Error("ส่งลิงก์รีเซ็ตไม่สำเร็จ กรุณาลองอีกครั้ง");
|
||||
} else {
|
||||
const password = String(form.get("password") ?? "");
|
||||
@@ -47,9 +48,21 @@ export function EmailActionForm({ mode, token = "", invalidToken = false }: {
|
||||
}
|
||||
|
||||
const title = mode === "forgot" ? "ลืมรหัสผ่าน" : "ตั้งรหัสผ่านใหม่";
|
||||
const loginHref = `/auth/login${nextPath === "/" ? "" : `?next=${encodeURIComponent(nextPath)}`}`;
|
||||
const canReset = Boolean(token) && !invalidToken;
|
||||
return <Card className="w-full max-w-sm">
|
||||
<CardHeader><CardTitle>{title}</CardTitle></CardHeader>
|
||||
<CardContent className="flex flex-col gap-4">
|
||||
{oidcOnly ? <>
|
||||
<p className="text-sm text-muted-foreground">Buzz Guide ใช้ Sudloh Account สำหรับเข้าสู่ระบบ กรุณาตั้งรหัสผ่านใหม่ที่ Sudloh Account</p>
|
||||
<Button nativeButton={false} render={<a href="https://account.sudloh.com/reset-password" target="_blank" rel="noreferrer" />}>
|
||||
ไปหน้าตั้งรหัสผ่าน Sudloh
|
||||
</Button>
|
||||
</> : null}
|
||||
{oidcEnabled && !oidcOnly && mode === "forgot" ? <p className="text-sm text-muted-foreground">
|
||||
หากเข้าสู่ระบบด้วย Sudloh Account ให้ <a href="https://account.sudloh.com/reset-password" target="_blank" rel="noreferrer" className="underline underline-offset-4">ตั้งรหัสผ่านที่ Sudloh</a> ส่วนแบบฟอร์มด้านล่างสำหรับบัญชี Buzz Guide ที่ใช้อีเมลและรหัสผ่าน
|
||||
</p> : null}
|
||||
{!oidcOnly && <>
|
||||
{sent && <Alert><AlertDescription>{mode === "reset"
|
||||
? "ตั้งรหัสผ่านใหม่แล้ว กรุณาเข้าสู่ระบบ"
|
||||
: "หากอีเมลนี้มีบัญชีอยู่ โปรดตรวจสอบกล่องจดหมายและโฟลเดอร์สแปม"}</AlertDescription></Alert>}
|
||||
@@ -57,7 +70,7 @@ export function EmailActionForm({ mode, token = "", invalidToken = false }: {
|
||||
ลิงก์รีเซ็ตไม่ถูกต้องหรือหมดอายุ กรุณาขอลิงก์ใหม่
|
||||
</AlertDescription></Alert>}
|
||||
{error && <Alert variant="destructive"><AlertDescription>{error}</AlertDescription></Alert>}
|
||||
{(mode !== "reset" || (!sent && token)) && <form onSubmit={submit}>
|
||||
{(mode !== "reset" || (!sent && canReset)) && <form onSubmit={submit}>
|
||||
<FieldGroup>
|
||||
{mode !== "reset" ? <Field>
|
||||
<FieldLabel htmlFor="auth-email">อีเมล</FieldLabel>
|
||||
@@ -74,10 +87,11 @@ export function EmailActionForm({ mode, token = "", invalidToken = false }: {
|
||||
mode === "forgot" ? "ส่งลิงก์รีเซ็ต" : "ตั้งรหัสผ่าน"}</Button>
|
||||
</FieldGroup>
|
||||
</form>}
|
||||
{mode === "reset" && !token && <Button variant="link" nativeButton={false} render={<Link href="/auth/forgot-password" />}>
|
||||
{mode === "reset" && !canReset && !sent && <Button variant="link" nativeButton={false} render={<Link href={`/auth/forgot-password${nextPath === "/" ? "" : `?next=${encodeURIComponent(nextPath)}`}`} />}>
|
||||
ขอลิงก์รีเซ็ตใหม่
|
||||
</Button>}
|
||||
<Button variant="link" nativeButton={false} render={<Link href="/auth/login" />}>กลับไปเข้าสู่ระบบ</Button>
|
||||
</>}
|
||||
<Button variant="link" nativeButton={false} render={<Link href={loginHref} />}>กลับไปเข้าสู่ระบบ</Button>
|
||||
</CardContent>
|
||||
</Card>;
|
||||
}
|
||||
|
||||
@@ -27,6 +27,7 @@ export function SudlohSignInRedirect({ nextPath }: { nextPath: string }) {
|
||||
return <div className="grid min-h-[calc(100svh-4rem)] place-items-center p-4">
|
||||
<div className="flex flex-col items-center gap-4 text-center">
|
||||
<p>{failed ? "ไม่สามารถเริ่มเข้าสู่ระบบได้" : "กำลังไปที่ Sudloh Account…"}</p>
|
||||
<p className="max-w-sm text-sm text-muted-foreground">เข้าสู่ระบบหรือสมัครสมาชิกที่ Sudloh Account แล้วระบบจะพาคุณกลับมายัง Buzz Guide</p>
|
||||
{failed && <Button onClick={() => void start().catch(() => setFailed(true))}>ลองอีกครั้ง</Button>}
|
||||
</div>
|
||||
</div>;
|
||||
|
||||
Reference in New Issue
Block a user