loginOrCreate

abstract suspend fun loginOrCreate(request: IMagicLinksEmailLoginOrCreateParameters): MagicLinksEmailLoginOrCreateResponse

Sends a magic link email to the provided address, logging in an existing user or creating a new one. Calls the POST /sdk/v1/magic_links/email/login_or_create endpoint. Generates and stores a PKCE code pair for use in the subsequent MagicLinksClient.authenticate call.

Kotlin:

StytchConsumer.magicLinks.email.loginOrCreate(
MagicLinksEmailLoginOrCreateParameters(
email = "user@example.com",
)
)

iOS:

let params = MagicLinksEmailLoginOrCreateParameters(email: "user@example.com")
let response = try await StytchConsumer.magicLinks.email.loginOrCreate(params)

React Native:

StytchConsumer.magicLinks.email.loginOrCreate({ email: "user@example.com" })

Return

MagicLinksEmailLoginOrCreateResponse confirming the email was sent.

Parameters

request
  • IMagicLinksEmailLoginOrCreateParameters

  • email — The email address to send the magic link to.

  • loginMagicLinkUrl? — The URL to redirect existing users to after clicking the link.

  • signupMagicLinkUrl? — The URL to redirect new users to after clicking the link.

  • loginExpirationMinutes? — Expiration for the login magic link, in minutes.

  • signupExpirationMinutes? — Expiration for the signup magic link, in minutes.

  • loginTemplateId? — Custom email template ID to use for login emails.

  • signupTemplateId? — Custom email template ID to use for signup emails.

  • locale? — Locale for the email content (e.g. "en").

Throws

StytchError

if the request fails.

if the coroutine is cancelled.