增加谷歌登录

This commit is contained in:
sijinhui
2024-10-02 23:43:30 +08:00
parent 47c72bf010
commit d86d5a1951
7 changed files with 123 additions and 33 deletions

View File

@@ -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" />

View 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>
);
}

View File

@@ -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>
</>
);

View File

@@ -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 =