inflearn logo
강의

강의

N
챌린지

챌린지

멘토링

멘토링

N
클립

클립

로드맵

로드맵

지식공유

Next + React Query로 SNS 서비스 만들기

회원가입 실제로 하기

CredentialsSignin 에러

1777

밍끼

작성한 질문수 9

1

CredentialsSignin 에러가 발생합니다.
아래의 CredentialsSignin 질문과 같이 redis 재시작,
백엔드 서버 재시작, next, node_modules 삭제 후
다시 npm install 후 확인해도 계속 같은 에러가 나옵니다.

next

[auth][error] CredentialsSignin: Read more at https://errors.authjs.dev#credentialssignin
    at Module.callback (webpack-internal:///(rsc)/./node_modules/@auth/core/lib/actions/callback/index.js:256:30)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async AuthInternal (webpack-internal:///(rsc)/./node_modules/@auth/core/lib/index.js:65:24)
    at async Auth (webpack-internal:///(rsc)/./node_modules/@auth/core/index.js:123:29)
    at async /Users/mac/Documents/next14/node_modules/next/dist/compiled/next-server/app-route.runtime.dev.js:6:63251

백엔드

[Nest] 6106  - 01/01/2024, 3:07:18 PM     LOG [WebSocketsController] EventsGateway subscribed to the "test" message +22ms
[Nest] 6106  - 01/01/2024, 3:07:18 PM     LOG [WebSocketsController] EventsGateway subscribed to the "sendMessage" message +0ms
[Nest] 6106  - 01/01/2024, 3:07:18 PM     LOG [WebSocketsController] EventsGateway subscribed to the "login" message +0ms
[Nest] 6106  - 01/01/2024, 3:07:18 PM     LOG [RoutesResolver] AppController {/}: +2ms
[Nest] 6106  - 01/01/2024, 3:07:18 PM     LOG [RouterExplorer] Mapped {/, GET} route +0ms
[Nest] 6106  - 01/01/2024, 3:07:18 PM     LOG [RoutesResolver] ApiController {/api}: +1ms
[Nest] 6106  - 01/01/2024, 3:07:18 PM     LOG [RouterExplorer] Mapped {/api/login, POST} route +0ms
[Nest] 6106  - 01/01/2024, 3:07:18 PM     LOG [RouterExplorer] Mapped {/api/logIn, POST} route +0ms
[Nest] 6106  - 01/01/2024, 3:07:18 PM     LOG [RouterExplorer] Mapped {/api/logout, POST} route +0ms
[Nest] 6106  - 01/01/2024, 3:07:18 PM     LOG [RouterExplorer] Mapped {/api/logOut, POST} route +0ms
[Nest] 6106  - 01/01/2024, 3:07:18 PM     LOG [RouterExplorer] Mapped {/api/user, GET} route +0ms
[Nest] 6106  - 01/01/2024, 3:07:18 PM     LOG [RouterExplorer] Mapped {/api/decode, POST} route +0ms
[Nest] 6106  - 01/01/2024, 3:07:18 PM     LOG [RoutesResolver] HashtagsController {/api/hashtags}: +0ms
[Nest] 6106  - 01/01/2024, 3:07:18 PM     LOG [RouterExplorer] Mapped {/api/hashtags, POST} route +0ms
[Nest] 6106  - 01/01/2024, 3:07:18 PM     LOG [RouterExplorer] Mapped {/api/hashtags, GET} route +1ms
[Nest] 6106  - 01/01/2024, 3:07:18 PM     LOG [RouterExplorer] Mapped {/api/hashtags/trends, GET} route +0ms
[Nest] 6106  - 01/01/2024, 3:07:18 PM     LOG [RouterExplorer] Mapped {/api/hashtags/:id, GET} route +0ms
[Nest] 6106  - 01/01/2024, 3:07:18 PM     LOG [RouterExplorer] Mapped {/api/hashtags/:id, PATCH} route +0ms
[Nest] 6106  - 01/01/2024, 3:07:18 PM     LOG [RouterExplorer] Mapped {/api/hashtags/:id, DELETE} route +0ms
[Nest] 6106  - 01/01/2024, 3:07:18 PM     LOG [RoutesResolver] UsersController {/api/users}: +0ms
[Nest] 6106  - 01/01/2024, 3:07:18 PM     LOG [RouterExplorer] Mapped {/api/users, POST} route +0ms
[Nest] 6106  - 01/01/2024, 3:07:18 PM     LOG [RouterExplorer] Mapped {/api/users/followRecommends, GET} route +0ms
[Nest] 6106  - 01/01/2024, 3:07:18 PM     LOG [RouterExplorer] Mapped {/api/users, GET} route +0ms
[Nest] 6106  - 01/01/2024, 3:07:18 PM     LOG [RouterExplorer] Mapped {/api/users/:id, GET} route +0ms
[Nest] 6106  - 01/01/2024, 3:07:18 PM     LOG [RouterExplorer] Mapped {/api/users/:id/posts, GET} route +0ms
[Nest] 6106  - 01/01/2024, 3:07:18 PM     LOG [RouterExplorer] Mapped {/api/users/:id, PATCH} route +0ms
[Nest] 6106  - 01/01/2024, 3:07:18 PM     LOG [RouterExplorer] Mapped {/api/users/:id, DELETE} route +1ms
[Nest] 6106  - 01/01/2024, 3:07:18 PM     LOG [RouterExplorer] Mapped {/api/users/:id/follow, POST} route +0ms
[Nest] 6106  - 01/01/2024, 3:07:18 PM     LOG [RouterExplorer] Mapped {/api/users/:id/follow, DELETE} route +0ms
[Nest] 6106  - 01/01/2024, 3:07:18 PM     LOG [RouterExplorer] Mapped {/api/users/:id/rooms, GET} route +0ms
[Nest] 6106  - 01/01/2024, 3:07:18 PM     LOG [RouterExplorer] Mapped {/api/users/:id/rooms/:roomId, GET} route +0ms
[Nest] 6106  - 01/01/2024, 3:07:18 PM     LOG [RoutesResolver] PostsController {/api/posts}: +0ms
[Nest] 6106  - 01/01/2024, 3:07:18 PM     LOG [RouterExplorer] Mapped {/api/posts, POST} route +0ms
[Nest] 6106  - 01/01/2024, 3:07:18 PM     LOG [RouterExplorer] Mapped {/api/posts/recommends, GET} route +0ms
[Nest] 6106  - 01/01/2024, 3:07:18 PM     LOG [RouterExplorer] Mapped {/api/posts/followings, GET} route +0ms
[Nest] 6106  - 01/01/2024, 3:07:18 PM     LOG [RouterExplorer] Mapped {/api/posts, GET} route +0ms
[Nest] 6106  - 01/01/2024, 3:07:18 PM     LOG [RouterExplorer] Mapped {/api/posts/:id, GET} route +0ms
[Nest] 6106  - 01/01/2024, 3:07:18 PM     LOG [RouterExplorer] Mapped {/api/posts/:id/heart, DELETE} route +0ms
[Nest] 6106  - 01/01/2024, 3:07:18 PM     LOG [RouterExplorer] Mapped {/api/posts/:id/heart, POST} route +0ms
[Nest] 6106  - 01/01/2024, 3:07:18 PM     LOG [RouterExplorer] Mapped {/api/posts/:id, DELETE} route +0ms
[Nest] 6106  - 01/01/2024, 3:07:18 PM     LOG [RouterExplorer] Mapped {/api/posts/:id/reposts, POST} route +0ms
[Nest] 6106  - 01/01/2024, 3:07:18 PM     LOG [RouterExplorer] Mapped {/api/posts/:id/reposts, DELETE} route +0ms
[Nest] 6106  - 01/01/2024, 3:07:18 PM     LOG [RouterExplorer] Mapped {/api/posts/:id/comments, GET} route +0ms
[Nest] 6106  - 01/01/2024, 3:07:18 PM     LOG [RouterExplorer] Mapped {/api/posts/:id/comments, POST} route +0ms
[Nest] 6106  - 01/01/2024, 3:07:18 PM     LOG [RouterExplorer] Mapped {/api/posts/:id/photos/:imageId, GET} route +0ms
[Nest] 6106  - 01/01/2024, 3:07:18 PM     LOG [RoutesResolver] MessagesController {/api/messages}: +0ms
[Nest] 6106  - 01/01/2024, 3:07:18 PM     LOG [RouterExplorer] Mapped {/api/messages, POST} route +0ms
[Nest] 6106  - 01/01/2024, 3:07:18 PM     LOG [RouterExplorer] Mapped {/api/messages, GET} route +0ms
[Nest] 6106  - 01/01/2024, 3:07:18 PM     LOG [RouterExplorer] Mapped {/api/messages/:id, GET} route +0ms
[Nest] 6106  - 01/01/2024, 3:07:18 PM     LOG [RouterExplorer] Mapped {/api/messages/:id, PATCH} route +0ms
[Nest] 6106  - 01/01/2024, 3:07:18 PM     LOG [RouterExplorer] Mapped {/api/messages/:id, DELETE} route +0ms
[Nest] 6106  - 01/01/2024, 3:07:18 PM     LOG [NestApplication] Nest application successfully started +2ms
redis connected
test 12345
test 123125
test sadfasf
test zcxv

 

react next.js react-query next-auth msw

답변 1

0

제로초(조현영)

authorize 함수 부분 보여주세요. return 값이 null인 상황입니다

0

밍끼

import NextAuth from "next-auth";
import CredentialsProvider from "next-auth/providers/credentials";
import { NextResponse } from "next/server";

export const {
  handlers: { GET, POST },
  auth,
  signIn,
} = NextAuth({
  pages: {
    signIn: "/i/flow/login",
    newUser: "/i/flow/signup",
  },
  providers: [
    CredentialsProvider({
      async authorize(credentials) {
        const authResponse = await fetch(`${process.env.AUTH_URL}/api/login`, {
          method: "POST",
          headers: {
            "Content-Type": "application/json",
          },
          body: JSON.stringify({
            id: credentials.username,
            password: credentials.password,
          }),
        });

        if (!authResponse.ok) {
          return null;
        }

        const user = await authResponse.json();
        return {
          email: user.id,
          name: user.nickname,
          image: user.image,
          ...user,
        };
      },
    }),
  ],
});

무조건 status가 200으로 찍히긴하네여ㅠ

0

제로초(조현영)

!authResponse.ok 위에서 console.log(authResponse)하시면 백엔드에서 어떤 status 보내는지 확인하실 수 있습니다.

status가 500 대이면 백엔드쪽 에러인데 백엔드 콘솔에 에러가 없네요;;

0

제로초(조현영)

근데 에러가 나면 프론트 화면에

아이디와 비밀번호가 일치하지 않습니다.

메시지 안 뜨나요? 프론트쪽에서 뭐가 문제인 건가요?

0

밍끼

console.log(authResponse) 작성시 console

Response {
  [Symbol(realm)]: null,
  [Symbol(state)]: {
    aborted: false,
    rangeRequested: false,
    timingAllowPassed: true,
    requestIncludesCredentials: true,
    type: 'default',
    status: 401,
    timingInfo: {
      startTime: 11867.10775,
      redirectStartTime: 0,
      redirectEndTime: 0,
      postRedirectStartTime: 11867.10775,
      finalServiceWorkerStartTime: 0,
      finalNetworkResponseStartTime: 0,
      finalNetworkRequestStartTime: 0,
      endTime: 0,
      encodedBodySize: 52,
      decodedBodySize: 52,
      finalConnectionTimingInfo: null
    },
    cacheState: '',
    statusText: 'Unauthorized',
    headersList: HeadersList {
      cookies: null,
      [Symbol(headers map)]: [Map],
      [Symbol(headers map sorted)]: null
    },
    urlList: [ URL {} ],
    body: { stream: undefined }
  },
  [Symbol(headers)]: HeadersList {
    cookies: null,
    [Symbol(headers map)]: Map(9) {
      'x-powered-by' => [Object],
      'vary' => [Object],
      'access-control-allow-credentials' => [Object],
      'content-type' => [Object],
      'content-length' => [Object],
      'etag' => [Object],
      'date' => [Object],
      'connection' => [Object],
      'keep-alive' => [Object]
    },
    [Symbol(headers map sorted)]: null
  }
}

프론트 onSubmit 함수 이고 아이디와 비밀번호가 일치하지않습니다 라고 메세지가 나오지않고있습니다.

  const onSubmit: FormEventHandler<HTMLFormElement> = async (e) => {
    e.preventDefault();
    setMessage("");
    try {
      const response = await signIn("credentials", {
        username: id,
        password,
        redirect: false,
      });

      if (!response?.ok) {
        setMessage("아이디와 비밀번호가 일치하지 않습니다.");
      } else {
        router.replace("/home");
      }
    } catch (err) {
      console.error(err);
      setMessage("아이디와 비밀번호가 일치하지 않습니다.");
    }
  };

0

제로초(조현영)

catch문이나 setMessage 가 있는 부분에 console.log 넣으면 그 콘솔은 실행되나요?

0

밍끼

catch문 에서는 console이 실행되지않고
if (!response?.ok) 에서도 console이 실행되지 않습니다.

try문과 try문3 에서만 console이 출력되고 현재 response가 이렇게 출력되는데
그래서 !response?.ok 으로 들어가질 못하는거같은데 왜 true가 날라오는지를 모르겠네여ㅠ

{error: 'CredentialsSignin', status: 200, ok: true, url: null}


  const onSubmit: FormEventHandler<HTMLFormElement> = async (e) => {
    e.preventDefault();
    setMessage("");

    try {
      const response = await signIn("credentials", {
        username: id,
        password,
        redirect: false,
      });
      console.log(
        "try문----------------------------------------------",
        response
      );
      if (!response?.ok) {
        console.log(
          "try문2----------------------------------------------",
          response
        );
        setMessage("아이디와 비밀번호가 일치하지 않습니다.");
      } else {
        console.log(
          "try문3----------------------------------------------",
          response
        );
        router.replace("/home");
      }
    } catch (err) {
      console.log("catch문----------------------------------------------");
      console.error(err);
      setMessage("아이디와 비밀번호가 일치하지 않습니다.");
    }
  };

0

제로초(조현영)

음 지금 next-auth 버전 몇 이신가요?

일단은 response.ok 대신 response.error 유무로 구별하시면 되긴 합니다.

0

밍끼

  "next-auth": "^5.0.0-beta.3",


사용하고있습니다.

0

밍끼

 

{"url":"http://localhost:9090/i/flow/login?error=CredentialsSignin"}
요청 URL:http://localhost:3000/api/auth/callback/credentials?
요청 메서드:POST
상태 코드:200 OK
원격 주소:[::1]:3000

네트워크텝에는 이런식으로 되어있습니다.

0

밍끼

우선 말씀하신대로 임시로 response.error로 변경해놓았습니다ㅠ

캡처링부분 질문있습니다.

0

76

2

깃에 소스코드를 찾을 수 없습니다.

0

113

2

useInfiniteQuery promise와 react use 사용시 페이지 무한 로딩

0

98

1

import 파일 경로를 찾지 못 해서 에러가 발생합니다.

0

111

2

css 라이브러리 추천 부탁드립니다

0

141

2

팔로우 추천 목록이 빈 배열로 들어옵니다.

0

133

1

게시물 업로드 시 userId가 undefined로 들어가는 오류

0

119

1

useSuspenseQuery 사용 시 SSR 401 이슈 관련

0

172

1

리액트 쿼리 useinfinitequery 무한스크롤 구현 시 페이지가 이동할 경우 데이터가 보존되게 할 수 있나요??

0

184

3

폴링이 필요없는 이유

0

93

2

next Request Memoization과 react cache

0

110

2

seo 최적화 기준은 데이터 fetching인가요 아님 데이터 렌더링인가요?

0

84

2

next.js 서버fetch 에러 fallback ui 구현 방법

0

173

2

프레임워크 여론 파악법

0

125

2

필터옵션이 많은 페이지에서 서버 fetch를 하는게 맞는걸까요??

0

103

2

서버 fetch suspense 로 감싸고 새로고침 시 잠시 빈 화면이 노출된 후 fallback ui가 노출됩니다.

0

102

2

template.tsx 내 서버fetch 응답값과 클라이언트 컴포넌트 상태값 싱크가 맞지 않는 이슈

0

66

2

Auth.js 사용 시 authorize 함수가 호출되지 않습니다

0

132

2

next.js 에서 로그인에 관하여

0

138

1

Next의 route handler에 대한 질문이 있습니다.

0

101

2

게시판 리스트 만들때 use client를 어디서부터 집어넣어야할지 모르겠습니다

0

98

2

프라이빗 폴더를 해야 하는 이유가 모호한 것 같아요.

0

85

2

vanilla-extract 못찾는 문제

0

230

2

fetch 캐싱과 revalidate 관련

0

85

2