【问题标题】:How to get username in Next-Auth for Github Provider?如何在 Next-Auth for Github Provider 中获取用户名?
【发布时间】:2022-03-03 13:49:22
【问题描述】:

我正在使用https://next-auth.js.org/ 作为我的登录系统,但我无法从中获取用户名。它只是返回名称、电子邮件、图像和访问令牌。但是我想要的是来自 GitHub 帐户的用户名,那么我该如何实现呢?

【问题讨论】:

    标签: javascript node.js next.js


    【解决方案1】:

    我不得不做一些解决方法

    使用此端点通过 id 获取您的用户信息: https://api.github.com/user/[userId]

    您可以从 data.user.image 中获取您的 userId,next-auth 提供: https://avatars.githubusercontent.com/u/[userId]?v=4

    【讨论】:

      【解决方案2】:

      是的,如果您使用 Prisma 和 postgress Get 在帐户表下,您将能够找到 providedAccountiD 然后您可以从 https://api.github.com/user/[userId] 发送请求,来自 postgress 帐户表的用户 ID - > 提供的帐户 ID 谢谢!

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2021-11-26
        • 2021-05-23
        • 2013-11-25
        • 2022-12-17
        • 2021-11-12
        • 2021-04-01
        • 2014-06-08
        • 1970-01-01
        相关资源
        最近更新 更多