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 { useParams } from 'next/navigation';
|
||||
import { MapPin, Calendar, Phone, MessageCircle, Share2, Flag, Heart } from 'lucide-react';
|
||||
// import { adts } from '@/data/adt';
|
||||
import { prisma } from '@/prisma/prisma-client';
|
||||
import Header from '@/components/Header';
|
||||
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({
|
||||
where: {
|
||||
id: Number(id),
|
||||
id: Number(params.id),
|
||||
},
|
||||
include: {
|
||||
user: true
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
if (!adt) {
|
||||
return notFound();
|
||||
|
||||
@ -1,11 +1,8 @@
|
||||
// "use client"
|
||||
|
||||
import Categories from "@/components/Categories";
|
||||
import Header from "@/components/Header";
|
||||
import ListingCard from "@/components/ListingCard";
|
||||
import { adts } from "@/data/adt";
|
||||
import { prisma } from "@/prisma/prisma-client";
|
||||
import Image from "next/image";
|
||||
|
||||
export default async function Home() {
|
||||
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">
|
||||
{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>
|
||||
</main>
|
||||
|
||||
@ -1,8 +1,6 @@
|
||||
import React, { use } from 'react';
|
||||
import { Settings, Package, Heart, Bell } from 'lucide-react';
|
||||
import ListingCard from '@/components/ListingCard';
|
||||
import { adts } from '@/data/adt';
|
||||
import Header from '@/components/Header';
|
||||
import { getUserSession } from '@/lib/get-user-session';
|
||||
import { redirect } from 'next/navigation';
|
||||
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">
|
||||
{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>
|
||||
</main>
|
||||
|
||||
@ -1,8 +1,6 @@
|
||||
import { NextResponse } from 'next/server';
|
||||
import { PrismaClient } from '@prisma/client';
|
||||
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';
|
||||
|
||||
const prisma = new PrismaClient();
|
||||
|
||||
@ -1,156 +1,8 @@
|
||||
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";
|
||||
import NextAuth from "next-auth"
|
||||
import { authOptions } from "@/constants/auth-options"
|
||||
|
||||
export const dynamic = 'force-dynamic';
|
||||
const handler = NextAuth(authOptions)
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export const handler = NextAuth(authOptions)
|
||||
|
||||
export { handler as GET, handler as POST }
|
||||
// Экспортируем напрямую функции GET и POST, без промежуточной переменной
|
||||
export const GET = handler
|
||||
export const POST = handler
|
||||
@ -17,22 +17,22 @@ interface Props {
|
||||
}
|
||||
|
||||
export const ProfileForm: React.FC<Props> = ({ data }) => {
|
||||
const form = useForm({
|
||||
const form = useForm<TFormRegisterValues>({
|
||||
resolver: zodResolver(formRegisterSchema),
|
||||
defaultValues: {
|
||||
name: data.name,
|
||||
name: data.name || '',
|
||||
email: data.email,
|
||||
password: '',
|
||||
confirmPassword: '',
|
||||
},
|
||||
});
|
||||
|
||||
const onSubmit = async (data: TFormRegisterValues) => {
|
||||
const onSubmit = async (formData: TFormRegisterValues) => {
|
||||
try {
|
||||
await updateUserInfo({
|
||||
email: data.email,
|
||||
name: data.name,
|
||||
password: data.password,
|
||||
email: formData.email,
|
||||
name: formData.name,
|
||||
password: formData.password,
|
||||
});
|
||||
|
||||
// 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"
|
||||
|
||||
export const getUserSession = async () => {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user