getServerSession returns null inside getServerSideProps
Unanswered
Common Murre posted this in #help-forum
Common MurreOP
export const getServerSideProps: GetServerSideProps = async ({ res, req }) => {
const session = await getServerSession(req,res,authOptions)
console.log(session); // returns nullUser is authenticated since it works on the api and pages
import NextAuth from 'next-auth';
import GithubProvider from 'next-auth/providers/github';
import GoogleProvider from 'next-auth/providers/google';
import CredentialsProvider from 'next-auth/providers/credentials';
import connectDB from '../../../middleware/mongodb';
import User from '../../../models/user';
const providers = () => {
const p = [];
if (process.env.GITHUB_ID && process.env.GITHUB_SECRET) {
p.push(
GithubProvider({
clientId: process.env.GITHUB_ID,
clientSecret: process.env.GITHUB_SECRET,
})
);
}
p.push(
CredentialsProvider({
name: 'Credentials',
credentials: {
name: { label: 'Username', type: 'text', placeholder: 'test' },
email: { label: 'Email', type: 'text', placeholder: 'Enter your email' },
password: { label: 'Password', type: 'password' },
terms: { label: 'I agree to the terms and conditions', type: 'checkbox' },
},
async authorize(credentials, req) {
await connectDB();
// db auth logic
},
})
);
return p;
};
export const authOptions = {
providers: providers(),
pages: {
signIn: '/login',
error: '/login',
},
};
export default NextAuth(authOptions);### Version:
* next@13.4.2 - page dir
* next-auth@^4.22.1
1 Reply
Common MurreOP
Any help would be appreciated found nothing till yet