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:
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:
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