fix:google login
This commit is contained in:
@@ -1,30 +1,30 @@
|
||||
import React from 'react';
|
||||
import { Form, Input, Button, Divider, message } from 'antd';
|
||||
import { GoogleOutlined } from '@ant-design/icons';
|
||||
import { Link, useNavigate } from 'react-router-dom';
|
||||
import { useAuth } from '@/contexts/AuthContext';
|
||||
import React from "react";
|
||||
import { Form, Input, Button, Divider, message } from "antd";
|
||||
import { GoogleOutlined } from "@ant-design/icons";
|
||||
import { Link, useNavigate } from "react-router-dom";
|
||||
import { useAuth } from "@/contexts/AuthContext";
|
||||
|
||||
const Login = () => {
|
||||
const navigate = useNavigate();
|
||||
const { login, signInWithGoogle } = useAuth();
|
||||
const { login, signInWithGoogle, loading } = useAuth();
|
||||
const [form] = Form.useForm();
|
||||
|
||||
const handleLogin = async (values) => {
|
||||
try {
|
||||
await login(values.email, values.password);
|
||||
message.success('登录成功!');
|
||||
navigate('/');
|
||||
message.success("登录成功!");
|
||||
navigate("/");
|
||||
} catch (error) {
|
||||
console.error('Login error:', error);
|
||||
console.error("Login error:", error);
|
||||
}
|
||||
};
|
||||
|
||||
const handleGoogleLogin = async () => {
|
||||
try {
|
||||
await signInWithGoogle();
|
||||
navigate('/');
|
||||
navigate("/");
|
||||
} catch (error) {
|
||||
console.error('Google login error:', error);
|
||||
console.error("Google login error:", error);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -49,8 +49,8 @@ const Login = () => {
|
||||
<Form.Item
|
||||
name="email"
|
||||
rules={[
|
||||
{ required: true, message: '请输入邮箱!' },
|
||||
{ type: 'email', message: '请输入有效的邮箱地址!' }
|
||||
{ required: true, message: "请输入邮箱!" },
|
||||
{ type: "email", message: "请输入有效的邮箱地址!" },
|
||||
]}
|
||||
>
|
||||
<Input placeholder="邮箱" />
|
||||
@@ -58,16 +58,17 @@ const Login = () => {
|
||||
|
||||
<Form.Item
|
||||
name="password"
|
||||
rules={[
|
||||
{ required: true, message: '请输入密码!' }
|
||||
]}
|
||||
rules={[{ required: true, message: "请输入密码!" }]}
|
||||
>
|
||||
<Input.Password placeholder="密码" />
|
||||
</Form.Item>
|
||||
|
||||
<div className="flex justify-between items-center mb-6">
|
||||
<Form.Item name="remember" valuePropName="checked" noStyle>
|
||||
<Link to="/forgot-password" className="text-primary-500 hover:text-primary-600">
|
||||
<Link
|
||||
to="/forgot-password"
|
||||
className="text-primary-500 hover:text-primary-600"
|
||||
>
|
||||
忘记密码?
|
||||
</Link>
|
||||
</Form.Item>
|
||||
@@ -86,10 +87,10 @@ const Login = () => {
|
||||
block
|
||||
onClick={handleGoogleLogin}
|
||||
className="mb-6"
|
||||
loading={loading}
|
||||
>
|
||||
使用 Google 账号登录
|
||||
</Button>
|
||||
|
||||
</Form>
|
||||
</div>
|
||||
|
||||
@@ -99,4 +100,4 @@ const Login = () => {
|
||||
);
|
||||
};
|
||||
|
||||
export default Login;
|
||||
export default Login;
|
||||
|
||||
Reference in New Issue
Block a user