mirror of
https://gitlab.com/foxixus/neomovies.git
synced 2025-10-28 01:48:50 +05:00
Update 8 files
- /src/app/admin/login/AdminLoginClient.tsx - /src/app/admin/login/page.tsx - /src/api.ts - /src/app/api/auth/[...nextauth]/route.ts - /src/lib/api.ts - /src/lib/auth.ts - /src/components/MovieCard.tsx - /src/components/MoviePlayer.tsx
This commit is contained in:
@@ -1,147 +0,0 @@
|
||||
'use client';
|
||||
|
||||
import { useState } from 'react';
|
||||
import { signIn } from 'next-auth/react';
|
||||
import { useRouter } from 'next/navigation';
|
||||
import styled from 'styled-components';
|
||||
|
||||
const Container = styled.div`
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
min-height: 100vh;
|
||||
padding: 2rem;
|
||||
background: #1a1a1a;
|
||||
`;
|
||||
|
||||
const Form = styled.form`
|
||||
width: 100%;
|
||||
max-width: 400px;
|
||||
padding: 2rem;
|
||||
background: rgba(255, 255, 255, 0.1);
|
||||
border-radius: 8px;
|
||||
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
|
||||
`;
|
||||
|
||||
const Title = styled.h1`
|
||||
color: white;
|
||||
text-align: center;
|
||||
margin-bottom: 2rem;
|
||||
font-size: 1.5rem;
|
||||
`;
|
||||
|
||||
const Input = styled.input`
|
||||
width: 100%;
|
||||
padding: 0.75rem;
|
||||
margin-bottom: 1rem;
|
||||
border: 1px solid rgba(255, 255, 255, 0.2);
|
||||
border-radius: 4px;
|
||||
background: rgba(255, 255, 255, 0.05);
|
||||
color: white;
|
||||
font-size: 1rem;
|
||||
|
||||
&:focus {
|
||||
outline: none;
|
||||
border-color: #3b82f6;
|
||||
}
|
||||
|
||||
&::placeholder {
|
||||
color: rgba(255, 255, 255, 0.5);
|
||||
}
|
||||
`;
|
||||
|
||||
const Button = styled.button`
|
||||
width: 100%;
|
||||
padding: 0.75rem;
|
||||
background: #3b82f6;
|
||||
color: white;
|
||||
border: none;
|
||||
border-radius: 4px;
|
||||
font-size: 1rem;
|
||||
cursor: pointer;
|
||||
transition: background-color 0.2s;
|
||||
|
||||
&:hover {
|
||||
background: #2563eb;
|
||||
}
|
||||
|
||||
&:disabled {
|
||||
background: #64748b;
|
||||
cursor: not-allowed;
|
||||
}
|
||||
`;
|
||||
|
||||
const ErrorMessage = styled.div`
|
||||
color: #ef4444;
|
||||
margin-bottom: 1rem;
|
||||
text-align: center;
|
||||
`;
|
||||
|
||||
export default function AdminLoginClient() {
|
||||
const [email, setEmail] = useState('');
|
||||
const [password, setPassword] = useState('');
|
||||
const [error, setError] = useState('');
|
||||
const [isLoading, setIsLoading] = useState(false);
|
||||
const router = useRouter();
|
||||
|
||||
const handleSubmit = async (e: React.FormEvent) => {
|
||||
e.preventDefault();
|
||||
setError('');
|
||||
setIsLoading(true);
|
||||
|
||||
try {
|
||||
const result = await signIn('credentials', {
|
||||
email,
|
||||
password,
|
||||
isAdminLogin: 'true',
|
||||
redirect: false,
|
||||
});
|
||||
|
||||
if (result?.error) {
|
||||
switch (result.error) {
|
||||
case 'NOT_AN_ADMIN':
|
||||
setError('У вас нет прав администратора');
|
||||
break;
|
||||
case 'EMAIL_NOT_VERIFIED':
|
||||
setError('Пожалуйста, подтвердите свой email');
|
||||
break;
|
||||
default:
|
||||
setError('Неверный email или пароль');
|
||||
}
|
||||
} else {
|
||||
router.push('/admin');
|
||||
}
|
||||
} catch (error) {
|
||||
setError('Произошла ошибка при входе');
|
||||
} finally {
|
||||
setIsLoading(false);
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<Container>
|
||||
<Form onSubmit={handleSubmit}>
|
||||
<Title>Вход в админ-панель</Title>
|
||||
{error && <ErrorMessage>{error}</ErrorMessage>}
|
||||
<Input
|
||||
type="email"
|
||||
placeholder="Email"
|
||||
value={email}
|
||||
onChange={(e) => setEmail(e.target.value)}
|
||||
required
|
||||
/>
|
||||
<Input
|
||||
type="password"
|
||||
placeholder="Пароль"
|
||||
value={password}
|
||||
onChange={(e) => setPassword(e.target.value)}
|
||||
required
|
||||
/>
|
||||
<Button type="submit" disabled={isLoading}>
|
||||
{isLoading ? 'Вход...' : 'Войти'}
|
||||
</Button>
|
||||
</Form>
|
||||
</Container>
|
||||
);
|
||||
}
|
||||
@@ -1,5 +0,0 @@
|
||||
import AdminLoginClient from './AdminLoginClient';
|
||||
|
||||
export default function AdminLoginPage() {
|
||||
return <AdminLoginClient />;
|
||||
}
|
||||
@@ -12,7 +12,6 @@ declare module 'next-auth' {
|
||||
email: string;
|
||||
verified: boolean;
|
||||
isAdmin: boolean;
|
||||
adminVerified?: boolean;
|
||||
} & DefaultSession['user']
|
||||
}
|
||||
}
|
||||
@@ -24,7 +23,7 @@ const handler = NextAuth({
|
||||
credentials: {
|
||||
email: { label: 'Email', type: 'email' },
|
||||
password: { label: 'Password', type: 'password' },
|
||||
isAdminLogin: { label: 'isAdminLogin', type: 'boolean' }
|
||||
isAdminVerified: { label: 'isAdminVerified', type: 'checkbox' }
|
||||
},
|
||||
async authorize(credentials) {
|
||||
if (!credentials?.email || !credentials?.password) {
|
||||
@@ -49,12 +48,9 @@ const handler = NextAuth({
|
||||
throw new Error('EMAIL_NOT_VERIFIED');
|
||||
}
|
||||
|
||||
// Если это попытка входа в админ-панель
|
||||
if (credentials.isAdminLogin === 'true') {
|
||||
// Проверяем, является ли пользователь админом
|
||||
if (!user.isAdmin) {
|
||||
throw new Error('NOT_AN_ADMIN');
|
||||
}
|
||||
// Проверяем права администратора и флаг верификации для админ-панели
|
||||
if (user.isAdmin && !credentials.isAdminVerified) {
|
||||
throw new Error('ADMIN_NOT_VERIFIED');
|
||||
}
|
||||
|
||||
return {
|
||||
@@ -62,8 +58,7 @@ const handler = NextAuth({
|
||||
email: user.email,
|
||||
name: user.name,
|
||||
verified: user.verified,
|
||||
isAdmin: user.isAdmin,
|
||||
adminVerified: credentials.isAdminLogin === 'true'
|
||||
isAdmin: user.isAdmin
|
||||
};
|
||||
}
|
||||
})
|
||||
@@ -78,7 +73,6 @@ const handler = NextAuth({
|
||||
token.id = user.id;
|
||||
token.verified = user.verified;
|
||||
token.isAdmin = user.isAdmin;
|
||||
token.adminVerified = user.adminVerified;
|
||||
}
|
||||
return token;
|
||||
},
|
||||
@@ -87,7 +81,6 @@ const handler = NextAuth({
|
||||
session.user.id = token.id as string;
|
||||
session.user.verified = token.verified as boolean;
|
||||
session.user.isAdmin = token.isAdmin as boolean;
|
||||
session.user.adminVerified = token.adminVerified as boolean;
|
||||
}
|
||||
return session;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user