Issue with adding a database to an Availability Group
Unable to access availability database 'test123' because the database
  replica is not in the PRIMARY or SECONDARY role. Connections to an
  availability database is permitted only when the database replica is
  in the PRIMARY or SECONDARY role.


You reported that the database was not showing under the databases folder when viewing your secondary instance with SSMS.  

If you refreshed and it was still not there, then this means that the database does not exist. 
The reason would/could be that something went wrong with automatic seeding. 

You should try executing these commands on the secondary instance:

ALTER AVAILABILITY GROUP [agname] JOIN; 
GO 
ALTER AVAILABILITY GROUP [agname] GRANT CREATE ANY DATABASE; 
GO 


After this you should retry automatic seeding &amp; validate that the database was created and fully seeded on the secondary instance.

To validate the automatic seeding process , you could use the  sys.dm_hadr_automatic_seeding DMV.

SELECT start_time,
    ag.name,
    db.database_name,
    current_state,
    performed_seeding,
    failure_state,
    failure_state_desc
FROM sys.dm_hadr_automatic_seeding autos 
    JOIN sys.availability_databases_cluster db 
        ON autos.ag_db_id = db.group_database_id
    JOIN sys.availability_groups ag 
        ON autos.ag_id = ag.group_id;


Source