fix for build
This commit is contained in:
parent
3726e9a45c
commit
75db98f254
@ -1,3 +1,7 @@
|
|||||||
{
|
{
|
||||||
"extends": ["next/core-web-vitals", "next/typescript"]
|
"extends": ["next/core-web-vitals", "next/typescript"],
|
||||||
|
"rules": {
|
||||||
|
"@typescript-eslint/no-unused-vars": "warn",
|
||||||
|
"@next/next/no-img-element": "warn"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,20 +1,22 @@
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
// import { useParams } from 'next/navigation';
|
// import { useParams } from 'next/navigation';
|
||||||
import { MapPin, Calendar, Phone, MessageCircle, Share2, Flag, Heart } from 'lucide-react';
|
import { MapPin, Calendar, Phone, MessageCircle, Share2, Flag, Heart } from 'lucide-react';
|
||||||
// import { adts } from '@/data/adt';
|
|
||||||
import { prisma } from '@/prisma/prisma-client';
|
import { prisma } from '@/prisma/prisma-client';
|
||||||
import Header from '@/components/Header';
|
|
||||||
import { notFound } from 'next/navigation';
|
import { notFound } from 'next/navigation';
|
||||||
|
|
||||||
export default async function AdtPage({params: { id } }: { params: { id: string } }) {
|
type Params = Promise<{ id: string }>
|
||||||
|
|
||||||
|
export default async function AdtPage(props: { params: Params }) {
|
||||||
|
const params = await props.params;
|
||||||
|
|
||||||
const adt = await prisma.adt.findUnique({
|
const adt = await prisma.adt.findUnique({
|
||||||
where: {
|
where: {
|
||||||
id: Number(id),
|
id: Number(params.id),
|
||||||
},
|
},
|
||||||
include: {
|
include: {
|
||||||
user: true
|
user: true
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
if (!adt) {
|
if (!adt) {
|
||||||
return notFound();
|
return notFound();
|
||||||
|
|||||||
@ -1,11 +1,8 @@
|
|||||||
// "use client"
|
// "use client"
|
||||||
|
|
||||||
import Categories from "@/components/Categories";
|
import Categories from "@/components/Categories";
|
||||||
import Header from "@/components/Header";
|
|
||||||
import ListingCard from "@/components/ListingCard";
|
import ListingCard from "@/components/ListingCard";
|
||||||
import { adts } from "@/data/adt";
|
|
||||||
import { prisma } from "@/prisma/prisma-client";
|
import { prisma } from "@/prisma/prisma-client";
|
||||||
import Image from "next/image";
|
|
||||||
|
|
||||||
export default async function Home() {
|
export default async function Home() {
|
||||||
const adts = await prisma.adt.findMany()
|
const adts = await prisma.adt.findMany()
|
||||||
@ -28,7 +25,7 @@ export default async function Home() {
|
|||||||
|
|
||||||
<div className="grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 gap-6">
|
<div className="grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 gap-6">
|
||||||
{adts.map((adt) => (
|
{adts.map((adt) => (
|
||||||
<ListingCard key={adt.id} title={adt.title} image={adt.image} price={adt.price} location={adt.location} date={String(adt.createdAt)} id={adt.id} />
|
<ListingCard key={adt.id} title={adt.title} image={String(adt.image)} price={String(adt.price)} location={String(adt.location)} date={String(adt.createdAt)} id={String(adt.id)} />
|
||||||
))}
|
))}
|
||||||
</div>
|
</div>
|
||||||
</main>
|
</main>
|
||||||
|
|||||||
@ -1,8 +1,6 @@
|
|||||||
import React, { use } from 'react';
|
import React, { use } from 'react';
|
||||||
import { Settings, Package, Heart, Bell } from 'lucide-react';
|
import { Settings, Package, Heart, Bell } from 'lucide-react';
|
||||||
import ListingCard from '@/components/ListingCard';
|
import ListingCard from '@/components/ListingCard';
|
||||||
import { adts } from '@/data/adt';
|
|
||||||
import Header from '@/components/Header';
|
|
||||||
import { getUserSession } from '@/lib/get-user-session';
|
import { getUserSession } from '@/lib/get-user-session';
|
||||||
import { redirect } from 'next/navigation';
|
import { redirect } from 'next/navigation';
|
||||||
import { prisma } from '@/prisma/prisma-client';
|
import { prisma } from '@/prisma/prisma-client';
|
||||||
@ -76,7 +74,7 @@ export default async function Profile() {
|
|||||||
|
|
||||||
<div className="grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 gap-6">
|
<div className="grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 gap-6">
|
||||||
{user?.adts.map((adt) => (
|
{user?.adts.map((adt) => (
|
||||||
<ListingCard key={adt.id} id={String(adt.id)} image={adt.image} {...adt}/>
|
<ListingCard key={adt.id} id={String(adt.id)} image={String(adt.image)} title={String(adt.title)} price={String(adt.price)} location={String(adt.location)} date={String(adt.createdAt)}/>
|
||||||
))}
|
))}
|
||||||
</div>
|
</div>
|
||||||
</main>
|
</main>
|
||||||
|
|||||||
@ -1,8 +1,6 @@
|
|||||||
import { NextResponse } from 'next/server';
|
import { NextResponse } from 'next/server';
|
||||||
import { PrismaClient } from '@prisma/client';
|
import { PrismaClient } from '@prisma/client';
|
||||||
import { formAdtCreateSchema } from '@/components/shared/adt-create/schemas';
|
import { formAdtCreateSchema } from '@/components/shared/adt-create/schemas';
|
||||||
import { getServerSession } from 'next-auth/next';
|
|
||||||
import { authOptions } from '../auth/[...nextauth]/route';
|
|
||||||
import { getUserSession } from '@/lib/get-user-session';
|
import { getUserSession } from '@/lib/get-user-session';
|
||||||
|
|
||||||
const prisma = new PrismaClient();
|
const prisma = new PrismaClient();
|
||||||
|
|||||||
@ -1,156 +1,8 @@
|
|||||||
import NextAuth, { AuthOptions } from "next-auth"
|
import NextAuth from "next-auth"
|
||||||
import GithubProvider from "next-auth/providers/github"
|
import { authOptions } from "@/constants/auth-options"
|
||||||
import CredentialsProvider from 'next-auth/providers/credentials';
|
|
||||||
import { prisma } from "@/prisma/prisma-client";
|
|
||||||
import { compare, hashSync } from "bcrypt";
|
|
||||||
import { Role } from "@prisma/client";
|
|
||||||
|
|
||||||
export const dynamic = 'force-dynamic';
|
const handler = NextAuth(authOptions)
|
||||||
|
|
||||||
export const authOptions: AuthOptions = {
|
// Экспортируем напрямую функции GET и POST, без промежуточной переменной
|
||||||
providers: [
|
export const GET = handler
|
||||||
GithubProvider({
|
export const POST = handler
|
||||||
clientId: process.env.GITHUB_ID || '',
|
|
||||||
clientSecret: process.env.GITHUB_SECRET || '',
|
|
||||||
profile(profile) {
|
|
||||||
return {
|
|
||||||
id: profile.id,
|
|
||||||
name: profile.name || profile.login,
|
|
||||||
email: profile.email,
|
|
||||||
image: profile.avatar_url,
|
|
||||||
role: 'USER' as Role
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}),
|
|
||||||
CredentialsProvider({
|
|
||||||
name: 'Credentials',
|
|
||||||
credentials: {
|
|
||||||
email: {label: 'Email', type: 'text'},
|
|
||||||
password: {label: 'Password', type: 'password'},
|
|
||||||
},
|
|
||||||
async authorize(credentials) {
|
|
||||||
if (!credentials) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
const values = {
|
|
||||||
email: credentials.email
|
|
||||||
}
|
|
||||||
|
|
||||||
const findUser = await prisma.user.findFirst({
|
|
||||||
where: values
|
|
||||||
})
|
|
||||||
|
|
||||||
if (!findUser) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
const isPasswordValid = await compare(credentials.password, findUser.password);
|
|
||||||
|
|
||||||
if (!isPasswordValid) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
// verified //
|
|
||||||
|
|
||||||
return {
|
|
||||||
id: findUser.id,
|
|
||||||
|
|
||||||
email: findUser.email,
|
|
||||||
name: findUser.name,
|
|
||||||
role: findUser.role,
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
})
|
|
||||||
],
|
|
||||||
secret: process.env.NEXTAUTH_SECRET,
|
|
||||||
session: {
|
|
||||||
strategy: 'jwt'
|
|
||||||
},
|
|
||||||
callbacks: {
|
|
||||||
async signIn({ user, account}) {
|
|
||||||
try {
|
|
||||||
if (account?.provaider === 'credentials') {
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!user.email){
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
const findUser = await prisma.user.findFirst({
|
|
||||||
where: {
|
|
||||||
OR: [
|
|
||||||
{ provider: account?.provider, providerId: account?.providerId as string },
|
|
||||||
{ email: user.email }
|
|
||||||
]
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
if (findUser) {
|
|
||||||
await prisma.user.update({
|
|
||||||
where: {
|
|
||||||
id: findUser.id
|
|
||||||
},
|
|
||||||
data: {
|
|
||||||
provider: account?.provider,
|
|
||||||
providerId: account?.providerAccountId
|
|
||||||
}
|
|
||||||
})
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
|
|
||||||
await prisma.user.create({
|
|
||||||
data: {
|
|
||||||
email: user.email,
|
|
||||||
name: user.name || 'User #' + user.id,
|
|
||||||
password: hashSync(user.id.toString(), 10), // ИЗМЕНИТЬ
|
|
||||||
provider: account?.provider,
|
|
||||||
providerId: account?.providerAccountId
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
return true;
|
|
||||||
|
|
||||||
} catch (error) {
|
|
||||||
console.error('Error [SIGNIN]', error)
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
async jwt({ token }) {
|
|
||||||
if (!token.email) {
|
|
||||||
return token;
|
|
||||||
}
|
|
||||||
|
|
||||||
const findUser = await prisma.user.findFirst({
|
|
||||||
where: {
|
|
||||||
email: token.email
|
|
||||||
}
|
|
||||||
})
|
|
||||||
if (findUser) {
|
|
||||||
token.id = String(findUser.id);
|
|
||||||
token.email = String(findUser.email);
|
|
||||||
token.name = String(findUser.name);
|
|
||||||
token.role = String(findUser.role);
|
|
||||||
}
|
|
||||||
|
|
||||||
return token
|
|
||||||
},
|
|
||||||
session({ session, token }) {
|
|
||||||
if (session?.user) {
|
|
||||||
session.user.id = token.id,
|
|
||||||
// session.user.email = token.email,
|
|
||||||
session.user.role = token.role
|
|
||||||
}
|
|
||||||
|
|
||||||
return session;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export const handler = NextAuth(authOptions)
|
|
||||||
|
|
||||||
export { handler as GET, handler as POST }
|
|
||||||
@ -17,22 +17,22 @@ interface Props {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export const ProfileForm: React.FC<Props> = ({ data }) => {
|
export const ProfileForm: React.FC<Props> = ({ data }) => {
|
||||||
const form = useForm({
|
const form = useForm<TFormRegisterValues>({
|
||||||
resolver: zodResolver(formRegisterSchema),
|
resolver: zodResolver(formRegisterSchema),
|
||||||
defaultValues: {
|
defaultValues: {
|
||||||
name: data.name,
|
name: data.name || '',
|
||||||
email: data.email,
|
email: data.email,
|
||||||
password: '',
|
password: '',
|
||||||
confirmPassword: '',
|
confirmPassword: '',
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
const onSubmit = async (data: TFormRegisterValues) => {
|
const onSubmit = async (formData: TFormRegisterValues) => {
|
||||||
try {
|
try {
|
||||||
await updateUserInfo({
|
await updateUserInfo({
|
||||||
email: data.email,
|
email: formData.email,
|
||||||
name: data.name,
|
name: formData.name,
|
||||||
password: data.password,
|
password: formData.password,
|
||||||
});
|
});
|
||||||
|
|
||||||
// toast.error('Данные обновлены 📝', {
|
// toast.error('Данные обновлены 📝', {
|
||||||
|
|||||||
151
constants/auth-options.ts
Normal file
151
constants/auth-options.ts
Normal file
@ -0,0 +1,151 @@
|
|||||||
|
import NextAuth, { AuthOptions } from "next-auth"
|
||||||
|
import GithubProvider from "next-auth/providers/github"
|
||||||
|
import CredentialsProvider from 'next-auth/providers/credentials';
|
||||||
|
import { prisma } from "@/prisma/prisma-client";
|
||||||
|
import { compare, hashSync } from "bcrypt";
|
||||||
|
import { Role } from "@prisma/client";
|
||||||
|
|
||||||
|
|
||||||
|
export const authOptions: AuthOptions = {
|
||||||
|
providers: [
|
||||||
|
GithubProvider({
|
||||||
|
clientId: process.env.GITHUB_ID || '',
|
||||||
|
clientSecret: process.env.GITHUB_SECRET || '',
|
||||||
|
profile(profile) {
|
||||||
|
return {
|
||||||
|
id: profile.id,
|
||||||
|
name: profile.name || profile.login,
|
||||||
|
email: profile.email,
|
||||||
|
image: profile.avatar_url,
|
||||||
|
role: 'USER' as Role
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}),
|
||||||
|
CredentialsProvider({
|
||||||
|
name: 'Credentials',
|
||||||
|
credentials: {
|
||||||
|
email: {label: 'Email', type: 'text'},
|
||||||
|
password: {label: 'Password', type: 'password'},
|
||||||
|
},
|
||||||
|
async authorize(credentials) {
|
||||||
|
if (!credentials) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
const values = {
|
||||||
|
email: credentials.email
|
||||||
|
}
|
||||||
|
|
||||||
|
const findUser = await prisma.user.findFirst({
|
||||||
|
where: values
|
||||||
|
})
|
||||||
|
|
||||||
|
if (!findUser) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
const isPasswordValid = await compare(credentials.password, findUser.password);
|
||||||
|
|
||||||
|
if (!isPasswordValid) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
// verified //
|
||||||
|
|
||||||
|
return {
|
||||||
|
id: findUser.id,
|
||||||
|
|
||||||
|
email: findUser.email,
|
||||||
|
name: findUser.name,
|
||||||
|
role: findUser.role,
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
})
|
||||||
|
],
|
||||||
|
secret: process.env.NEXTAUTH_SECRET,
|
||||||
|
session: {
|
||||||
|
strategy: 'jwt'
|
||||||
|
},
|
||||||
|
callbacks: {
|
||||||
|
async signIn({ user, account}) {
|
||||||
|
try {
|
||||||
|
if (account?.provaider === 'credentials') {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!user.email){
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
const findUser = await prisma.user.findFirst({
|
||||||
|
where: {
|
||||||
|
OR: [
|
||||||
|
{ provider: account?.provider, providerId: account?.providerId as string },
|
||||||
|
{ email: user.email }
|
||||||
|
]
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
if (findUser) {
|
||||||
|
await prisma.user.update({
|
||||||
|
where: {
|
||||||
|
id: findUser.id
|
||||||
|
},
|
||||||
|
data: {
|
||||||
|
provider: account?.provider,
|
||||||
|
providerId: account?.providerAccountId
|
||||||
|
}
|
||||||
|
})
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
await prisma.user.create({
|
||||||
|
data: {
|
||||||
|
email: user.email,
|
||||||
|
name: user.name || 'User #' + user.id,
|
||||||
|
password: hashSync(user.id.toString(), 10), // ИЗМЕНИТЬ
|
||||||
|
provider: account?.provider,
|
||||||
|
providerId: account?.providerAccountId
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
return true;
|
||||||
|
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Error [SIGNIN]', error)
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
async jwt({ token }) {
|
||||||
|
if (!token.email) {
|
||||||
|
return token;
|
||||||
|
}
|
||||||
|
|
||||||
|
const findUser = await prisma.user.findFirst({
|
||||||
|
where: {
|
||||||
|
email: token.email
|
||||||
|
}
|
||||||
|
})
|
||||||
|
if (findUser) {
|
||||||
|
token.id = String(findUser.id);
|
||||||
|
token.email = String(findUser.email);
|
||||||
|
token.name = String(findUser.name);
|
||||||
|
token.role = String(findUser.role);
|
||||||
|
}
|
||||||
|
|
||||||
|
return token
|
||||||
|
},
|
||||||
|
session({ session, token }) {
|
||||||
|
if (session?.user) {
|
||||||
|
session.user.id = token.id;
|
||||||
|
// session.user.email = token.email;
|
||||||
|
session.user.role = token.role;
|
||||||
|
}
|
||||||
|
|
||||||
|
return session;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -1,4 +1,4 @@
|
|||||||
import { authOptions } from "@/app/api/auth/[...nextauth]/route"
|
import { authOptions } from "@/constants/auth-options"
|
||||||
import { getServerSession } from "next-auth"
|
import { getServerSession } from "next-auth"
|
||||||
|
|
||||||
export const getUserSession = async () => {
|
export const getUserSession = async () => {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user