diff --git a/pages/admin.tsx b/pages/admin.tsx index 51c5c46..f8048c0 100644 --- a/pages/admin.tsx +++ b/pages/admin.tsx @@ -1,13 +1,15 @@ -import { getSession, useSession } from 'next-auth/react'; +import { useSession } from 'next-auth/react'; import { getAllSubmissions } from '../server/challengeFunctions'; import { getAllLogs } from '../server/logging'; import styles from '../styles/admin.module.scss'; import dayjs from 'dayjs'; -import { useEffect, useState } from 'react'; -import { Col, Row, Form, Button, Toast } from 'react-bootstrap'; +import { useState } from 'react'; +import { Col, Row, Form, Button } from 'react-bootstrap'; import Log from '../components/log'; import Link from 'next/link'; import { useRouter } from 'next/router'; +import { unstable_getServerSession } from 'next-auth'; +import { authOptions } from './api/auth/[...nextauth]'; export default function Admin({ submissions, logs }) { const { data: session, status } = useSession(); @@ -146,7 +148,7 @@ export default function Admin({ submissions, logs }) { } export async function getServerSideProps(context) { - const session = await getSession(context); + const session = await unstable_getServerSession(context.req, context.res, authOptions); if (session?.user.role !== "ADMIN") return { notFound: true }; let submissions = await getAllSubmissions(); if (!submissions) submissions = []; diff --git a/pages/api/changeUsername.ts b/pages/api/changeUsername.ts index e1cb1e4..5a3f56e 100644 --- a/pages/api/changeUsername.ts +++ b/pages/api/changeUsername.ts @@ -1,9 +1,10 @@ -import { getSession } from 'next-auth/react'; +import { unstable_getServerSession } from 'next-auth'; import { changeUsername } from '../../server/userFunctions'; +import { authOptions } from './auth/[...nextauth]'; export default async function submitUsername(req, res) { if (req.method === 'POST') { - const session = await getSession({ req }); + const session = await unstable_getServerSession(req, res, authOptions); if (session) { // Signed in let userId = session.user.id; @@ -24,7 +25,7 @@ export default async function submitUsername(req, res) { } //Change Username - let result = await changeUsername(userId, username); + const result = await changeUsername(userId, username); res.status(200).json({ result: result }); } else { // Not Signed in diff --git a/pages/api/deleteLogs.ts b/pages/api/deleteLogs.ts index 27982b0..b649300 100644 --- a/pages/api/deleteLogs.ts +++ b/pages/api/deleteLogs.ts @@ -1,9 +1,10 @@ -import { getSession } from 'next-auth/react'; +import { unstable_getServerSession } from 'next-auth'; import { clearAllLogs } from '../../server/logging'; +import { authOptions } from './auth/[...nextauth]'; export default async function deleteLogs(req, res) { if (req.method === 'POST') { - const session = await getSession({ req }); + const session = await unstable_getServerSession(req, res, authOptions); if (session && session.user.role !== 'ADMIN') { res.status(401).json({ error: 'Unauthorized' }); @@ -11,7 +12,7 @@ export default async function deleteLogs(req, res) { } //Delete user - let result = await clearAllLogs(); + const result = await clearAllLogs(); res.status(200).json({ result: 'success' });; return; } else { diff --git a/pages/api/deleteUser.ts b/pages/api/deleteUser.ts index 83f7e7b..9c90740 100644 --- a/pages/api/deleteUser.ts +++ b/pages/api/deleteUser.ts @@ -1,9 +1,10 @@ -import { getSession } from 'next-auth/react'; +import { unstable_getServerSession } from 'next-auth'; import { deleteAccount } from '../../server/userFunctions'; +import { authOptions } from './auth/[...nextauth]'; export default async function deleteUser(req, res) { if (req.method === 'POST') { - const session = await getSession({ req }); + const session = await unstable_getServerSession(req, res, authOptions); if (session) { // Signed in let userId = session.user.id; diff --git a/pages/api/extendTimeInstance.ts b/pages/api/extendTimeInstance.ts index 4bcc36b..0bca29a 100644 --- a/pages/api/extendTimeInstance.ts +++ b/pages/api/extendTimeInstance.ts @@ -1,9 +1,10 @@ -import { getSession } from 'next-auth/react'; +import { unstable_getServerSession } from 'next-auth'; import { userEnabled } from '../../server/userFunctions'; +import { authOptions } from './auth/[...nextauth]'; export default async function extendTimeInstance(req, res) { if (req.method === 'POST') { - const session = await getSession({ req }); + const session = await unstable_getServerSession(req, res, authOptions); if (session) { // Signed in let userId = session.user.id; diff --git a/pages/api/getTimeLeft.ts b/pages/api/getTimeLeft.ts index bd29c7c..252b617 100644 --- a/pages/api/getTimeLeft.ts +++ b/pages/api/getTimeLeft.ts @@ -1,9 +1,10 @@ -import { getSession } from 'next-auth/react'; +import { unstable_getServerSession } from 'next-auth'; import { userEnabled } from '../../server/userFunctions'; +import { authOptions } from './auth/[...nextauth]'; export default async function getTimeLeft(req, res) { if (req.method === 'POST') { - const session = await getSession({ req }); + const session = await unstable_getServerSession(req, res, authOptions); if (session) { // Signed in let userId = session.user.id; diff --git a/pages/api/startInstance.ts b/pages/api/startInstance.ts index 6db8541..ae73702 100644 --- a/pages/api/startInstance.ts +++ b/pages/api/startInstance.ts @@ -1,10 +1,11 @@ +import { unstable_getServerSession } from 'next-auth'; import { getSession } from 'next-auth/react'; import { validateChallengeHash } from '../../server/challengeFunctions'; import { userEnabled } from '../../server/userFunctions'; export default async function startInstance(req, res) { if (req.method === 'POST') { - const session = await getSession({ req }); + const session = await unstable_getServerSession(req, res, authOptions); if (session) { // Signed in let userId = session.user.id; diff --git a/pages/api/stopInstance.ts b/pages/api/stopInstance.ts index dd92a1a..5756803 100644 --- a/pages/api/stopInstance.ts +++ b/pages/api/stopInstance.ts @@ -1,9 +1,10 @@ -import { getSession } from 'next-auth/react'; +import { unstable_getServerSession } from 'next-auth'; import { userEnabled } from '../../server/userFunctions'; +import { authOptions } from './auth/[...nextauth]'; export default async function stopInstance(req, res) { if (req.method === 'POST') { - const session = await getSession({ req }); + const session = await unstable_getServerSession(req, res, authOptions); if (session) { // Signed in let userId = session.user.id; diff --git a/pages/api/submitFlag.ts b/pages/api/submitFlag.ts index 6c98fc9..b77e239 100644 --- a/pages/api/submitFlag.ts +++ b/pages/api/submitFlag.ts @@ -1,10 +1,11 @@ -import { getSession } from "next-auth/react" +import { unstable_getServerSession } from "next-auth"; import { getChallengeById, getLastSubmission, submitFlag } from '../../server/challengeFunctions'; import { userEnabled } from "../../server/userFunctions"; +import { authOptions } from "./auth/[...nextauth]"; export default async function submit(req, res) { if (req.method === 'POST') { - const session = await getSession({ req }) + const session = await unstable_getServerSession(req, res, authOptions); if (session) { // Signed in let userId = session.user.id; diff --git a/pages/challenges.tsx b/pages/challenges.tsx index d520982..1abe89f 100644 --- a/pages/challenges.tsx +++ b/pages/challenges.tsx @@ -1,5 +1,5 @@ import { authOptions } from "./api/auth/[...nextauth]" -import { getSession, useSession } from 'next-auth/react'; +import { useSession } from 'next-auth/react'; import { useState } from 'react'; import { Col, Row } from 'react-bootstrap'; import Challenge from '../components/challenge'; diff --git a/pages/profile.tsx b/pages/profile.tsx index 270dd59..a0dbcc5 100644 --- a/pages/profile.tsx +++ b/pages/profile.tsx @@ -1,4 +1,4 @@ -import { getSession, signOut, useSession } from 'next-auth/react'; +import { signOut, useSession } from 'next-auth/react'; import { useState } from 'react'; import { Button, Row, Col } from 'react-bootstrap'; import ModalForm from '../components/modalForm';