DescopeUser class

The DescopeUser class represents an existing user in Descope.

After a user is signed in with any authentication method the DescopeSession object keeps a DescopeUser value in its DescopeSession.user property so the user's details are always available.

In the example below we finalize an OTP authentication for the user by verifying the code. The authentication response has a DescopeUser property which can be used directly or later on when it's kept in the DescopeSession.

final authResponse = await Descope.otp.verify(method: DeliveryMethod.email, loginId: 'andy@example.com', code: '123456');
print('Finished OTP login for user: ${authResponse.user}');

Descope.sessionManager.session = DescopeSession(authResponse);
print('Created session for user ${descopeSession.user.userId}');

The details for a signed in user can be updated manually by calling the auth.me API with the refreshJwt from the active DescopeSession. If the operation is successful the call returns a new DescopeUser value.

final session = Descope.sessionManager.session;
if (session != null) {
  final descopeUser = await Descope.auth.me(refreshJwt: session.refreshJwt);
  session.updateUser(descopeUser);
}

In the code above we check that there's an active DescopeSession in the shared session manager. If so we ask the Descope server for the latest user details and then update the DescopeSession with them.

Annotations
  • @JsonSerializable()

Constructors

DescopeUser(String userId, List<String> loginIds, int createdAt, String? name, Uri? picture, String? email, bool isVerifiedEmail, String? phone, bool isVerifiedPhone, Map<String, dynamic> customAttributes, String? givenName, String? middleName, String? familyName)

Properties

createdAt int
The time at which the user was created in Descope.
final
customAttributes Map<String, dynamic>
A mapping of any custom attributes associated with this user. User custom attributes are managed via the Descope console.
final
email String?
The user's email address.
final
familyName String?
Optional user's family name.
final
givenName String?
Optional user's given name.
final
hashCode int
The hash code for this object.
no setteroverride
isVerifiedEmail bool
Whether the email address has been verified to be a valid authentication method for this user. If email is nil then this is always false.
final
isVerifiedPhone bool
Whether the phone number has been verified to be a valid authentication method for this user. If phone is null then this is always false.
final
loginIds List<String>
The identifiers the user can sign in with. This is a list of one or more email addresses, phone numbers, usernames, or any custom identifiers the user can authenticate with.
final
middleName String?
Optional user's middle name.
final
name String?
The user's full name.
final
phone String?
The user's phone number.
final
picture Uri?
The user's profile picture.
final
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
userId String
The unique identifier for the user in Descope. This value never changes after the user is created, and it always matches the Subject (sub) claim value in the user's JWT after signing in.
final

Methods

noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toString() String
A string representation of this object.
inherited

Operators

operator ==(Object other) bool
The equality operator.
override

Static Properties

fromJson DescopeUser Function(Map<String, dynamic> json)
getter/setter pair
toJson Map<String, dynamic> Function(DescopeUser instance)
getter/setter pair