Back to Medusa

updateProvider - Auth Module Reference

www/apps/resources/references/auth/IAuthModuleService/methods/auth.IAuthModuleService.updateProvider/page.mdx

2.14.23.7 KB
Original Source

import { TypeList } from "docs-ui"

updateProvider - Auth Module Reference

This documentation provides a reference to the updateProvider method. This belongs to the Auth Module.

<Note>

You should only use this methods when implementing complex customizations. For common cases, check out available workflows instead.

</Note>

This method updates an auth identity's details using the provider that created it. It uses the update method of the underlying provider, passing it the providerData parameter as a parameter. The method returns the data returned by the provider.

Example

The following example is in the context of an API route, where req is an instance of the MedusaRequest object:

ts
const { success, authIdentity, location, error } =
  await authModuleService.updateProvider("emailpass", {
    email: "[email protected]",
    password: "password",
    // The ID of a user, customer, or custom actor type that is being updated.
    // For example, `user_123`.
    entity_id: req.auth_context.actor_id,
  })

Parameters

<TypeList types={[{"name":"provider","type":"string","description":"The ID of the provider to update the auth identity with.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"providerData","type":"Record<string, unknown>","description":"The data to pass to the provider to update the auth identity.","optional":false,"defaultValue":"","expandable":false,"children":[]}]} expandUrl="https://docs.medusajs.com/learn/fundamentals/data-models/manage-relationships#retrieve-records-of-relation" sectionTitle="updateProvider"/>

Returns

<TypeList types={[{"name":"Promise","type":"Promise<AuthenticationResponse>","optional":false,"defaultValue":"","description":"The details of the update result.","expandable":false,"children":[{"name":"success","type":"boolean","description":"Whether the authentication was successful.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"authIdentity","type":"AuthIdentityDTO","description":"The authenticated user's details.","optional":true,"defaultValue":"","expandable":false,"children":[{"name":"id","type":"string","description":"The ID of the auth identity.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"provider_identities","type":"ProviderIdentityDTO[]","description":"The list of provider identities linked to the auth identity.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"app_metadata","type":"Record<string, unknown>","description":"Holds information related to the actor IDs tied to the auth identity.","optional":true,"defaultValue":"","expandable":false,"children":[]}]},{"name":"error","type":"string","description":"If an error occurs during the authentication process,\nwhether within the Auth Module or a third-party provider,\nthe error message is set in this field.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"location","type":"string","description":"The URL to redirect to for further authentication action\nwith a third-party provider. This takes precedence before\nthe success field.\n\nSo, after checking that authentication is successful,\nyou should check whether this field is defined and, if so, redirect to the\nspecified location.","optional":true,"defaultValue":"","expandable":false,"children":[]}]}]} expandUrl="https://docs.medusajs.com/learn/fundamentals/data-models/manage-relationships#retrieve-records-of-relation" sectionTitle="updateProvider"/>