fix: resolve NextAuth UntrustedHost error and add login debugging
- Add trustHost: true to NextAuth configuration - Add console logging for login debugging - Fix authentication issues preventing login redirect
This commit is contained in:
@@ -44,18 +44,24 @@ function LoginForm() {
|
|||||||
setLoading(true);
|
setLoading(true);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
console.log('开始登录...', { email, callbackUrl });
|
||||||
const result = await signIn('credentials', {
|
const result = await signIn('credentials', {
|
||||||
email,
|
email,
|
||||||
password,
|
password,
|
||||||
redirect: false,
|
redirect: false,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
console.log('登录结果:', result);
|
||||||
|
|
||||||
if (result?.error) {
|
if (result?.error) {
|
||||||
|
console.error('登录错误:', result.error);
|
||||||
setError('邮箱或密码错误');
|
setError('邮箱或密码错误');
|
||||||
} else {
|
} else {
|
||||||
|
console.log('登录成功,准备跳转到:', callbackUrl);
|
||||||
router.push(callbackUrl);
|
router.push(callbackUrl);
|
||||||
}
|
}
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
|
console.error('登录异常:', err);
|
||||||
setError('登录失败,请稍后重试');
|
setError('登录失败,请稍后重试');
|
||||||
} finally {
|
} finally {
|
||||||
setLoading(false);
|
setLoading(false);
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import { eq } from 'drizzle-orm';
|
|||||||
import bcrypt from 'bcryptjs';
|
import bcrypt from 'bcryptjs';
|
||||||
|
|
||||||
export const { handlers, signIn, signOut, auth } = NextAuth({
|
export const { handlers, signIn, signOut, auth } = NextAuth({
|
||||||
|
trustHost: true,
|
||||||
providers: [
|
providers: [
|
||||||
CredentialsProvider({
|
CredentialsProvider({
|
||||||
name: '邮箱密码',
|
name: '邮箱密码',
|
||||||
|
|||||||
Reference in New Issue
Block a user