Svelte updating user attributes

I’m using the okta signin widget with svelte, I’m trying to update user details; name/address/phone number etc. I’ve tried a number of different ways but I am unable to get it to work, the closest I’ve gotten is to use the okta API and api/v1/users/me, the code below returns a response with the update in it but it doesn’t actually update the users details when I check in the console.

let userDetails = { "profile": { "login": username,
    "firstName": nameArray[0], "lastName": nameArray[1],
     "streetAddress": streetAddress, "primaryPhone": phone, "zipCode": postcode,
      "city": city }}
    let result

      result = await fetch(`${oktaUrl}/api/v1/users/me`, {
        method: 'POST',
        body: JSON.stringify(userDetails),
        headers: {
          'Authorization': 'SSWS *apicode*',
          'Content-Type': 'application/json',
          'Accept': 'application/json'

Any help with the above or even how to do it using the signing widget would be great.

Hi @tapirs

Can you please include credentials: 'include' inside the fetch request in order to pass also the cookies to Okta inside the CORS request?

Hi @dragos, that is looking a lot better I am able to update the profile, the problem is that its the profile of the user attached to the API key that gets updated rather than the current user.

When I change the URL to use a user id at the end rather than “me” I’m back to core exception.

I noticed in the docs there is an early access for requesting a token per user with specific permissions to access part of the API -, but this just gives me an error “Custom scopes are not allowed for this request.” and I don’t think I have this enabled.

Thanks, Andrew

Finally figured it out need to add the “credentials: ‘include’” and leave out the authorization header. Thanks for your help @dragos

1 Like