// After email confirm, the user will be give the ability to go back
                  
                  
                        // to this page.
                  
                  
                        url: environment.hostName,
                  
                  
                        handleCodeInApp: false
                  
                  
                      };
                  
                  
                      this.authLoading$.next(true);
                  
                  
                      this.fireAuth.createUserWithEmailAndPassword(credentials.email, credentials.password)
                  
                  
                        .then((userCredentials) => {
                  
                  
                          this.authLoading$.next(false);
                  
                  
                          userCredentials.user?.sendEmailVerification(actionCodeSettings);
                  
                  
                          this.router.navigate(['/']);
                  
                  
                        })
                  
                  
                        .catch((err) => {
                  
                  
                          this._snackBar.open(err.message, "OK", { duration: 15000 });
                  
                  
                          this.authLoading$.next(false);
                  
                  
                        });
                  
                  
                    }
                  
                  
                  
                  
                  
                    signIn(credentials: SignInInterface) {
                  
                  
                      this.authLoading$.next(true);
                  
                  
                      this.fireAuth.signInWithEmailAndPassword(credentials.email, credentials.password)
                  
                  
                        .then((userCredentials) => {
                  
                  
                          return userCredentials.user?.getIdTokenResult();
                  
                  
                        })
                  
                  
                        .then((token) => {
                  
                  
                          if (token && token.claims && token.claims.admin) {
                  
                  
                            this.authLoading$.next(false);
                  
                  
                            this.router.navigate(['/']);
                  
                  
                          } else {
                  
                  
                            this.fireAuth.signOut();
                  
                  
                            const message = "Не достаточно прав доступа."
                  
                  
                            this._snackBar.open(message, "OK", { duration: 15000 });
                  
                  
                          }
                  
                  
                          this.authLoading$.next(false);
                  
                  
                        })
                  
                  
                        .catch((err) => {
                  
                  
                          this._snackBar.open(err.message, "OK", { duration: 15000 });
                  
                  
                          this.authLoading$.next(false);
                  
                  
                        });
                  
                  
                  
                  
                  
                    }
                  
                  
                  
                  
                  
                    restorePassword(email: string) {
                  
                  
                      this.authLoading$.next(true);
                  
                  
                      var actionCodeSettings = {
                  
                  
                        // After password reset, the user will be give the ability to go back
                  
                  
                        // to this page.
                  
                  
                        url: environment.hostName,
                  
                  
                        handleCodeInApp: false
                  
                  
                      };
                  
                  
                      let message: string = "Писмо с инструкциями отослано на ваш имейл.";
                  
                  
                      this.fireAuth.sendPasswordResetEmail(email, actionCodeSettings).then(() => {
                  
                  
                        this._snackBar.open(message, "OK", { duration: 15000 });
                  
                  
                        this.authLoading$.next(false);
                  
                  
                        this.router.navigate(['/']);
                  
                  
                  
                  
                  
                      }).catch(err => {
                  
                  
                        this._snackBar.open(err.message, "OK", { duration: 15000 });
                  
                  
                        this.authLoading$.next(false);
                  
                  
                      });
                  
                  
                    }
                  
                  
                
хммм ... Надо подумать .. Тяжело ( Но сам захотел попробовать реализовать) Да там все просто - чтобы админ мог делать некоторые действия - например удалять статьи и заходить в комнату админов
Обсуждают сегодня