[๋ฏธํ•ด๊ฒฐ๐Ÿฅฒ] [next-auth] CLIENT_FETCH_ERROR...

์ด์˜จยท2024๋…„ 2์›” 14์ผ
0

๊ธฐํƒ€

๋ชฉ๋ก ๋ณด๊ธฐ
9/10

[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์„ ์ฐพ์„ ์ˆ˜ ์—†์—ˆ๋‹ค.


๋„ฅ์ŠคํŠธ ๊ณต์‹ ๋ฌธ์„œ์—์„œ๋Š” ์—๋Ÿฌ์˜ ์ด์œ ๊ฐ€ ์—ฌ๋Ÿฌ๊ฐ€์ง€ ์žˆ๋‹ค๊ณ  ํ๋ฆฌ๋ฉํ……ํ•˜๊ฒŒ ๋งํ•ด์„œ ใ… ใ…  ์ง์ ‘ ๊ตฌ๊ธ€๋ง์— ๋“ค์–ด๊ฐ”๋‹ค..

(1) secret ์„ค์ •

๊ทธ๋Ÿฌ๋‹ค๊ฐ€ โ€˜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)

(2) getServerSession

api route ๋ถ€๋ถ„์ด๋ผ ์„œ๋ฒ„์‚ฌ์ด๋“œ๋ผ์„œ getSession์ด ์•„๋‹Œ getServerSession๋กœ ๋ณ€๊ฒฝํ•ด์ฃผ์—ˆ๋‹ค.

  const {session} = await getServerSession(req, res, authOptions)

๊ทผ๋ฐ๋„ ํ•ด๊ฒฐ์ด ์•ˆ๋๋‹ค..

๊ณ„์† ์‹œ๋„ํ•˜๋Š”์ค‘...

profile
๐Ÿ‘ฉ๐Ÿปโ€๐Ÿ’ป

0๊ฐœ์˜ ๋Œ“๊ธ€