- let person_id = local_user_view.person.id;
- check_private_instance(&Some(local_user_view), &local_site)?;
+ check_private_instance(&local_user_view, &local_site)?;
+ let person_id = local_user_view.map(|v| v.person.id);
+ // If we get a valid personId back we can safely assume that the user is authenticated,
+ // if there's no personId then the JWT was missing or invalid.
+ let is_authenticated = person_id.is_some();
+
+ let res = if is_authenticated {
+ // user is fully authenticated; allow remote lookups as well.
+ search_query_to_object_id(&data.q, &context).await
+ } else {
+ // user isn't authenticated only allow a local search.
+ search_query_to_object_id_local(&data.q, &context).await
+ }
+ .with_lemmy_type(LemmyErrorType::CouldntFindObject)?;