immich-app/immich · error · Exception

User not logged in

Error message

User not logged in

What it means

Thrown by the createAlbum provider in RemoteAlbumProvider before calling RemoteAlbumService.createAlbum. The service requires a User object as the album owner, so when ref.read(currentUserProvider) returns null (unauthenticated), the operation aborts with this exception. It means an album creation was attempted without a valid session.

Solutions

  1. Check currentUserProvider (or await auth state) before enabling/invoking album creation; disable the action when logged out.
  2. Catch the exception, prompt the user to log in, then retry the creation.
  3. Refresh the session token proactively so currentUserProvider doesn't yield null mid-session.
  4. Route the create-album flow through authenticated screens only.

Example fix

// before
final currentUser = ref.read(currentUserProvider);
if (currentUser == null) {
  throw Exception('User not logged in');
}
// after
final currentUser = ref.read(currentUserProvider);
if (currentUser == null) {
  await ref.read(authProvider.notifier).reauthenticate();
  throw const UnauthenticatedException(); // handled upstream with a login prompt
}
Defensive patterns

Strategy: validation

Validate before calling

final user = ref.read(currentUserProvider);
if (user == null) {
  // disable create action / prompt login first
  return;
}

Type guard

bool hasUser(User? u) => u != null && u.id.isNotEmpty;

Try / catch

try {
  await ref.read(remoteAlbumProvider.notifier).createAlbum(title: title);
} catch (e) {
  if (e.toString().contains('User not logged in')) {
    await promptLogin();
  } else {
    rethrow;
  }
}

Prevention

When it happens

Trigger: Calling createAlbum (title/description/assetIds) while currentUserProvider reads null — after logout/token expiry, or before login completes when the create action is triggered.

Common situations: User taps 'create album' after their session expired in the background; UI not disabled during logout transition; stale app state restored post-logout.

Related errors


AI-assisted analysis of immich-app/immich@e55ac299a4 (2026-09-15). Data as JSON: /api/errors/563a905347284163. Report an issue: GitHub.

Appendix: source

Thrown at mobile/lib/providers/infrastructure/remote_album.provider.dart:83

  }

  Future<List<RemoteAlbum>> sortAlbums(
    List<RemoteAlbum> albums,
    AlbumSortMode sortMode, {
    bool isReverse = false,
  }) async {
    return await _remoteAlbumService.sortAlbums(albums, sortMode, isReverse: isReverse);
  }

  Future<RemoteAlbum?> createAlbum({
    required String title,
    String? description,
    List<String> assetIds = const [],
  }) async {
    try {
      final currentUser = ref.read(currentUserProvider);
      if (currentUser == null) {
        throw Exception('User not logged in');
      }

      final album = await _remoteAlbumService.createAlbum(
        title: title,
        owner: currentUser,
        description: description,
        assetIds: assetIds,
      );

      state = state.copyWith(albums: [...state.albums, album]);

      return album;
    } catch (error, stack) {
      _logger.severe('Failed to create album', error, stack);
      rethrow;
    }
  }

View on GitHub (pinned to e55ac299a4)