• 로그인
  • 장바구니에 상품이 없습니다.

home2 게시판 Next.js 게시판 getServerSession이 null값이 나옵니다...

getServerSession이 null값이 나옵니다...

  • 이 주제에는 1개 답변, 2명 참여가 있으며 codingapple2 년 전에 전에 마지막으로 업데이트했습니다.
2 글 보임 - 1 에서 2 까지 (총 2 중에서)
  • 글쓴이
  • #88632

    강동윤
    참가자
    contents, parent 부분은 잘 출력이 되는데 getServerSession이 null 값이 나옵니다 그러니 이메일 출력도 안되네요... 어떻게 해야 할까요?
    오류메세지는 Cannot read properties of null (reading 'user') 라고 나옵니다 그런데 이미 getServerSession을 session변수에 담아 출력했을 때부터 null이라고 뜨네요
    
    api/comment.js
    import { getServerSession } from "next-auth";
    import { connectDB } from "@/util/database"; 
    import { ObjectId } from "mongodb";
    import { authOptions } from "next-auth";
    export default async function handler(req, res) {
    let session = await getServerSession(req, res, authOptions) 
     console.log(session) // 이부분이 null 값이 나옵니다.
     console.log(req.body)
    if (req.method === 'POST') {
     req.body = JSON.parse(req.body)
    let content = {
     contents: req.body.comment,
     author: session.user.email,
     parent: new ObjectId(req._id),
    }
    let client = await connectDB;
    const db = client.db('forum');
    let result = await db.collection('comment').insertOne(content);
     res.status(200).json('댓글 작성 완료');
    }
    }
    
    detail/[number]/comment.js
    
    'use client'
    import { useState } from "react"
    export default function Comment(props) {
    let [comment, setComment] = useState('')
    return (
    <div>
    <div>댓글목록</div>
    <input onChange={(e)=>{setComment(e.target.value)}}/>
    <button onClick={()=>{
    fetch('/api/comment', {
     method: 'POST',
     body: JSON.stringify({comment: comment, _id: props._id})
    })
    }}>댓글전송</button>
    </div>
     )
    }
     
    #88667

    codingapple
    키 마스터
    nextauth 설정파일에 이상한거없는지 확인하거나
    로그아웃하고 재로그인해봅시다
2 글 보임 - 1 에서 2 까지 (총 2 중에서)
  • 답변은 로그인 후 가능합니다.

About

현재 월 700명 신규수강중입니다.

  (09:00~20:00) 빠른 상담은 카톡 플러스친구 코딩애플 (링크)
  admin@codingapple.com
  이용약관
ⓒ Codingapple, 강의 예제, 영상 복제 금지
top

© Codingapple, All rights reserved. 슈퍼로켓 에듀케이션 / 서울특별시 강동구 고덕로 19길 30 / 사업자등록번호 : 212-26-14752 온라인 교육학원업 / 통신판매업신고번호 : 제 2017-서울강동-0002 호 / 개인정보관리자 : 박종흠