In hook_form_alter how can I attach libraries on frontend only?
To answer your question, you can get the active theme name using below code in module file.

$activeTheme = \Drupal::service('theme.manager')-&gt;getActiveTheme()-&gt;getName()

and check if $activeTheme !== 'Your admin theme'.

Recommended way:

In your case as you want to add library specific to theme, it should be added in theme file and not module file.