Skip to content

AuthService

reference
2 min readUpdated

Kind: Class

Source: Frontend/src/app/services/security/auth.service.ts (line 131)

Part of: Frontend

AuthService manages authentication-related state and navigation checks in the frontend. It exposes methods for login, token access, route detection, branch switching, user information persistence, and activation decisions.

Methods

MethodSignatureReturns
isLoggedInisLoggedIn()boolean
getTokengetToken()string
isLoginPageisLoginPage()boolean
isSheetPageisSheetPage()boolean
routeToLoginPagerouteToLoginPage()void
canActivatecanActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot)boolean
switchBranchswitchBranch(branchId: number)string
loginlogin(usernameInput: string, passwordInput: string, rememberMe: boolean, cookiesCode: string, locationInfo: LocationInfo)void
saveUserLoggedInInformationsaveUserLoggedInInformation()void
verifyverify(verfyRequest: VerfyRequest)void
resendCodeToVerfyresendCodeToVerfy(TempToken: any)void
countOfActiveLoginDevicesByUsercountOfActiveLoginDevicesByUser()void
verifiedOTPloginverifiedOTPlogin(username: undefined, password: undefined, id: undefined, grantCode: undefined, grantIP: undefined, isTwoFactorVerified: undefined)void
trustedMachinetrustedMachine(grantCode: string)void
useJwtHelperuseJwtHelper(givenToken: any)void
checkCanActivatecheckCanActivate(url: string)boolean
getSubscriptionPackagesgetSubscriptionPackages()void
getSubscriptionFeatuesgetSubscriptionFeatues()void
HasPermissionHasPermission(data: string, ID: number, SecurityAccessTypeID: number)any
GetCompanyGetCompany(domain: string)void
HasPermission2HasPermission2(PersonUserID: number, SecurityAccessTypeID: number, PageID: number)any
userPermissionsForNewListuserPermissionsForNewList()void
getPermissionsForSheetgetPermissionsForSheet(moduleId: number, objId: number)any
setListOfNewPermissionsetListOfNewPermission(value: ListOfNewResponse)void
setExportLogssetExportLogs(moduleId: number)void
checkErrorResponsecheckErrorResponse(Response: undefined, module: string)string
getNotificationCountgetNotificationCount()Observable<any>
clearStoredDataclearStoredData()void
logOutlogOut(companyId: number, userId: number)void
getRefreshTokengetRefreshToken()string
storeTokensstoreTokens(accessToken: string, refreshToken: string)void
isTokenExpiredisTokenExpired()boolean
refreshAccessTokenrefreshAccessToken(refreshToken: string)Observable<any>
isLoggedInWithValidTokenisLoggedInWithValidToken()boolean
initializeTokenRefreshinitializeTokenRefresh()void
getTokenExpirationInfogetTokenExpirationInfo(){ expiresAt: Date, timeUntilExpiry: number, shouldRefresh: boolean }
startTokenRefreshTimerstartTokenRefreshTimer()void
stopTokenRefreshTimerstopTokenRefreshTimer()void
shouldRefreshTokenshouldRefreshToken()boolean
getTimeUntilExpirygetTimeUntilExpiry()number

Properties

PropertyType
localStorageRememberMestring
refreshMinutesTimeBeforeExpirationnumber
jwtHelperany
userPremissionsUserPremissions[]
loggedInUserPerson
_listOfNewPermissionListOfNewResponse
listOfNewPermissionany
SubscriptionPackagesnumber[]

Where it refuses work

  • AuthService stops the work with an early return when !token, in 6 places.
  • AuthService stops the work with an early return when !expirationDate, in 2 places.
  • AuthService stops the work with an early return when item === undefined || item === null.
  • AuthService stops the work with an early return when window.location.href.includes("ogin") || window.location.href.includes("ignin") || window….
  • AuthService stops the work with an early return when window.location.href.toLocaleLowerCase().includes("edit") || window.location.href.toLocal….
  • AuthService stops the work with an early return when url === 'home' || url === ''.

When something fails

  • AuthService handles failure in 5 places: it turns it into a return value in 4, and logs it and continues in 1.

Diagram

mermaid
graph LR
  App[Frontend Component or Route Guard] --> AuthService[AuthService]
  AuthService --> Login[login]
  AuthService --> Verify[verify]
  AuthService --> Token[getToken]
  AuthService --> Status[isLoggedIn]
  AuthService --> Routes[isLoginPage / isSheetPage]
  AuthService --> Guard[canActivate]
  AuthService --> Navigation[routeToLoginPage]
  AuthService --> Branch[switchBranch]
  AuthService --> UserInfo[saveUserLoggedInInformation]

Usage

ts
import { Component } from '@angular/core';
import { AuthService } from './services/security/auth.service';

@Component({
  selector: 'app-account',
  template: `
    <button *ngIf="!isLoggedIn" (click)="login()">Log in</button>
    <button *ngIf="isLoggedIn" (click)="switchBranch()">Switch branch</button>
  `,
})
export class AccountComponent {
  constructor(private readonly authService: AuthService) {}

  get isLoggedIn(): boolean {
    return this.authService.isLoggedIn();
  }

  login(): void {
    this.authService.login();
  }

  switchBranch(): void {
    const branch = this.authService.switchBranch();
    console.log('Selected branch:', branch);
  }
}

AI Coding Instructions

  • Keep authentication checks in AuthService rather than duplicating login or token logic in components.
  • Call canActivate() from route guard integration points and redirect with routeToLoginPage() when access is denied.
  • Check isLoginPage() and isSheetPage() before applying page-specific authentication behavior.
  • Read tokens through getToken() instead of accessing authentication state directly.
  • Keep saveUserLoggedInInformation() and verify() aligned with the login flow.

Used by

218 references from 218 files. Each is a place in this repository where the symbol is actually used — go read one rather than trusting an example.

Imported by (218)

  • AppRoutingModuleFrontend/src/app/app-routing.module.ts:1
  • AppComponentFrontend/src/app/app.component.ts:1
  • MrqDetailsComponentFrontend/src/app/components/MRQ/mrq-details/mrq-details.component.ts:1
  • MrqInquiryComponentFrontend/src/app/components/MRQ/mrq-details/mrq-inquiry/mrq-inquiry.component.ts:1
  • MrqListComponentFrontend/src/app/components/MRQ/mrq-list/mrq-list.component.ts:1
  • BillOfMaterialsDetailsComponentFrontend/src/app/components/bill-of-materials/bill-of-materials-details/bill-of-materials-details.component.ts:1
  • BillOfMaterialsListComponentFrontend/src/app/components/bill-of-materials/bill-of-materials-list/bill-of-materials-list.component.ts:1
  • BlogPopupComponentFrontend/src/app/components/blogs/blog-popup/blog-popup.component.ts:1

…and 210 more.

Was this page helpful?

Download as PDF