issue with ldap login on next-auth

Viewed 23

I'm trying to build a signin mechanism using active directory and nextauth, i'm getting a type error which i'm unable to solve. i'm attaching my [...nextauth.js] and error page below.

export default NextAuth({
  providers: [
    CredentialsProvider({
      name: "LDAP",
      credentials: {
        username: { label: "DN", type: "text", placeholder: "" },
        password: { label: "Password", type: "password" },
      },
      async authorize(credentials, req) {
        
        const client = ldap.createClient({
          url: process.env.LDAP_URI,
        })
 
        console.log(credentials)
        
        return new Promise((resolve, reject) => {
          client.bind(credentials.username, credentials.password, (error) => {
            if (error) {
              console.error("Failed")
              reject()
            } else {
              console.log("Logged in")
              resolve({
                username: credentials.username,
                password: credentials.password,
              })
            }
          })
        })
      },
    }),
  ],
  callbacks: {
    async jwt({ token, user }) {
      const isSignIn = user ? true : false
      if (isSignIn) {
        token.username = user.username
        token.password = user.password
      }
      return token
    },
    async session({ session, token }) {
      return { ...session, user: { username: token.username } }
    },
  },
  secret: process.env.NEXTAUTH_SECRET,
  jwt: {
    secret: process.env.JWT_SECRET,
  }
})

My active directory is running on a windows server 2016 vm and the network have been bridged. I'm able to connect and browser the AD using ldap clients such as apache directory studio.

0 Answers
Related