Next v13 support?
f00d4tehg0dz opened this issue · 1 comments
After upgrading the final branch to Next.js 13 and Next Auth 4.22.x you are no longer able to make an authenticated post. Sign-in authentication works as expected, however.
Error
[next-auth][error][CLIENT_FETCH_ERROR]
https://next-auth.js.org/errors#client_fetch_error undefined {
error: {},
url: 'http://localhost:3000/api/auth/session',
message: undefined
}
Invalid prisma.post.create() invocation:
{
data: {
title: "Test",
content: "test content",
author: {
connect: {
email: undefined,
? id?: String
}
}
}
}
I fixed this problem by copy/paste the [...nextauth].ts from (https://github.com/nextauthjs/next-auth-example/tree/main/pages/api/auth)
Then in the // pages/api/post/index.ts.
Add:
import { getServerSession } from "next-auth";
import { authOptions } from "../auth/[...nextauth]"
Remove:
import { getSession } from 'next-auth/react';
change:
const session = await getSession({ req });
to:
const session = await getServerSession(req, res, authOptions);
Hope this helps!