Merge pull request #36 from Ravinou/update-nextAuth-method

update: getServerSession is now stable for NextAuth
This commit is contained in:
Ravinou 2023-04-18 18:31:02 +02:00 committed by GitHub
commit cc54d0d6ba
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
27 changed files with 53 additions and 53 deletions

View file

@ -3,7 +3,7 @@ import Head from 'next/head';
import 'react-toastify/dist/ReactToastify.css'; import 'react-toastify/dist/ReactToastify.css';
import { useSession } from 'next-auth/react'; import { useSession } from 'next-auth/react';
import { authOptions } from '../../pages/api/auth/[...nextauth]'; import { authOptions } from '../../pages/api/auth/[...nextauth]';
import { unstable_getServerSession } from 'next-auth/next'; import { getServerSession } from 'next-auth/next';
//Components //Components
import UserSettings from '../../Containers/UserSettings/UserSettings'; import UserSettings from '../../Containers/UserSettings/UserSettings';
@ -29,7 +29,7 @@ export default function Account() {
export async function getServerSideProps(context) { export async function getServerSideProps(context) {
//Var //Var
const session = await unstable_getServerSession( const session = await getServerSession(
context.req, context.req,
context.res, context.res,
authOptions authOptions

View file

@ -2,12 +2,12 @@
import { promises as fs } from 'fs'; import { promises as fs } from 'fs';
import path from 'path'; import path from 'path';
import { authOptions } from '../auth/[...nextauth]'; import { authOptions } from '../auth/[...nextauth]';
import { unstable_getServerSession } from 'next-auth/next'; import { getServerSession } from 'next-auth/next';
export default async function handler(req, res) { export default async function handler(req, res) {
if (req.method == 'GET') { if (req.method == 'GET') {
//Verify that the user is logged in. //Verify that the user is logged in.
const session = await unstable_getServerSession(req, res, authOptions); const session = await getServerSession(req, res, authOptions);
if (!session) { if (!session) {
res.status(401).json({ message: 'You must be logged in.' }); res.status(401).json({ message: 'You must be logged in.' });
return; return;

View file

@ -2,12 +2,12 @@
import { promises as fs } from 'fs'; import { promises as fs } from 'fs';
import path from 'path'; import path from 'path';
import { authOptions } from '../auth/[...nextauth]'; import { authOptions } from '../auth/[...nextauth]';
import { unstable_getServerSession } from 'next-auth/next'; import { getServerSession } from 'next-auth/next';
export default async function handler(req, res) { export default async function handler(req, res) {
if (req.method == 'GET') { if (req.method == 'GET') {
//Verify that the user is logged in. //Verify that the user is logged in.
const session = await unstable_getServerSession(req, res, authOptions); const session = await getServerSession(req, res, authOptions);
if (!session) { if (!session) {
res.status(401).json({ message: 'You must be logged in.' }); res.status(401).json({ message: 'You must be logged in.' });
return; return;

View file

@ -2,12 +2,12 @@
import { promises as fs } from 'fs'; import { promises as fs } from 'fs';
import path from 'path'; import path from 'path';
import { authOptions } from '../auth/[...nextauth]'; import { authOptions } from '../auth/[...nextauth]';
import { unstable_getServerSession } from 'next-auth/next'; import { getServerSession } from 'next-auth/next';
export default async function handler(req, res) { export default async function handler(req, res) {
if (req.method == 'GET') { if (req.method == 'GET') {
//Verify that the user is logged in. //Verify that the user is logged in.
const session = await unstable_getServerSession(req, res, authOptions); const session = await getServerSession(req, res, authOptions);
if (!session) { if (!session) {
res.status(401).json({ message: 'You must be logged in.' }); res.status(401).json({ message: 'You must be logged in.' });
return; return;

View file

@ -2,12 +2,12 @@
import { promises as fs } from 'fs'; import { promises as fs } from 'fs';
import path from 'path'; import path from 'path';
import { authOptions } from '../auth/[...nextauth]'; import { authOptions } from '../auth/[...nextauth]';
import { unstable_getServerSession } from 'next-auth/next'; import { getServerSession } from 'next-auth/next';
export default async function handler(req, res) { export default async function handler(req, res) {
if (req.method == 'GET') { if (req.method == 'GET') {
//Verify that the user is logged in. //Verify that the user is logged in.
const session = await unstable_getServerSession(req, res, authOptions); const session = await getServerSession(req, res, authOptions);
if (!session) { if (!session) {
res.status(401).json({ message: 'You must be logged in.' }); res.status(401).json({ message: 'You must be logged in.' });
return; return;

View file

@ -1,6 +1,6 @@
//Lib //Lib
import { authOptions } from '../auth/[...nextauth]'; import { authOptions } from '../auth/[...nextauth]';
import { unstable_getServerSession } from 'next-auth/next'; import { getServerSession } from 'next-auth/next';
import { promises as fs } from 'fs'; import { promises as fs } from 'fs';
import path from 'path'; import path from 'path';
const { exec } = require('child_process'); const { exec } = require('child_process');
@ -8,7 +8,7 @@ const { exec } = require('child_process');
export default async function handler(req, res) { export default async function handler(req, res) {
if (req.method == 'POST') { if (req.method == 'POST') {
//Verify that the user is logged in. //Verify that the user is logged in.
const session = await unstable_getServerSession(req, res, authOptions); const session = await getServerSession(req, res, authOptions);
if (!session) { if (!session) {
res.status(401).json({ message: 'You must be logged in.' }); res.status(401).json({ message: 'You must be logged in.' });
return; return;

View file

@ -1,13 +1,13 @@
//Lib //Lib
import { authOptions } from '../auth/[...nextauth]'; import { authOptions } from '../auth/[...nextauth]';
import { unstable_getServerSession } from 'next-auth/next'; import { getServerSession } from 'next-auth/next';
import nodemailerSMTP from '../../../helpers/functions/nodemailerSMTP'; import nodemailerSMTP from '../../../helpers/functions/nodemailerSMTP';
import emailTest from '../../../helpers/templates/emailTest'; import emailTest from '../../../helpers/templates/emailTest';
export default async function handler(req, res) { export default async function handler(req, res) {
if (req.method == 'POST') { if (req.method == 'POST') {
//Verify that the user is logged in. //Verify that the user is logged in.
const session = await unstable_getServerSession(req, res, authOptions); const session = await getServerSession(req, res, authOptions);
if (!session) { if (!session) {
res.status(401).json({ message: 'You must be logged in.' }); res.status(401).json({ message: 'You must be logged in.' });
return; return;

View file

@ -2,12 +2,12 @@
import { promises as fs } from 'fs'; import { promises as fs } from 'fs';
import path from 'path'; import path from 'path';
import { authOptions } from '../auth/[...nextauth]'; import { authOptions } from '../auth/[...nextauth]';
import { unstable_getServerSession } from 'next-auth/next'; import { getServerSession } from 'next-auth/next';
export default async function handler(req, res) { export default async function handler(req, res) {
if (req.method == 'PUT') { if (req.method == 'PUT') {
//Verify that the user is logged in. //Verify that the user is logged in.
const session = await unstable_getServerSession(req, res, authOptions); const session = await getServerSession(req, res, authOptions);
if (!session) { if (!session) {
res.status(401).json({ message: 'You must be logged in.' }); res.status(401).json({ message: 'You must be logged in.' });
return; return;

View file

@ -2,12 +2,12 @@
import { promises as fs } from 'fs'; import { promises as fs } from 'fs';
import path from 'path'; import path from 'path';
import { authOptions } from '../auth/[...nextauth]'; import { authOptions } from '../auth/[...nextauth]';
import { unstable_getServerSession } from 'next-auth/next'; import { getServerSession } from 'next-auth/next';
export default async function handler(req, res) { export default async function handler(req, res) {
if (req.method == 'PUT') { if (req.method == 'PUT') {
//Verify that the user is logged in. //Verify that the user is logged in.
const session = await unstable_getServerSession(req, res, authOptions); const session = await getServerSession(req, res, authOptions);
if (!session) { if (!session) {
res.status(401).json({ message: 'You must be logged in.' }); res.status(401).json({ message: 'You must be logged in.' });
return; return;

View file

@ -2,12 +2,12 @@
import { promises as fs } from 'fs'; import { promises as fs } from 'fs';
import path from 'path'; import path from 'path';
import { authOptions } from '../auth/[...nextauth]'; import { authOptions } from '../auth/[...nextauth]';
import { unstable_getServerSession } from 'next-auth/next'; import { getServerSession } from 'next-auth/next';
export default async function handler(req, res) { export default async function handler(req, res) {
if (req.method == 'PUT') { if (req.method == 'PUT') {
//Verify that the user is logged in. //Verify that the user is logged in.
const session = await unstable_getServerSession(req, res, authOptions); const session = await getServerSession(req, res, authOptions);
if (!session) { if (!session) {
res.status(401).json({ message: 'You must be logged in.' }); res.status(401).json({ message: 'You must be logged in.' });
return; return;

View file

@ -2,12 +2,12 @@
import { promises as fs } from 'fs'; import { promises as fs } from 'fs';
import path from 'path'; import path from 'path';
import { authOptions } from '../auth/[...nextauth]'; import { authOptions } from '../auth/[...nextauth]';
import { unstable_getServerSession } from 'next-auth/next'; import { getServerSession } from 'next-auth/next';
export default async function handler(req, res) { export default async function handler(req, res) {
if (req.method == 'PUT') { if (req.method == 'PUT') {
//Verify that the user is logged in. //Verify that the user is logged in.
const session = await unstable_getServerSession(req, res, authOptions); const session = await getServerSession(req, res, authOptions);
if (!session) { if (!session) {
res.status(401).json({ message: 'You must be logged in.' }); res.status(401).json({ message: 'You must be logged in.' });
return; return;

View file

@ -2,12 +2,12 @@
import { promises as fs } from 'fs'; import { promises as fs } from 'fs';
import path from 'path'; import path from 'path';
import { authOptions } from '../auth/[...nextauth]'; import { authOptions } from '../auth/[...nextauth]';
import { unstable_getServerSession } from 'next-auth/next'; import { getServerSession } from 'next-auth/next';
export default async function handler(req, res) { export default async function handler(req, res) {
if (req.method == 'PUT') { if (req.method == 'PUT') {
//Verify that the user is logged in. //Verify that the user is logged in.
const session = await unstable_getServerSession(req, res, authOptions); const session = await getServerSession(req, res, authOptions);
if (!session) { if (!session) {
res.status(401).json({ message: 'You must be logged in.' }); res.status(401).json({ message: 'You must be logged in.' });
return; return;

View file

@ -3,12 +3,12 @@ import { hashPassword, verifyPassword } from '../../../helpers/functions/auth';
import { promises as fs } from 'fs'; import { promises as fs } from 'fs';
import path from 'path'; import path from 'path';
import { authOptions } from '../auth/[...nextauth]'; import { authOptions } from '../auth/[...nextauth]';
import { unstable_getServerSession } from 'next-auth/next'; import { getServerSession } from 'next-auth/next';
export default async function handler(req, res) { export default async function handler(req, res) {
if (req.method == 'PUT') { if (req.method == 'PUT') {
//Verify that the user is logged in. //Verify that the user is logged in.
const session = await unstable_getServerSession(req, res, authOptions); const session = await getServerSession(req, res, authOptions);
if (!session) { if (!session) {
res.status(401).json({ message: 'You must be logged in.' }); res.status(401).json({ message: 'You must be logged in.' });
return; return;

View file

@ -2,12 +2,12 @@
import { promises as fs } from 'fs'; import { promises as fs } from 'fs';
import path from 'path'; import path from 'path';
import { authOptions } from '../auth/[...nextauth]'; import { authOptions } from '../auth/[...nextauth]';
import { unstable_getServerSession } from 'next-auth/next'; import { getServerSession } from 'next-auth/next';
export default async function handler(req, res) { export default async function handler(req, res) {
if (req.method == 'PUT') { if (req.method == 'PUT') {
//Verify that the user is logged in. //Verify that the user is logged in.
const session = await unstable_getServerSession(req, res, authOptions); const session = await getServerSession(req, res, authOptions);
if (!session) { if (!session) {
res.status(401).json({ message: 'You must be logged in.' }); res.status(401).json({ message: 'You must be logged in.' });
return; return;

View file

@ -5,7 +5,7 @@ import { verifyPassword } from '../../../helpers/functions/auth';
import fs from 'fs'; import fs from 'fs';
import path from 'path'; import path from 'path';
////Use if need getServerSideProps and therefore unstable_getServerSession ////Use if need getServerSideProps and therefore getServerSession
export const authOptions = { export const authOptions = {
providers: [ providers: [
CredentialsProvider({ CredentialsProvider({

View file

@ -1,14 +1,14 @@
import { promises as fs } from 'fs'; import { promises as fs } from 'fs';
import path from 'path'; import path from 'path';
import { authOptions } from '../../../pages/api/auth/[...nextauth]'; import { authOptions } from '../../../pages/api/auth/[...nextauth]';
import { unstable_getServerSession } from 'next-auth/next'; import { getServerSession } from 'next-auth/next';
const util = require('node:util'); const util = require('node:util');
const exec = util.promisify(require('node:child_process').exec); const exec = util.promisify(require('node:child_process').exec);
export default async function handler(req, res) { export default async function handler(req, res) {
if (req.method == 'POST') { if (req.method == 'POST') {
//Verify that the user is logged in. //Verify that the user is logged in.
const session = await unstable_getServerSession(req, res, authOptions); const session = await getServerSession(req, res, authOptions);
if (!session) { if (!session) {
res.status(401).json({ message: 'You must be logged in.' }); res.status(401).json({ message: 'You must be logged in.' });
return; return;

View file

@ -1,14 +1,14 @@
import { promises as fs } from 'fs'; import { promises as fs } from 'fs';
import path from 'path'; import path from 'path';
import { authOptions } from '../../../auth/[...nextauth]'; import { authOptions } from '../../../auth/[...nextauth]';
import { unstable_getServerSession } from 'next-auth/next'; import { getServerSession } from 'next-auth/next';
const util = require('node:util'); const util = require('node:util');
const exec = util.promisify(require('node:child_process').exec); const exec = util.promisify(require('node:child_process').exec);
export default async function handler(req, res) { export default async function handler(req, res) {
if (req.method == 'DELETE') { if (req.method == 'DELETE') {
//Verify that the user is logged in. //Verify that the user is logged in.
const session = await unstable_getServerSession(req, res, authOptions); const session = await getServerSession(req, res, authOptions);
if (!session) { if (!session) {
res.status(401).json({ message: 'You must be logged in.' }); res.status(401).json({ message: 'You must be logged in.' });
return; return;

View file

@ -1,12 +1,12 @@
import { promises as fs } from 'fs'; import { promises as fs } from 'fs';
import path from 'path'; import path from 'path';
import { authOptions } from '../../../auth/[...nextauth]'; import { authOptions } from '../../../auth/[...nextauth]';
import { unstable_getServerSession } from 'next-auth/next'; import { getServerSession } from 'next-auth/next';
export default async function handler(req, res) { export default async function handler(req, res) {
if (req.method == 'PUT') { if (req.method == 'PUT') {
//Verify that the user is logged in. //Verify that the user is logged in.
const session = await unstable_getServerSession(req, res, authOptions); const session = await getServerSession(req, res, authOptions);
if (!session) { if (!session) {
res.status(401).json({ message: 'You must be logged in.' }); res.status(401).json({ message: 'You must be logged in.' });
return; return;

View file

@ -1,14 +1,14 @@
import { promises as fs } from 'fs'; import { promises as fs } from 'fs';
import path from 'path'; import path from 'path';
import { authOptions } from '../../../auth/[...nextauth]'; import { authOptions } from '../../../auth/[...nextauth]';
import { unstable_getServerSession } from 'next-auth/next'; import { getServerSession } from 'next-auth/next';
const util = require('node:util'); const util = require('node:util');
const exec = util.promisify(require('node:child_process').exec); const exec = util.promisify(require('node:child_process').exec);
export default async function handler(req, res) { export default async function handler(req, res) {
if (req.method == 'PUT') { if (req.method == 'PUT') {
//Verify that the user is logged in. //Verify that the user is logged in.
const session = await unstable_getServerSession(req, res, authOptions); const session = await getServerSession(req, res, authOptions);
if (!session) { if (!session) {
res.status(401).json({ message: 'You must be logged in.' }); res.status(401).json({ message: 'You must be logged in.' });
return; return;

View file

@ -1,12 +1,12 @@
import { promises as fs } from 'fs'; import { promises as fs } from 'fs';
import path from 'path'; import path from 'path';
import { authOptions } from '../../../auth/[...nextauth]'; import { authOptions } from '../../../auth/[...nextauth]';
import { unstable_getServerSession } from 'next-auth/next'; import { getServerSession } from 'next-auth/next';
export default async function handler(req, res) { export default async function handler(req, res) {
if (req.method == 'GET') { if (req.method == 'GET') {
//Verify that the user is logged in. //Verify that the user is logged in.
const session = await unstable_getServerSession(req, res, authOptions); const session = await getServerSession(req, res, authOptions);
if (!session) { if (!session) {
res.status(401).json({ message: 'You must be logged in.' }); res.status(401).json({ message: 'You must be logged in.' });
return; return;

View file

@ -1,12 +1,12 @@
import fs from 'fs'; import fs from 'fs';
import path from 'path'; import path from 'path';
import { authOptions } from '../../../pages/api/auth/[...nextauth]'; import { authOptions } from '../../../pages/api/auth/[...nextauth]';
import { unstable_getServerSession } from 'next-auth/next'; import { getServerSession } from 'next-auth/next';
export default async function handler(req, res) { export default async function handler(req, res) {
if (req.method == 'GET') { if (req.method == 'GET') {
//Verify that the user is logged in. //Verify that the user is logged in.
const session = await unstable_getServerSession(req, res, authOptions); const session = await getServerSession(req, res, authOptions);
if (!session) { if (!session) {
// res.status(401).json({ message: 'You must be logged in.' }); // res.status(401).json({ message: 'You must be logged in.' });
res.status(401).end(); res.status(401).end();

View file

@ -1,6 +1,6 @@
//Lib //Lib
import { authOptions } from '../pages/api/auth/[...nextauth]'; import { authOptions } from '../pages/api/auth/[...nextauth]';
import { unstable_getServerSession } from 'next-auth/next'; import { getServerSession } from 'next-auth/next';
import { useSession } from 'next-auth/react'; import { useSession } from 'next-auth/react';
import Head from 'next/head'; import Head from 'next/head';
@ -32,7 +32,7 @@ export default function Index() {
export async function getServerSideProps(context) { export async function getServerSideProps(context) {
//Var //Var
const session = await unstable_getServerSession( const session = await getServerSession(
context.req, context.req,
context.res, context.res,
authOptions authOptions

View file

@ -5,7 +5,7 @@ import { useState } from 'react';
import { SpinnerDotted } from 'spinners-react'; import { SpinnerDotted } from 'spinners-react';
import { useRouter } from 'next/router'; import { useRouter } from 'next/router';
import { authOptions } from './api/auth/[...nextauth]'; import { authOptions } from './api/auth/[...nextauth]';
import { unstable_getServerSession } from 'next-auth/next'; import { getServerSession } from 'next-auth/next';
//Components //Components
import Error from '../Components/UI/Error/Error'; import Error from '../Components/UI/Error/Error';
@ -179,7 +179,7 @@ export default function Login() {
export async function getServerSideProps(context) { export async function getServerSideProps(context) {
//Var //Var
const session = await unstable_getServerSession( const session = await getServerSession(
context.req, context.req,
context.res, context.res,
authOptions authOptions

View file

@ -1,6 +1,6 @@
import RepoList from '../../Containers/RepoList/RepoList'; import RepoList from '../../Containers/RepoList/RepoList';
import { authOptions } from '../../pages/api/auth/[...nextauth]'; import { authOptions } from '../../pages/api/auth/[...nextauth]';
import { unstable_getServerSession } from 'next-auth/next'; import { getServerSession } from 'next-auth/next';
export default function Add() { export default function Add() {
return <RepoList />; return <RepoList />;
@ -8,7 +8,7 @@ export default function Add() {
export async function getServerSideProps(context) { export async function getServerSideProps(context) {
//Var //Var
const session = await unstable_getServerSession( const session = await getServerSession(
context.req, context.req,
context.res, context.res,
authOptions authOptions

View file

@ -1,6 +1,6 @@
import RepoList from '../../../Containers/RepoList/RepoList'; import RepoList from '../../../Containers/RepoList/RepoList';
import { authOptions } from '../../../pages/api/auth/[...nextauth]'; import { authOptions } from '../../../pages/api/auth/[...nextauth]';
import { unstable_getServerSession } from 'next-auth/next'; import { getServerSession } from 'next-auth/next';
export default function Add() { export default function Add() {
return <RepoList />; return <RepoList />;
@ -8,7 +8,7 @@ export default function Add() {
export async function getServerSideProps(context) { export async function getServerSideProps(context) {
//Var //Var
const session = await unstable_getServerSession( const session = await getServerSession(
context.req, context.req,
context.res, context.res,
authOptions authOptions

View file

@ -1,6 +1,6 @@
import Head from 'next/head'; import Head from 'next/head';
import { authOptions } from '../../pages/api/auth/[...nextauth]'; import { authOptions } from '../../pages/api/auth/[...nextauth]';
import { unstable_getServerSession } from 'next-auth/next'; import { getServerSession } from 'next-auth/next';
//Components //Components
import StorageUsedChartBar from '../../Containers/Monitoring/StorageUsedChartBar/StorageUsedChartBar'; import StorageUsedChartBar from '../../Containers/Monitoring/StorageUsedChartBar/StorageUsedChartBar';
@ -47,7 +47,7 @@ export default function Monitoring() {
export async function getServerSideProps(context) { export async function getServerSideProps(context) {
//Var //Var
const session = await unstable_getServerSession( const session = await getServerSession(
context.req, context.req,
context.res, context.res,
authOptions authOptions

View file

@ -3,7 +3,7 @@ import SetupWizard from '../../Containers/SetupWizard/SetupWizard';
import { useRouter } from 'next/router'; import { useRouter } from 'next/router';
import Head from 'next/head'; import Head from 'next/head';
import { authOptions } from '../../pages/api/auth/[...nextauth]'; import { authOptions } from '../../pages/api/auth/[...nextauth]';
import { unstable_getServerSession } from 'next-auth/next'; import { getServerSession } from 'next-auth/next';
export default function SetupWizardStep() { export default function SetupWizardStep() {
////Var ////Var
@ -22,7 +22,7 @@ export default function SetupWizardStep() {
export async function getServerSideProps(context) { export async function getServerSideProps(context) {
//Var //Var
const session = await unstable_getServerSession( const session = await getServerSession(
context.req, context.req,
context.res, context.res,
authOptions authOptions