We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
System: OS: Windows 10 10.0.22621 CPU: (16) x64 AMD Ryzen 7 7700 8-Core Processor Memory: 19.88 GB / 31.15 GB Binaries: Node: 20.3.1 - C:\Program Files\nodejs\node.EXE Yarn: 1.22.19 - ~\AppData\Roaming\npm\yarn.CMD npm: 9.8.1 - C:\Program Files\nodejs\npm.CMD Browsers: Edge: Spartan (44.22621.1992.0), Chromium (115.0.1901.188) Internet Explorer: 11.0.22621.1
i dont have one
I'm right now testing the new features and when i try a server nextjs component like this:
const Profile = async () => { const user: UserSession | null = await getServerSession(authOptions); const userInfo = await fetch(process.env.API_URL + 'user', { method: 'GET' }).then((res)=>res.json()) .then ((data) => data) .catch((error) => console.error(error)) return ( <div className={styles.profileContainer}> <div> <h1>Profile picture {userInfo}</h1><br/> <EditImage imageUrl={user?.image as string}/> </div> <EditableInput endpoint='changename' text={user?.name} placeholder='Put the new name' title='Name'/> </div>) } export default Profile
the user endpoint always return unauthorized, when you try it into a client component it works normally.
Create an endpoint with authentication in Nextjs 13 with session handling:
import { NextResponse } from "next/server"; import { PrismaClient } from "@prisma/client"; import { getServerSession } from 'next-auth' import { UserSession } from "@/interfaces/user"; import { authOptions } from "../auth/[...nextauth]/authOptions";
const prisma = new PrismaClient()
export async function GET () { const userSession: userSession | null = await getServerSession(authOptions) if(userSession) { try { const user = await prisma.user.findUnique({ where: { id: userSession?.id }, }) return NextResponse.json({user}) } catch { return NextResponse.json("Not found", { status: 400 }) } } else return NextResponse.json("Not Authorized", { status: 401 }) }
Call it inside a next server component always userSession is null
It should return the session information and is returning null.
The text was updated successfully, but these errors were encountered:
check out the pinned issue #7423 (comment)
Sorry, something went wrong.
No branches or pull requests
Environment
System:
OS: Windows 10 10.0.22621
CPU: (16) x64 AMD Ryzen 7 7700 8-Core Processor
Memory: 19.88 GB / 31.15 GB
Binaries:
Node: 20.3.1 - C:\Program Files\nodejs\node.EXE
Yarn: 1.22.19 - ~\AppData\Roaming\npm\yarn.CMD
npm: 9.8.1 - C:\Program Files\nodejs\npm.CMD
Browsers:
Edge: Spartan (44.22621.1992.0), Chromium (115.0.1901.188)
Internet Explorer: 11.0.22621.1
Reproduction URL
i dont have one
Describe the issue
I'm right now testing the new features and when i try a server nextjs component like this:
the user endpoint always return unauthorized, when you try it into a client component it works normally.
How to reproduce
Create an endpoint with authentication in Nextjs 13 with session handling:
import { NextResponse } from "next/server";
import { PrismaClient } from "@prisma/client";
import { getServerSession } from 'next-auth'
import { UserSession } from "@/interfaces/user";
import { authOptions } from "../auth/[...nextauth]/authOptions";
const prisma = new PrismaClient()
Call it inside a next server component always userSession is null
Expected behavior
It should return the session information and is returning null.
The text was updated successfully, but these errors were encountered: