uniform-turquoiseU
Refine2y ago
5 replies
uniform-turquoise

Login/logout redirect with next-auth credentials

I'm trying to implement next-auth with credentials provider.
I have another server dedicated for authenticate, and Refine will make request to that server to authenticate user:
const authOptions = {
  providers: [
    CredentialsProvider({
      credentials: {
        username: { label: "Username", type: "text", placeholder: "Username" },
        password: { label: "Password", type: "password" }
      },
      async authorize(credentials, req) {
        const res = await fetch("http://localhost:8001/user/login", {
          method: 'POST',
          body: JSON.stringify(credentials),
          headers: { "Content-Type": "application/json" }
        })
        const user = await res.json()
        if (res.ok && user) {
          return user
        }
        return null
      }
    }),
  ],
  secret: 'secret'
};

The authentication part works fine, but whenever I login/logout, Refine keep redirect me back to http://localhost:8001/login or http://localhost:8001/
Was this page helpful?