syncCurrentAuthToSharedProfileFile function

Future<void> syncCurrentAuthToSharedProfileFile({
  1. required File file,
  2. String? apiUrl,
  3. String? activeProject,
})

Implementation

Future<void> syncCurrentAuthToSharedProfileFile({required File file, String? apiUrl, String? activeProject}) async {
  final token = MeshagentAuth.current.getAccessToken();
  final user = MeshagentAuth.current.getUser();
  final userId = _stringValue(user?["id"]);
  if (token == null || token.trim().isEmpty || userId.isEmpty) {
    return;
  }

  final expiration = MeshagentAuth.current.expiration;
  await writeSharedProfileToFile(
    file: file,
    userId: userId,
    profile: SharedProfileInfo(
      id: userId,
      firstName: _nullableString(user?["first_name"]),
      lastName: _nullableString(user?["last_name"]),
      email: _nullableString(user?["email"]),
    ),
    apiUrl: apiUrl,
    session: SharedProfileSession(
      accessToken: token,
      refreshToken: MeshagentAuth.current.getRefreshToken(),
      expiresAt: expiration == null ? null : expiration.toUtc().millisecondsSinceEpoch ~/ 1000,
      tokenType: "Bearer",
    ),
    activeProject: activeProject,
  );
}