如何从Next.js的Auth0删除用户? [英] How to delete user from Auth0 on Next.js?

查看:104
本文介绍了如何从Next.js的Auth0删除用户?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在阅读了以下资源之后,我可以在Next.js上登录和注销用户:

I can login and logout users on Next.js after reading these resources amongst others:

@ auth0/nextjs-auth0

API调用示例

SPA + API:Node.js实现用于API

但是我无法找到是否可以使用auth0/nextjs-auth0库删除用户.

But nowhere could I find out if I can delete users using the auth0/nextjs-auth0 library.

我还在此处中查看了该模块的处理程序.

I also looked into the module's handlers here.

我是否认为无法使用@ auth0/nextjs-auth0库删除用户?

Am I right to think there is no way to delete a user using the @auth0/nextjs-auth0 library?

如果是,删除用户的首选方式是什么?我想允许用户单击浏览器中的按钮以从Auth0中删除自己.

If yes, what is the most preferred way to delete a user? I'd like to allow users to click a button in the browser to delete themselves from Auth0.

目前,我正在考虑使用 node-auth0 库来完成此操作遵循此解决方案:

At this point, I'm thinking of using node-auth0 library to do it following this solution:

 management.users.delete({ id: USER_ID }, function (err) {
    if (err) {
      // Handle error.
    }
 
    // User deleted.
  });

但是它需要一个节点后端,我想避免这种情况.即使这样,这是最好的解决方案还是有更好的解决方案?Auth0生态系统非常庞大.

But it requires a node back end, which I sort of wanted to avoid. Even so, is this the best solution or are there better ones? The Auth0 ecosystem is quite sprawling.

编辑2020年10月27日:将尝试在无服务器"服务器中使用node-auth0库.Next.js中的函数,以允许用户在周末删除其帐户.Next的运行时配置隐藏了秘密.如果这不是最好的方法,请告诉我.谢谢.

Edit 27 Oct 2020: Will try using node-auth0 library in "serverless" function in Next.js to allow user to delete their account over the weekend. Secrets are hidden with Next's runtime configuration. If this is not the best way to do it, please let me know. Thanks.

推荐答案

我相信您的意思是通过删除用户"注销用户.因为如果要从数据库中删除用户,则必须具有处理数据库连接的节点服务器.如果您要注销用户,请在"pages/api/v1"页面中创建一个logout.js.在next.js中,无服务器功能或api函数被写在"pages/api"中.

I believe you mean logging out a user by "deleting a user". Because If you want to delete a user from the database, you have to have node server which handles the db connection. If you want to log out the user, in "pages/api/v1" create a logout.js. in next.js, serverless functions or api functions are written in "pages/api".

import auth0 from "/utils/auth0"; 
// auth0 file is where you set the configuration for the auth0.

export default async function logout(req,res) {
  try {
    await auth0.handleLogout(req, res);
  } catch (error) {
    console.error(error);
    res.status(error.status || 400).end(error.message);
  }
}  

这篇关于如何从Next.js的Auth0删除用户?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆