mirror of
https://github.com/ChatGPTNextWeb/ChatGPT-Next-Web.git
synced 2025-11-16 14:03:43 +08:00
测试增加邮件认证
This commit is contained in:
@@ -7,7 +7,8 @@ import { Flex } from "antd";
|
||||
|
||||
export default async function AdminPage() {
|
||||
const session = await getSession();
|
||||
if (!(session?.user?.name && ADMIN_LIST.includes(session.user.name))) {
|
||||
const name = session?.user?.email || session?.user?.name;
|
||||
if (!(name && ADMIN_LIST.includes(name))) {
|
||||
// Replace '/dashboard' with the desired redirect path
|
||||
redirect("/");
|
||||
}
|
||||
|
||||
@@ -16,7 +16,8 @@ export default async function AuthLayout({
|
||||
}) {
|
||||
const session = await getSession();
|
||||
// If the user is already authenticated, redirect them to home
|
||||
if (session?.user?.name && isName(session.user.name)) {
|
||||
const name = session?.user?.email || session?.user?.name;
|
||||
if (name && isName(name)) {
|
||||
// Replace '/dashboard' with the desired redirect path
|
||||
redirect("/");
|
||||
}
|
||||
|
||||
@@ -1,13 +1,14 @@
|
||||
"use client";
|
||||
|
||||
import { signIn } from "next-auth/react";
|
||||
import React, { useState, useEffect, useRef } from "react";
|
||||
import React, { useState, useEffect, useRef, use } from "react";
|
||||
import { isName } from "@/lib/auth_list";
|
||||
|
||||
export default function UserLoginButton() {
|
||||
const [loading, setLoading] = useState(false);
|
||||
|
||||
const nameInput = useRef<HTMLInputElement>(null);
|
||||
const emailInput = useRef<HTMLInputElement>(null);
|
||||
const [username, setUsername] = useState("");
|
||||
const [error, setError] = useState(false);
|
||||
|
||||
@@ -27,18 +28,31 @@ export default function UserLoginButton() {
|
||||
setLoading(true);
|
||||
e.preventDefault();
|
||||
|
||||
console.log("current,username2", username);
|
||||
const result = await signIn("credentials", {
|
||||
username: username,
|
||||
redirect: false,
|
||||
});
|
||||
let result: { error: any; url: string | null } | undefined = {
|
||||
error: null,
|
||||
url: null,
|
||||
};
|
||||
if (emailInput.current && emailInput.current.value) {
|
||||
result = await signIn("email", {
|
||||
email: emailInput.current.value,
|
||||
redirect: false,
|
||||
});
|
||||
} else {
|
||||
result = await signIn("credentials", {
|
||||
username: username,
|
||||
redirect: false,
|
||||
});
|
||||
}
|
||||
setLoading(false);
|
||||
if (!result?.error) {
|
||||
window.location.href = "/";
|
||||
} else setError(true);
|
||||
console.log("------1", result);
|
||||
// if (!result?.error) {
|
||||
// console.log('------2',result)
|
||||
// window.location.href = result?.url || "/";
|
||||
// } else setError(true);
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
if (!username) return;
|
||||
if (nameInput.current) {
|
||||
if (!isName(username)) {
|
||||
setError(true);
|
||||
@@ -81,7 +95,7 @@ export default function UserLoginButton() {
|
||||
onCompositionStart={(e) => e.preventDefault()}
|
||||
onCompositionEnd={handleComposition}
|
||||
onChange={onNameChange}
|
||||
required
|
||||
// required
|
||||
placeholder="输入姓名、拼音或邮箱"
|
||||
className={`${
|
||||
loading
|
||||
@@ -95,6 +109,29 @@ export default function UserLoginButton() {
|
||||
}
|
||||
`}
|
||||
/>
|
||||
<input
|
||||
id="email"
|
||||
name="email"
|
||||
type="email"
|
||||
ref={emailInput}
|
||||
// value={username}
|
||||
onCompositionStart={(e) => e.preventDefault()}
|
||||
// onCompositionEnd={handleComposition}
|
||||
// onChange={onNameChange}
|
||||
// required
|
||||
placeholder="邮箱验证,测试阶段"
|
||||
className={`${
|
||||
loading
|
||||
? "cursor-not-allowed bg-stone-50 dark:bg-stone-800"
|
||||
: "bg-white hover:bg-stone-50 active:bg-stone-100 dark:bg-black dark:hover:border-white dark:hover:bg-black"
|
||||
} group my-2 flex h-10 w-full items-center justify-center space-x-2 rounded-md border border-stone-200 transition-colors duration-75 focus:outline-none dark:border-stone-700
|
||||
${
|
||||
error
|
||||
? "focus:invalid:border-red-500 focus:invalid:ring-red-500"
|
||||
: ""
|
||||
}
|
||||
`}
|
||||
/>
|
||||
{/*{error && <p className="mt-2 text-pink-600 text-sm">{error}</p>}*/}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -12,7 +12,8 @@ const serverConfig = getServerSideConfig();
|
||||
|
||||
export default async function App() {
|
||||
const session = await getSession();
|
||||
if (!session || !(session?.user?.name && isName(session.user.name))) {
|
||||
const name = session?.user?.email || session?.user?.name;
|
||||
if (!(name && isName(name))) {
|
||||
redirect("/login");
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user