Quantcast
Channel: Ionic Forum - Latest topics
Viewing all articles
Browse latest Browse all 70440

Ionic 4 firebase phone-authentication redirect new users to particular page

$
0
0

@Pratikjaiswa15 wrote:

I am using firebase phone-authentication in my ionic 4 app. I have successfully implemented jwt authentication. If the token is available I redirect users to the main page else redirecting to the login page.

But here comes the problem on the login page. If the user is new(coming for the first time) then I want to redirect to the details page to get some other data like email, name, else (old user) redirect to the main page.

The problem is I don’t have different buttons for login and signup in my app. The same login is used for both login and register

What is the best solution to check if the user is new or old?

Here is my code

authentication.service.ts

authenticationState = new BehaviorSubject(false);

    constructor(private storage: StorageService, private plt: Platform, private router: Router) {

        this.plt.ready().then(() => {
          this.checkToken();
        });
       }

       checkToken() {
        this.storage.get(TOKEN_KEY).then(res => {
          if (res) {
            this.authenticationState.next(true);
          }
        })
      }

      login() {
        return this.storage.set(TOKEN_KEY, 'Bearer 1234567').then(() => {
          this.authenticationState.next(true);
        });
      }

      logout() {
        return this.storage.clear().then(() => {
          this.authenticationState.next(false);
          this.router.navigate(['home'])

        });
      }

      isAuthenticated() {
        return this.authenticationState.value;
      }

app.component.ts

constructor(private authenticationService: AuthenticationService){
    this.authenticationService.authenticationState.subscribe(state => {
            if (state) {
              this.router.navigate(['menu/items']);
            } else {
              this.router.navigate(['home']);
            }
          });
}

home.page.ts

if(old user) {
// redirect to main page
}

else {
redirect to details page
}

Posts: 1

Participants: 1

Read full topic


Viewing all articles
Browse latest Browse all 70440

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>