This is where that ?? operator you tried earlier would come in. It will prevent that error from occurring by providing a default value if the variable isn't set.
You can also avoid the if using && if you wanted, though one could argue over which is better from a readability standpoint.
($_SESSION["username"]??'') != 'admin' && exit;