DEV Community

Discussion on: Using Credentials provider with a custom backend in NextAuth.js!

Collapse
sawebb profile image
Austin Webb

You are not getting a response because the user isn't being set properly. The following code is able to handle Credentials (user & pass) and Providers auth, while setting jwt and session correctly.

callbacks: {
    jwt: async (token, user) => {
      if (user) {
        token.jwt = user.jwt;
        token.user = user.user;
        token.accessToken = user?.accessToken;
      }
      return Promise.resolve(token);
    },
    session: async (session, token) => {
      session.jwt = token.jwt;
      session.accessToken = token.accessToken ? token.accessToken :
      session.user = token.user ? token.user : session.user; 
      return Promise.resolve(session);
    },
},
Enter fullscreen mode Exit fullscreen mode