0

So I am trying to integrate Next-Auth into my project to create a members area plus staff portal for our site.

I have noticed that I can do a credential that would allow me to use the username and passwords already in the database - however I can't seem to find the documentation on a signup page for credentials logins as we want to accept new members/staff to register.

What I have found is the following:

import CredentialsProvider from `next-auth/providers/credentials`
...
providers: [
  CredentialsProvider({
    // The name to display on the sign in form (e.g. 'Sign in with...')
    name: 'Credentials',
    // The credentials is used to generate a suitable form on the sign in page.
    // You can specify whatever fields you are expecting to be submitted.
    // e.g. domain, username, password, 2FA token, etc.
    // You can pass any HTML attribute to the <input> tag through the object.
    credentials: {
      username: { label: "Username", type: "text", placeholder: "jsmith" },
      password: {  label: "Password", type: "password" }
    },
    async authorize(credentials, req) {
      // You need to provide your own logic here that takes the credentials
      // submitted and returns either a object representing a user or value
      // that is false/null if the credentials are invalid.
      // e.g. return { id: 1, name: 'J Smith', email: 'jsmith@example.com' }
      // You can also use the `req` object to obtain additional parameters
      // (i.e., the request IP address)
      const res = await fetch("/your/endpoint", {
        method: 'POST',
        body: JSON.stringify(credentials),
        headers: { "Content-Type": "application/json" }
      })
      const user = await res.json()

      // If no error and we have user data, return it
      if (res.ok && user) {
        return user
      }
      // Return null if user data could not be retrieved
      return null
    }
  })
]
...

However I don't see how this will allow signup feature.

Russell Harrower
  • 778
  • 1
  • 6
  • 20

1 Answers1

0

It is easy man after the user signup then call login function with email and password which created in advance.

const email = "abs@gmail.com";
const pass = "123456"
axios.post('http:yoursignupURL',{email , pass});
// after user registered in database
login('credential',{
email : email,
password : password
})
Paiman Rasoli
  • 1,088
  • 1
  • 5
  • 15