Identity state
The identity state determines whether an identity is active or not with the following states:
- active- The identity can use self-service flows such as sign-in.
- inactive- The identity can't use self-service flows.
When an inactive identity tries to sign in, the server responds with a UI error.
Change identity state using the SDK
Use the SDK to activate and de-activate identities:
- JavaScript
- Go
import { Configuration, IdentityApi } from "@ory/client"
import { JsonPatchOpEnum } from "@ory/client/api"
const identity = new IdentityApi(
  new Configuration({
    basePath: `https://${process.env.ORY_PROJECT_SLUG}.projects.oryapis.com`,
    accessToken: process.env.ORY_API_KEY,
  }),
)
export async function setState(
  identityId: string,
  state: "active" | "inactive",
) {
  return await identity
    .patchIdentity({
      id: identityId,
      jsonPatch: [
        {
          op: JsonPatchOpEnum.Replace,
          value: state,
          path: "/state",
        },
      ],
    })
    .then(({ data }) => data)
}
package identity
import (
	"context"
	"fmt"
	"os"
	ory "github.com/ory/client-go"
)
var oryAuthed = context.WithValue(context.Background(), ory.ContextAccessToken, os.Getenv("ORY_API_KEY"))
func setState(identityId string, state string) (err error) {
	cfg := ory.NewConfiguration()
	cfg.Servers = ory.ServerConfigurations{
		{URL: fmt.Sprintf("https://%s.projects.oryapis.com", os.Getenv("ORY_PROJECT_SLUG"))},
	}
	apiClient := ory.NewAPIClient(cfg)
	_, _, err = apiClient.IdentityApi.
		PatchIdentity(oryAuthed, identityId).
		JsonPatch([]ory.JsonPatch{{Op: "replace", Path: "/state", Value: state}}).Execute()
	return err
}