[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
}
๋ฅ์คํธ๋ฅผ ์ฌ์ฉํ ํ๋ก์ ํธ๋ฅผ ํ๋ ์ค ์ด๋ฌํ CLIENT_FETCH_ERROR ์๋ฌ๋ฅผ ๋ง๋ฌ๋ค.
ํด๋ผ์ด์ธํธ ๋ถ๋ถ์์๋ session์ด ์กด์ฌํ์ง๋ง, api route์์๋ session์ ์ฐพ์ ์ ์์๋ค.
๋ฅ์คํธ ๊ณต์ ๋ฌธ์์์๋ ์๋ฌ์ ์ด์ ๊ฐ ์ฌ๋ฌ๊ฐ์ง ์๋ค๊ณ ํ๋ฆฌ๋ฉํ
ํ๊ฒ ๋งํด์ ใ
ใ
์ง์ ๊ตฌ๊ธ๋ง์ ๋ค์ด๊ฐ๋ค..
๊ทธ๋ฌ๋ค๊ฐ โsecretโ property์ ๋ํด ์๊ฒ ๋์๋ค.
โNextAuth.js used to generate a secret for convenience, when the user did not define one. This might have been useful in development, but can be a concern in production. We have always been clear about that in the docs, but from now on, if you forget to define a secret property in production, we will show the user an error page.โ
๋ฐ๋ผ์ โsecretโ property์ ๋ํ ์ค์ ์ ํด์ฃผ๊ธฐ๋ก ํ๋ค.
export const authOptions = {
session: {
strategy: "jwt",
},
providers: [
...
],
secret: process.env.NEXTAUTH_SECRET,
}
export default NextAuth(authOptions)
api route ๋ถ๋ถ์ด๋ผ ์๋ฒ์ฌ์ด๋๋ผ์ getSession์ด ์๋ getServerSession๋ก ๋ณ๊ฒฝํด์ฃผ์๋ค.
const {session} = await getServerSession(req, res, authOptions)
๊ณ์ ์๋ํ๋์ค...