     // MARK: Properties
     
     /** ID of the currently logged-in user, or nil if nobody is logged in */
-    var currentUserId: String = ""
+    private var _currentUserId: String?
+    var currentUserId: String? {
+        get {
+            if (_currentUserId == nil) {
+                let ad = UIApplication.sharedApplication().delegate as! AppDelegate
+                if let user = DatabaseUtils.getUser(ad.managedObjectContext) {
+                    _currentUserId = user.username
+                }
+            }
+            return _currentUserId
+        }
+        set {
+            _currentUserId = newValue
+        }
+    }
 
     // MARK: - Constants
     

    func logout(completion: () -> (Void)) {
        // Clear our session token and remove entries from the db
        self.sessionToken = nil
        currentUserId = ""
        let ad = UIApplication.sharedApplication().delegate as! AppDelegate!
        DatabaseUtils.clearDatabase(ad.managedObjectContext)
        completion()

                           "Development" :  "https://devel-api.tidepool.io"]
    
    // Session token, acquired on login and saved in NSUserDefaults
    private var _sessionToken: String?
    var sessionToken: String? {
        set(newToken) {
            if ( newToken != nil ) {
