Skip to main content

Auth (frappe.auth)

Session helpers on the core client. These hit classic /api/method/... even when apiVersion is 2 — v16 /api/v2/method/login does not create a session.

How the client authenticates each request (token, cookie, OAuth, …) lives on Authentication. This page is the frappe.auth module.

Every method accepts trailing RequestOptions.

Methods

MethodReturnsNotes
login(credentials)AuthResponseFull login envelope, not a nested .data object
getLoggedUser()stringCurrent user name
logout()voidAlways reset()s the auth strategy, including when the logout request fails
forgetPassword(user)voidPOST frappe.core.doctype.user.user.reset_password
ping()stringHealth check: ping on v2, frappe.ping on classic REST
const session = await frappe.auth.login({
username: 'admin',
password: 'password',
device: 'desktop',
})

const otpSession = await frappe.auth.login({
username: 'admin',
password: 'password',
otp: '123456',
tmpId: session.tmp_id!,
device: 'mobile',
})

const user: string = await frappe.auth.getLoggedUser()
await frappe.auth.ping()
await frappe.auth.forgetPassword('admin@example.com')
await frappe.auth.logout()

Credentials

login accepts UserPassCredentials or OTPCredentials:

FieldFirst factorOTP follow-up
usernamerequiredoptional
passwordrequiredoptional
otpoptionalrequired
tmpIdoptionalrequired (tmp_id from the previous response)
deviceoptionaloptional (desktop, mobile, …)

Wire names: usr, pwd, otp, tmp_id, device.

AuthResponse

Typical fields. Extra server keys exist at runtime ([key: string]: unknown).

FieldMeaning
messageStatus text (Logged In, …)
home_pageDesk/home path
full_nameDisplay name
tmp_idSecond-factor token for the OTP request
verification{ method, message?, status? } when 2FA is required
exc_typePresent on some failure envelopes

See also

  • AuthenticationtokenAuth, cookieAuth, oauthAuth, custom strategies
  • ErrorsAuthenticationError, CsrfError