authenticate

abstract suspend fun authenticate(request: IOTPsAuthenticateParameters): OTPsAuthenticateResponse

Authenticates a one-time passcode entered by the user, establishing a session. Calls the POST /sdk/v1/otps/authenticate endpoint.

Kotlin:

StytchConsumer.otps.authenticate(
OTPsAuthenticateParameters(
token = "123456",
methodId = "phone-number-test-d5a3b680-e8a3-40c0-b815-ab79986666d0",
sessionDurationMinutes = 30,
)
)

iOS:

let params = OTPsAuthenticateParameters(
token: "123456",
methodId: "phone-number-test-d5a3b680-e8a3-40c0-b815-ab79986666d0",
sessionDurationMinutes: 30
)
let response = try await StytchConsumer.otps.authenticate(params)

React Native:

StytchConsumer.otps.authenticate({
token: "123456",
methodId: "phone-number-test-d5a3b680-e8a3-40c0-b815-ab79986666d0",
sessionDurationMinutes: 30,
})

Return

OTPsAuthenticateResponse containing the authenticated session and user.

Parameters

request
  • IOTPsAuthenticateParameters

  • token — The OTP code entered by the user.

  • methodId — The method ID returned from the send or loginOrCreate call (e.g. phone-number-xxx or email-xxx).

  • sessionDurationMinutes — Duration of the session to create, in minutes.

Throws

StytchError

if the code is invalid, expired, or the method ID does not match.

if the coroutine is cancelled.