Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

User class does not include fields in parity with nhost-js #139

Closed
totzk9 opened this issue Jul 13, 2024 · 5 comments
Closed

User class does not include fields in parity with nhost-js #139

totzk9 opened this issue Jul 13, 2024 · 5 comments

Comments

@totzk9
Copy link
Contributor

totzk9 commented Jul 13, 2024

nhost-js has

export interface User {
    /** User's unique identifier (uuid) */
    id: string;
    /** The date-time when the user has been created */
    createdAt: string;
    /** User's display name */
    displayName: string;
    /** The URL to the user's profile picture */
    avatarUrl: string;
    /** The locale of the user, as a two-characters string
     * @example `'en'`
     */
    locale: string;
    /** User's email address */
    email?: string;
    /** Whether or not the user is anonymous */
    isAnonymous: boolean;
    /** The default role of the user
     * @example `'user'`
     */
    defaultRole: string;
    /** The roles assigned to the user
     * @example `['user', 'me']`
     */
    roles: string[];
    /** Additional attributes used for user information */
    metadata: Record<string, unknown>;
    /** Is `true` if the user email has not been verified */
    emailVerified: boolean;
    phoneNumber: string | null;
    phoneNumberVerified: boolean;
    activeMfaType: 'totp' | null;
}

while nhost-dart only have

class User {
  User({
    required this.id,
    required this.displayName,
    required this.locale,
    required this.createdAt,
    required this.isAnonymous,
    required this.defaultRole,
    required this.roles,
    this.metadata,
    this.email,
    this.avatarUrl,
  });

  final String id;
  final String? email;
  final String displayName;

  /// A [Uri] locating the user's avatar image, or `null` if none
  final Uri? avatarUrl;
  final String locale;
  final DateTime createdAt;

  final bool isAnonymous;
  final String defaultRole;
  final List<String> roles;
  final Map<String, Object?>? metadata;

  static User fromJson(dynamic json) {
    return User(
      id: json['id'] as String,
      email: json['email'] as String?,
      displayName: json['displayName'] as String,
      locale: json['locale'] as String,
      avatarUrl: json['avatarUrl'] == null
          ? null
          : Uri.parse(json['avatarUrl'] as String),
      createdAt: DateTime.parse(json['createdAt']),
      isAnonymous: json['isAnonymous'] as bool,
      defaultRole: json['defaultRole'] as String,
      roles: <String>[...json['roles']],
      metadata: json['metadata'] == null
          ? null
          : <String, Object?>{...json['metadata']},
    );
  }

  Map<String, dynamic> toJson() {
    return <String, dynamic>{
      'id': id,
      'email': email,
      'displayName': displayName,
      'avatarUrl': avatarUrl?.toString(),
      'locale': locale,
      'createdAt': createdAt.toIso8601String(),
      'isAnonymous': isAnonymous,
      'defaultRole': defaultRole,
      'metadata': metadata,
      'roles': roles,
    };
  }

  @override
  String toString() {
    return {
      'id': id,
      'displayName': displayName,
      'locale': locale,
      'createdAt': createdAt,
      'isAnonymous': isAnonymous,
      'defaultRole': defaultRole,
      'roles': roles,
      'metadata': metadata,
      'email': email,
      'avatarUrl': avatarUrl,
    }.toString();
  }
}

Reason why I pointed this out:
My use case is to make use of the emailVerified, phoneNumber and phoneNumberVerified. activeMfaType will also be useful in future implementations

@totzk9
Copy link
Contributor Author

totzk9 commented Jul 13, 2024

@onehassan @dbarrosop
I'd like to clarify, does the NhostSession for User already contain the missing fields I mentioned? (e.g emailVerified, phoneNumber and phoneNumberVerified) If so, I could probably create a PR for this

@totzk9
Copy link
Contributor Author

totzk9 commented Jul 13, 2024

Did some debugging and signIn does indeed returns the missing fields

{
"accessToken":"eyJhbGc......KI",
"accessTokenExpiresIn":2592000,
"refreshToken":"9b5....6f8",
"refreshTokenId":"465....784",
"user":{"avatarUrl":"http....=g",
"createdAt":"2024-07-13T06:13:52.606751Z",
"defaultRole":"user",
"displayName":"tyro..mail.com",
"email":"tyro...mail.com",
"emailVerified":true,
"id":"be0...e4d",
"isAnonymous":false,
"locale":"en",
"metadata":null,
"phoneNumber":"",
"phoneNumberVerified":false,
"roles":["user","me"]}
}

Will be working on a PR

@totzk9
Copy link
Contributor Author

totzk9 commented Jul 13, 2024

Fixed by #140

@dbarrosop
Copy link
Member

Thanks for the PR, for reference, this is how it should look like:

https://github.com/nhost/hasura-auth/blob/main/go/api/openapi.yaml#L504-L569

So your PR looks good, thanks again.

@totzk9
Copy link
Contributor Author

totzk9 commented Jul 23, 2024

#140 merged

@totzk9 totzk9 closed this as completed Jul 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants