Enhance login page to display messages from URL parameters and update email redirect options for sign-up confirmation.

This commit is contained in:
2025-04-18 21:50:06 +08:00
parent 3af015ca44
commit 9cb85a2910
2 changed files with 22 additions and 5 deletions

View File

@@ -1,12 +1,13 @@
'use client';
import { useState, useEffect } from 'react';
import { useRouter } from 'next/navigation';
import { useRouter, useSearchParams } from 'next/navigation';
import Link from 'next/link';
import { useAuth } from '@/lib/auth';
export default function LoginPage() {
const router = useRouter();
const searchParams = useSearchParams();
const { signIn, signInWithGitHub, signInWithGoogle, user } = useAuth();
const [email, setEmail] = useState('');
@@ -14,6 +15,14 @@ export default function LoginPage() {
const [isLoading, setIsLoading] = useState(false);
const [message, setMessage] = useState({ type: '', content: '' });
// 读取URL中的消息参数
useEffect(() => {
const messageParam = searchParams.get('message');
if (messageParam) {
setMessage({ type: 'info', content: messageParam });
}
}, [searchParams]);
// 如果用户已登录,重定向到首页
useEffect(() => {
if (user) {
@@ -112,11 +121,16 @@ export default function LoginPage() {
{/* Message display */}
{message.content && (
<div className={`p-4 mb-4 text-sm ${
<div className={`p-4 mb-4 text-sm rounded-lg ${
message.type === 'error'
? 'text-red-700 bg-red-100 rounded-lg'
: 'text-blue-700 bg-blue-100 rounded-lg'
? 'text-red-700 bg-red-100 border border-red-200'
: 'text-blue-700 bg-blue-50 border border-blue-200'
}`}>
{message.type === 'error' ? (
<span className="font-medium">Error: </span>
) : (
<span className="font-medium">Notice: </span>
)}
{message.content}
</div>
)}