netlify/gotrue-js

use admin method to update user_metadata, returning 404 **solved

Closed this issue · 0 comments

Im trying to update a users user_metadata but from the server side using an admin method. Im getting a 404 back but cant figure out why. I have it working perfectly with app_metadata and I just assumed it should work the exact same way? Heres a snippet of the actual fetch. Am i missing something? I tried using data instead of user_metadata (like one does on the client side) but no luck there.
(also i know this is doable if a user wants to update their own user_metadata but I want an admin to be able to change other users user_metadata hence using the admin method) Thanks!!

exports.handler = async (event, context) => {
const { identity, user } = context.clientContext;
const userID = event.queryStringParameters.id;
const userUrl = ${identity.url}/admin/users/${userID};
const adminAuthHeader = Bearer ${identity.token};
const name = event.queryStringParameters.name;
const company = event.queryStringParameters.company;

try {
return fetch(userUrl, {
method: "PUT",
headers: { Authorization: adminAuthHeader },
body: JSON.stringify({
user_metadata: {
name,
company
}
})
})