Skip to main content

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:

// Copyright © 2022 Ory Corp
// SPDX-License-Identifier: Apache-2.0

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)
}