mirror of
https://github.com/ChatGPTNextWeb/ChatGPT-Next-Web.git
synced 2025-11-16 14:03:43 +08:00
增加谷歌登录
This commit is contained in:
@@ -9,7 +9,7 @@ export default function LoginByGithub() {
|
||||
|
||||
return (
|
||||
<div
|
||||
className={`group my-2 flex h-10 w-7/12 items-center justify-center space-x-2 rounded-md border border-stone-200 transition-colors duration-75 focus:outline-none dark:border-stone-700 `} //
|
||||
className={`group my-2 flex h-10 w-1/12 items-center justify-center space-x-2 rounded-md border border-stone-200 transition-colors duration-75 focus:outline-none dark:border-stone-700 `} //
|
||||
>
|
||||
<button
|
||||
disabled={loading}
|
||||
@@ -18,7 +18,7 @@ export default function LoginByGithub() {
|
||||
e.preventDefault();
|
||||
signIn("github");
|
||||
}}
|
||||
className={`bg-transparent hover:bg-transparent mr-40`}
|
||||
className={`bg-transparent hover:bg-transparent`}
|
||||
>
|
||||
{loading ? (
|
||||
<LoadingDots color="#A8A29E" />
|
||||
|
||||
52
app/app/(auth)/login/loginByGoogle.tsx
Normal file
52
app/app/(auth)/login/loginByGoogle.tsx
Normal file
@@ -0,0 +1,52 @@
|
||||
"use client";
|
||||
|
||||
import LoadingDots from "@/app/components/icons/loading-dots";
|
||||
import { signIn } from "next-auth/react";
|
||||
import { useState } from "react";
|
||||
import { GoogleCircleFilled } from "@ant-design/icons";
|
||||
export default function LoginByGoogle() {
|
||||
const [loading, setLoading] = useState(false);
|
||||
|
||||
return (
|
||||
<div
|
||||
className={`group my-2 flex h-10 w-1/12 items-center justify-center space-x-2 rounded-md border border-stone-200 transition-colors duration-75 focus:outline-none dark:border-stone-700 `} //
|
||||
>
|
||||
<button
|
||||
disabled={loading}
|
||||
onClick={(e) => {
|
||||
setLoading(true);
|
||||
e.preventDefault();
|
||||
signIn("google", { redirect: false }).then((r) => {
|
||||
console.log("[auth log]", r);
|
||||
});
|
||||
}}
|
||||
className={`bg-transparent hover:bg-transparent`}
|
||||
>
|
||||
{loading ? (
|
||||
<LoadingDots color="#A8A29E" />
|
||||
) : (
|
||||
<>
|
||||
{/*<svg*/}
|
||||
{/* className="h-6 w-6 text-gray-500 dark:text-white"*/}
|
||||
{/* aria-hidden="true"*/}
|
||||
{/* fill="currentColor"*/}
|
||||
{/* viewBox="0 0 24 24"*/}
|
||||
{/*>*/}
|
||||
{/* */}
|
||||
{/*</svg>*/}
|
||||
<GoogleCircleFilled
|
||||
style={{
|
||||
fontSize: "24px",
|
||||
color: "rgb(107 114 128/var(--tw-text-opacity)) !import",
|
||||
}}
|
||||
/>
|
||||
{/*<p className="text-sm font-medium text-stone-600 dark:text-stone-400">*/}
|
||||
{/* Login with GitHub*/}
|
||||
{/*</p>*/}
|
||||
</>
|
||||
)}
|
||||
</button>
|
||||
<div className={`w-1`}></div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -1,4 +1,5 @@
|
||||
import LoginByGithub from "./loginByGithub";
|
||||
import LoginByGoogle from "./loginByGoogle";
|
||||
import UserLoginCore from "./user-login-core";
|
||||
|
||||
export default function LoginPage() {
|
||||
@@ -28,6 +29,8 @@ export default function LoginPage() {
|
||||
其它登录方式{" "}
|
||||
</span>
|
||||
<LoginByGithub />
|
||||
<LoginByGoogle />
|
||||
<div className="w-5/12" />
|
||||
</div>
|
||||
</>
|
||||
);
|
||||
|
||||
@@ -14,6 +14,7 @@ import { UserOutlined, MailOutlined, LoadingOutlined } from "@ant-design/icons";
|
||||
import type { FormProps } from "antd";
|
||||
import { SignInOptions } from "next-auth/react";
|
||||
import { getSession } from "next-auth/react";
|
||||
import { useSearchParams } from "next/navigation";
|
||||
|
||||
export default function UserLoginCore() {
|
||||
const [loading, setLoading] = useState(false);
|
||||
@@ -24,6 +25,27 @@ export default function UserLoginCore() {
|
||||
const [notification, notificationContextHolder] =
|
||||
notificationModule.useNotification();
|
||||
|
||||
const searchParams = useSearchParams();
|
||||
const error = searchParams.get("error");
|
||||
|
||||
useEffect(() => {
|
||||
switch (error) {
|
||||
case "AccessDenied":
|
||||
openNotification("error", {
|
||||
message: "登录失败",
|
||||
description: (
|
||||
<span>
|
||||
无权限,仅提供给熟人使用
|
||||
<br />
|
||||
<span style={{ color: "red" }}>请主动联系管理员解锁</span>
|
||||
</span>
|
||||
),
|
||||
});
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
});
|
||||
const openNotification = (level: string, arms: NotificationArgsProps) => {
|
||||
if (level === "error") {
|
||||
notification.error({
|
||||
@@ -119,6 +141,7 @@ export default function UserLoginCore() {
|
||||
}
|
||||
signIn(loginProvider, signInOptions).then((result) => {
|
||||
setLoading(false);
|
||||
console.log("[auth log]", result);
|
||||
if (!result?.error) {
|
||||
// 如果没有密码,且登录成功了,说明需要设置密码
|
||||
let result_url =
|
||||
|
||||
Reference in New Issue
Block a user