简体   繁体   中英

How to delete user from Auth0 on Next.js?

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

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 .

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

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.

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.
  });

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.

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.

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);
  }
}  

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM