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
| Method | Signature | Returns |
|---|---|---|
isLoggedIn | isLoggedIn() | boolean |
getToken | getToken() | string |
isLoginPage | isLoginPage() | boolean |
isSheetPage | isSheetPage() | boolean |
routeToLoginPage | routeToLoginPage() | void |
canActivate | canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot) | boolean |
switchBranch | switchBranch(branchId: number) | string |
login | login(usernameInput: string, passwordInput: string, rememberMe: boolean, cookiesCode: string, locationInfo: LocationInfo) | void |
saveUserLoggedInInformation | saveUserLoggedInInformation() | void |
verify | verify(verfyRequest: VerfyRequest) | void |
resendCodeToVerfy | resendCodeToVerfy(TempToken: any) | void |
countOfActiveLoginDevicesByUser | countOfActiveLoginDevicesByUser() | void |
verifiedOTPlogin | verifiedOTPlogin(username: undefined, password: undefined, id: undefined, grantCode: undefined, grantIP: undefined, isTwoFactorVerified: undefined) | void |
trustedMachine | trustedMachine(grantCode: string) | void |
useJwtHelper | useJwtHelper(givenToken: any) | void |
checkCanActivate | checkCanActivate(url: string) | boolean |
getSubscriptionPackages | getSubscriptionPackages() | void |
getSubscriptionFeatues | getSubscriptionFeatues() | void |
HasPermission | HasPermission(data: string, ID: number, SecurityAccessTypeID: number) | any |
GetCompany | GetCompany(domain: string) | void |
HasPermission2 | HasPermission2(PersonUserID: number, SecurityAccessTypeID: number, PageID: number) | any |
userPermissionsForNewList | userPermissionsForNewList() | void |
getPermissionsForSheet | getPermissionsForSheet(moduleId: number, objId: number) | any |
setListOfNewPermission | setListOfNewPermission(value: ListOfNewResponse) | void |
setExportLogs | setExportLogs(moduleId: number) | void |
checkErrorResponse | checkErrorResponse(Response: undefined, module: string) | string |
getNotificationCount | getNotificationCount() | Observable<any> |
clearStoredData | clearStoredData() | void |
logOut | logOut(companyId: number, userId: number) | void |
getRefreshToken | getRefreshToken() | string |
storeTokens | storeTokens(accessToken: string, refreshToken: string) | void |
isTokenExpired | isTokenExpired() | boolean |
refreshAccessToken | refreshAccessToken(refreshToken: string) | Observable<any> |
isLoggedInWithValidToken | isLoggedInWithValidToken() | boolean |
initializeTokenRefresh | initializeTokenRefresh() | void |
getTokenExpirationInfo | getTokenExpirationInfo() | { expiresAt: Date, timeUntilExpiry: number, shouldRefresh: boolean } |
startTokenRefreshTimer | startTokenRefreshTimer() | void |
stopTokenRefreshTimer | stopTokenRefreshTimer() | void |
shouldRefreshToken | shouldRefreshToken() | boolean |
getTimeUntilExpiry | getTimeUntilExpiry() | number |
Properties
| Property | Type |
|---|---|
localStorageRememberMe | string |
refreshMinutesTimeBeforeExpiration | number |
jwtHelper | any |
userPremissions | UserPremissions[] |
loggedInUser | Person |
_listOfNewPermission | ListOfNewResponse |
listOfNewPermission | any |
SubscriptionPackages | number[] |
Where it refuses work
AuthServicestops the work with an early return when!token, in 6 places.AuthServicestops the work with an early return when!expirationDate, in 2 places.AuthServicestops the work with an early return whenitem === undefined || item === null.AuthServicestops the work with an early return whenwindow.location.href.includes("ogin") || window.location.href.includes("ignin") || window….AuthServicestops the work with an early return whenwindow.location.href.toLocaleLowerCase().includes("edit") || window.location.href.toLocal….AuthServicestops the work with an early return whenurl === 'home' || url === ''.
When something fails
AuthServicehandles failure in 5 places: it turns it into a return value in 4, and logs it and continues in 1.
Diagram
mermaidgraph 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
tsimport { 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
AuthServicerather than duplicating login or token logic in components. - Call
canActivate()from route guard integration points and redirect withrouteToLoginPage()when access is denied. - Check
isLoginPage()andisSheetPage()before applying page-specific authentication behavior. - Read tokens through
getToken()instead of accessing authentication state directly. - Keep
saveUserLoggedInInformation()andverify()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)
AppRoutingModule—Frontend/src/app/app-routing.module.ts:1AppComponent—Frontend/src/app/app.component.ts:1MrqDetailsComponent—Frontend/src/app/components/MRQ/mrq-details/mrq-details.component.ts:1MrqInquiryComponent—Frontend/src/app/components/MRQ/mrq-details/mrq-inquiry/mrq-inquiry.component.ts:1MrqListComponent—Frontend/src/app/components/MRQ/mrq-list/mrq-list.component.ts:1BillOfMaterialsDetailsComponent—Frontend/src/app/components/bill-of-materials/bill-of-materials-details/bill-of-materials-details.component.ts:1BillOfMaterialsListComponent—Frontend/src/app/components/bill-of-materials/bill-of-materials-list/bill-of-materials-list.component.ts:1BlogPopupComponent—Frontend/src/app/components/blogs/blog-popup/blog-popup.component.ts:1
…and 210 more.
Was this page helpful?