Build a custom flow for handling user impersonation
Clerk's user impersonation feature allows you to sign in to your application as one of your users, enabling you to directly reproduce and remedy any issues they're experiencing. It's a helpful feature for customer support and debugging.
This guide will walk you through how to build a custom flow that handles user impersonation.
import com.clerk.api.Clerk
import com.clerk.api.auth.signInWithTicket
import com.clerk.api.network.serialization.onFailure
import com.clerk.api.network.serialization.onSuccess
import com.clerk.api.signin.SignIn
suspend fun impersonateUser(actorToken: String) {
Clerk.auth
.signInWithTicket(actorToken)
.onSuccess { signIn ->
if (signIn.status == SignIn.Status.COMPLETE && signIn.createdSessionId != null) {
Clerk.auth
.setActive(sessionId = signIn.createdSessionId)
.onFailure {
// See https://clerk.com/docs/guides/development/custom-flows/error-handling
// for more info on error handling
}
}
}
.onFailure {
// See https://clerk.com/docs/guides/development/custom-flows/error-handling
// for more info on error handling
}
}Feedback
Last updated on