firebase - How to generate tokens when user has logged in? -
my app requires users register , login use app. using firebase auth authenticating users. problem if user downloads app , doesn't login, receives push notifications sent other users shouldn't happen. user should notifications related app if she/he logged in. happening because tokens generated , stored after app gets downloaded.how can generate tokens if user has logged in? code tried use tokens not generating @ all:
private firebaseauth.authstatelistener mauthlistener; @override public void ontokenrefresh() { final string recent_token = firebaseinstanceid.getinstance().gettoken(); log.d(reg_token, recent_token); //databasereference = firebasedatabase.getinstance().getreference().child("blog"); mauth = firebaseauth.getinstance(); mauthlistener = new firebaseauth.authstatelistener() { @override public void onauthstatechanged(@nonnull firebaseauth firebaseauth) { if (firebaseauth.getcurrentuser() != null) { if(recent_token!=null) log.d(reg_token, recent_token); else if(recent_token==null) ontokenrefresh(); } } }; }}
i going comment since don't develop native android can't share code, sending pushs topics instead of token?
you subscribe user topic after he/she logs in or creates account , send pushs people subscribed these topics.
you can subscribe user topic using
firebasemessaging.getinstance().subscribetotopic("your_topic_name");
so when sending pushs you'll send your_topic_name
, , it's easier because don't need tokens , send 1 one (what think you're doing).
when user opens app you'll need check again , subscribe him (just safety).
here can find more subscribing users topics.
hope helps.
Comments
Post a Comment