diff --git a/pages/api/auth/[...nextauth].ts b/pages/api/auth/[...nextauth].ts index 098b95b..6020c99 100644 --- a/pages/api/auth/[...nextauth].ts +++ b/pages/api/auth/[...nextauth].ts @@ -70,21 +70,6 @@ export const authOptions: NextAuthOptions = { password: { label: "Парола", type: "password" } }, async authorize(credentials, req) { - //const user = { id: "1", name: "Администратора", email: "jsmith@example.com" } - //return user - // const res = await fetch("/your/endpoint", { - // method: 'POST', - // body: JSON.stringify(credentials), - // headers: { "Content-Type": "application/json" } - // }) - // const user = await res.json() - - // // If no error and we have user data, return it - // if (res.ok && user) { - // return user - // } - // // Return null if user data could not be retrieved - // return null const users = [ { id: "1", name: "admin", email: "admin@example.com", password: "admin123", role: "ADMIN", static: true }, { id: "2", name: "krasi", email: "krasi@example.com", password: "krasi123", role: "ADMIN", static: true }, @@ -272,6 +257,8 @@ export const authOptions: NextAuthOptions = { verifyRequest: "/auth/verify-request", // (used for check email message) newUser: null // If set, new users will be directed here on first sign in }, + + debug: process.env.NODE_ENV === 'development', } export default NextAuth(authOptions) \ No newline at end of file diff --git a/pages/cart/publishers/index.tsx b/pages/cart/publishers/index.tsx index 896ec40..57d9d35 100644 --- a/pages/cart/publishers/index.tsx +++ b/pages/cart/publishers/index.tsx @@ -8,6 +8,7 @@ import Layout from "../../../components/layout"; import PublisherCard from "../../../components/publisher/PublisherCard"; import axiosInstance from "../../../src/axiosSecure"; import axiosServer from '../../../src/axiosServer'; +const common = require("../../../src/helpers/common"); import toast from "react-hot-toast"; import { levenshteinEditDistance } from "levenshtein-edit-distance"; @@ -226,9 +227,38 @@ export default PublishersPage; //import { set } from "date-fns"; export const getServerSideProps = async (context) => { - const axios = await axiosServer(context); - //ToDo: refactor all axios calls to use axiosInstance and this URL - const { data: publishers } = await axios.get('/api/data/publishers?select=id,firstName,lastName,email,isActive,isTrained,isImported,assignments.shift.startTime,availabilities.startTime&dev=fromuseefect'); + // const axios = await axiosServer(context); + // //ToDo: refactor all axios calls to use axiosInstance and this URL + // const { data: publishers } = await axios.get('/api/data/publishers?select=id,firstName,lastName,email,isActive,isTrained,isImported,assignments.shift.startTime,availabilities.startTime&dev=fromuseefect'); + //use prisma instead of axios + const prisma = common.getPrismaClient(); + let publishers = await prisma.publisher.findMany({ + select: { + id: true, + firstName: true, + lastName: true, + email: true, + isActive: true, + isTrained: true, + isImported: true, + assignments: { + select: { + shift: { + select: { + startTime: true, + }, + }, + }, + }, + availabilities: { + select: { + startTime: true, + }, + }, + } + }); + publishers = JSON.parse(JSON.stringify(publishers)); + return { props: { diff --git a/pages/cart/publishers/myschedule.tsx b/pages/cart/publishers/myschedule.tsx index 952d9aa..bda1015 100644 --- a/pages/cart/publishers/myschedule.tsx +++ b/pages/cart/publishers/myschedule.tsx @@ -14,6 +14,8 @@ import { useSession, getSession } from 'next-auth/react'; import axiosInstance from 'src/axiosSecure'; import { toast } from 'react-toastify'; import LocalShippingIcon from '@mui/icons-material/LocalShipping'; +import { getServerSession } from 'next-auth'; +import { authOptions } from 'pages/api/auth/[...nextauth]'; export default function MySchedulePage({ assignments }) { @@ -160,7 +162,7 @@ export default function MySchedulePage({ assignments }) { //get future assignments for the current user (session.user.id) export const getServerSideProps = async (context) => { - const session = await getSession(context); + const session = await getServerSession(context.req, context.res, authOptions) context.res.setHeader("Cache-Control", "s-maxage=1, stale-while-revalidate");