angulartypescriptangular8angular15

Error: NG0204: Can't resolve all parameters for AuthService: (?). angular 15


I was upgrading an angular app from angular v8 to v15 it was upgraded successfully and smoothly, and it also compiled successfully but when i try to open it it gives me this error

Error: NG0204: Can't resolve all parameters for AuthService: (?)

here is the AuthService.ts

import { Injectable } from '@angular/core';
import { HttpHeaders, HttpClient, HttpErrorResponse } from '@angular/common/http';
import { Router } from '@angular/router';
import { Observable, throwError } from 'rxjs';
import { catchError, map } from 'rxjs/operators';
import { User } from './User';
import { FormGroup } from '@angular/forms';
import { ToastrService } from 'ngx-toastr';
import { LogindataService } from './logindata.service';
import { URLAPIService } from './urlapi.service';

@Injectable({
  providedIn: 'root'
})
export class AuthService {
  //endpoint: string = 'http://localhost:44393/api';
  endpoint: string = this.URLservice.ApiUrl;
  headers = new HttpHeaders().set('Content-Type', 'application/json');
  currentUser = {};
  registerForm: FormGroup;


  constructor(private URLservice: URLAPIService, private logindataser: LogindataService, private http: HttpClient, public router: Router, private toastr: ToastrService) { }


  // Sign-up
  signUp(user: User): Observable<any> {
    let api = `${this.endpoint}/Auth/Registration`;
    return this.http.post(api, user)
      .pipe(
        catchError(this.handleError)
      )
  }
  ////////////////////////////////////////
  // Sign-in
  signIn(user: User, IsRemember: any) {
    return this.http.post<any>(`${this.endpoint}/Auth/login`, user)
      .subscribe(
        (res: any) => {
          if (res.success == true) {
            //debugger;
            if (IsRemember == true) {
              localStorage.setItem('access_token', res.auth_token);
              localStorage.setItem('_id', res._id);
              localStorage.setItem('role', res.roles[0]);
            }
            else {
              sessionStorage.setItem('access_token', res.auth_token);
              sessionStorage.setItem('_id', res._id);
              sessionStorage.setItem('role', res.roles[0]);
            }

            if (res.roles[0] == 'Student') {
              this.router.navigate(['/Dashboard']);
            }
            else if (res.roles[0] == 'Teacher') {
              this.router.navigate(['/TeacherDashboard']);
            }
            else {
              this.router.navigate(['/Home']);
            }
          }
          else {
            this.toastr.warning(res.message, "Login");
          }
        },
        (err: any) => {
          this.toastr.error(err.message, "Login");
        })
  }

  //////////////////////////////////////////////////////
  getToken() {
    if (localStorage.getItem('access_token') != null) {
      return localStorage.getItem('access_token');
    }
    else {
      return sessionStorage.getItem('access_token');
    }
  }

  getid() {
    if (localStorage.getItem('_id') != null) {
      return localStorage.getItem('_id');
    }
    else {
      return sessionStorage.getItem('_id');
    }
  }

  getrole() {
    if (localStorage.getItem('role') != null) {
      return localStorage.getItem('role');
    }
    else {
      return sessionStorage.getItem('role');
    }
  }
  ////////////////////////////////////////////////
  get isLoggedIn(): boolean {
    let authToken = "";
    if (localStorage.getItem('access_token') != null) {
      authToken = localStorage.getItem('access_token');
    }
    else {
      authToken = sessionStorage.getItem('access_token');
    }
    return (authToken !== null) ? true : false;
  }
  //////////////////////////////////////////////
  doLogout() {
    let removeToken = localStorage.removeItem('access_token');
    let remove_id = localStorage.removeItem('_id');
    let role_id = localStorage.removeItem('role');

    let removeTokensession = sessionStorage.removeItem('access_token');
    let remove_idsession = sessionStorage.removeItem('_id');
    let role_idsession = sessionStorage.removeItem('role');

    this.logindataser.logOut();
    if ((removeToken == null && remove_id == null && role_id == null) || (removeTokensession == null && remove_idsession == null && role_idsession == null)) {
      this.router.navigate(['login']);
    }
  }
  ///////////////////////////////////////////////
  // User profile
  getUserProfile(id): Observable<any> {
    let api = `${this.endpoint}/Auth/GetUserProfile?uid=${id}`;
    return this.http.get(api, { headers: this.headers }).pipe(
      map((res: Response) => {
        return res || {}
      }),
      catchError(this.handleError)
    )
  }

  ///////////////////////////
  getorgization(): Observable<any> {
    return this.http.get(this.endpoint + '/Origination/GetOrganizationData');
  }

  GetNotifications(): Observable<any> {
    //debugger;
    return this.http.get(this.endpoint + '/Home/GetNotifications', {
      params: { Userid: this.getid() }
    });
  }

  GetMessages(): Observable<any> {
    //debugger;
    return this.http.get(this.endpoint + '/Home/GetMessages', {
      params: { Userid: this.getid() }
    });
  }

  AcceptRefuseJoinInCourse(body) {
    return this.http.post(this.endpoint + '/Home/AcceptRefuseenrole', body);
  }

  ///////////////////////////////////////////////////
  // Error 
  handleError(error: HttpErrorResponse) {
    let msg = '';
    if (error.error instanceof ErrorEvent) {
      // client-side error
      msg = error.error.message;
    } else {
      // server-side error
      msg = `Error Code: ${error.status}\nMessage: ${error.message}`;
    }
    return throwError(msg);
  }

  forgetPassword(body: any) {
    return this.http.post<any>(`${this.endpoint}/Auth/Forgetpassword`, body)
      .subscribe(
        (res: any) => {
          if (res.success == true) {
            this.toastr.success(res.message, "Forget Password");
            this.router.navigate(['/Login']);
          }
          else {
            this.toastr.warning(res.message, "Forget Password");
          }
        },
        (err: any) => {
          this.toastr.error(err.message, "Forget Password");
        })
  }

  resetPassword(body: any) {
    return this.http.post<any>(`${this.endpoint}/Auth/resetpassword`, body)
      .subscribe(
        (res: any) => {
          if (res.success == true) {
            this.toastr.success(res.message, "Reset Password");
            this.router.navigate(['/Login']);
          }
          else {
            this.toastr.warning(res.message, "Reset Password");
          }
        },
        (err: any) => {
          this.toastr.error(err.message, "Reset Password");
        })
  }

  savecontactus(body: any) {
    return this.http.post<any>(`${this.endpoint}/Home/Contactus`, body)
  }

  passwordConfirming(c: FormGroup) {
    let confirmpswrdcrtl = c.get('ConfirmPassword');
    if (confirmpswrdcrtl.errors == null || 'passwordMismatch' in confirmpswrdcrtl.errors) {
      if (c.get('Password').value !== confirmpswrdcrtl.value)
        confirmpswrdcrtl.setErrors({ passwordMismatch: true });
      else
        confirmpswrdcrtl.setErrors(null);
    }
  }
}

I tried every solution I found on the web but it didn't work for me most of solutions suggest to add @Injectable() but it is already add can anyone help?


Solution

  • I just found the problem in SocialLoginModule that was used in the project and was commented on in the imports