首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Next-auth凭证注册页面

Next-auth凭证注册页面
EN

Stack Overflow用户
提问于 2022-01-04 06:55:39
回答 1查看 365关注 0票数 0

因此,我正试图将Next集成到我的项目中,为我们的站点创建一个成员区和员工门户。

我注意到,我可以做一个凭据,允许我使用数据库中已经存在的用户名和密码--然而,我似乎无法在注册页面上找到凭证登录的文档,因为我们希望接受新的成员/工作人员注册。

我发现的情况如下:

代码语言:javascript
复制
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
    }
  })
]
...

不过,我看不出这将如何允许注册功能。

EN

回答 1

Stack Overflow用户

发布于 2022-01-04 12:39:21

这是简单的人后,用户注册,然后调用登录功能与电子邮件和密码,这是预先创建的。

代码语言:javascript
复制
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
})
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/70575025

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档