# updateUserMetaData - How can I update meta data from useUser without login/logout?

**URL:** <https://community.auth0.com/t/updateusermetadata-how-can-i-update-meta-data-from-useuser-without-login-logout/109231>\
**Category:** Get Help\
**Tags:** user-profile, user-management\
**Created:** [June 14, 2023, 1:52pm UTC](https://community.auth0.com/t/updateusermetadata-how-can-i-update-meta-data-from-useuser-without-login-logout/109231 "2023-06-14T13:52:59Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![bhbenhayward](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/bhbenhayward/32/48055_2.png) [@bhbenhayward](https://community.auth0.com/u/bhbenhayward)\
**Post date:** [June 14, 2023, 1:52pm UTC](https://community.auth0.com/t/updateusermetadata-how-can-i-update-meta-data-from-useuser-without-login-logout/109231/1 "2023-06-14T13:52:59Z")

</div>

Hi there,

I’m trying to update the users meta data in my next.js application, utilising the management API. The meta data is being updated successfully, but the user has to logout and login again in order for the changes to be reflected.

How can I update the metadata without needing the user to log back in?

API Code:

```auto
const userHandler = async (req, res) => {
  const { body } = req;

  const session = await getSession(req, res);
  const id = session.user.sub;
  const accessToken = session.accessToken;

  console.log('id', session);

  try {
    const params = body;

    const currentUserManagementClient = new ManagementClient({
      token: accessToken,
      domain: process.env.AUTH0_ISSUER_BASE_URL.replace('https://', ''),
      scope: process.env.AUTH0_SCOPE,
    });

    await currentUserManagementClient.updateUserMetadata({ id }, params);

    res.status(200).json(user);
  } catch (err) {
    console.log(err);
    res.status(500).json({ statusCode: 500, message: err.message });
  }
};

```

session console log:

```auto
id Session {
  user: {
    'REMOVED': {
      activeSubscription: true,
      stripeCustomerId: 'REMOVED',
      tokens: 0
    },
    given_name: 'Ben',
    family_name: 'Hayward',
    nickname: 'ben',
    name: 'Ben Hayward',
    picture: 'REMOVED',
    locale: 'en',
    updated_at: '2023-06-13T22:13:01.146Z',
    email: 'ben@REMOVED.com',
    email_verified: true,
    sub: 'google-oauth2|111663802953217651283',
    sid: 'qj0a432ZrWBGbFjVHmUd5oASQTibCDLA'
  },

```

Many thanks,

Ben

---

<div class="post-metadata">

**Author:** ![ty.frith](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/ty.frith/32/58484_2.png) [@ty.frith](https://community.auth0.com/u/ty.frith)\
**Post date:** [June 14, 2023, 6:42pm UTC](https://community.auth0.com/t/updateusermetadata-how-can-i-update-meta-data-from-useuser-without-login-logout/109231/3 "2023-06-14T18:42:41Z")

</div>

Hey there @bhbenhayward welcome to the community!

Have you looked into [silent authentication](https://auth0.com/docs/authenticate/login/configure-silent-authentication) at all? The following topic goes into a similar use case as yours:

> [@Silent Auth errors with Login Required after updating app\_metadata via Management API](https://community.auth0.com/t/silent-auth-errors-with-login-required-after-updating-app-metadata-via-management-api/65834):
>
> Hello, I am trying to understand why calling getAccessTokenSilently redirects me back to the login page after I update my user’s app\_metadata via the Management API. Here’s my setup: I have two applications: 1) an SPA, and 2) a M2M The SPA shows the Auth0 login screen and upon successful signup/login redirects back to my application After redirecting, the user is requested to enter an invite code (from their email) to link the Auth0 user to my backend domain model The SPA invokes my backend …

Keep us posted!

---

<div class="post-metadata">

**Author:** ![bhbenhayward](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/bhbenhayward/32/48055_2.png) [@bhbenhayward](https://community.auth0.com/u/bhbenhayward)\
**Post date:** [June 14, 2023, 7:54pm UTC](https://community.auth0.com/t/updateusermetadata-how-can-i-update-meta-data-from-useuser-without-login-logout/109231/4 "2023-06-14T19:54:36Z")

</div>

Hey @ty.frith ,

I tried to implement silent authentication via the ‘prompt none’ param, but I received a ‘login required’ error.

```auto
import { handleAuth, handleLogin } from '@auth0/nextjs-auth0';

export default handleAuth({
  async login(req, res) {
    try {
      await handleLogin(req, res, {
        authorizationParams: {
          audience: `${process.env.AUTH0_ISSUER_BASE_URL}/api/v2/`,
          prompt: 'none',
          scope:
            'openid profile email user_metadata read:current_user create:current_user_metadata update:current_user_metadata',
        },
      });
    } catch (error) {
      res.status(error.status || 400).end(error.message);
    }
  },
});

```

---

<div class="post-metadata">

**Author:** ![ty.frith](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/ty.frith/32/58484_2.png) [@ty.frith](https://community.auth0.com/u/ty.frith)\
**Post date:** [June 30, 2023, 12:23am UTC](https://community.auth0.com/t/updateusermetadata-how-can-i-update-meta-data-from-useuser-without-login-logout/109231/5 "2023-06-30T00:23:18Z")

</div>

Sorry for the delayed response here - Do you have MFA enabled?

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/auth0/original/3X/b/5/b560f266932fcce5d57f09a6595bd50518cae3f3.jpeg) [@system](https://community.auth0.com/u/system)\
**Post date:** [July 21, 2023, 9:37pm UTC](https://community.auth0.com/t/updateusermetadata-how-can-i-update-meta-data-from-useuser-without-login-logout/109231/6 "2023-07-21T21:37:24Z")

</div>

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.
