Skip to content

AuthService

reference
1 min readUpdated

Kind: Class

Source: Pams/Web/Pams.WebApp/Client/app/services/security/auth.service.ts (line 35)

Part of: Pams

AuthService manages client-side authentication state, JWT helper setup, branch switching, company lookup, and permission checks in the Pams web application. Route-related code can call canActivate() and verifyLogin() to determine whether a user session is valid.

Implements: CanActivate

Methods

MethodSignatureReturns
canActivatecanActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot)boolean
switchBranchswitchBranch(branchId: number)string
loginlogin(usernameInput: string, passwordInput: string)void
useJwtHelperuseJwtHelper()void
verifyLoginverifyLogin(url: string)boolean
HasPermissionHasPermission(data: string, ID: number, SecurityAccessTypeID: number)any
GetCompanyGetCompany(domain: string)void
HasPermission2HasPermission2(PersonUserID: number, SecurityAccessTypeID: number, PageID: number)any
logOutlogOut()void

Properties

PropertyType
userPremissionsUserPremissions[]
jwtHelperJwtHelper

Where it refuses work

  • AuthService stops the work with an early return when item == undefined || item == null.
  • AuthService stops the work with an early return when branchId == 0.
  • AuthService stops the work with an early return when url == "" && this.LoggedIn.

Diagram

mermaid
graph LR
    UI[Application UI] --> AuthService[AuthService]
    AuthService --> Login[login]
    AuthService --> Jwt[useJwtHelper]
    AuthService --> Verify[verifyLogin]
    AuthService --> Guard[canActivate]
    AuthService --> Branch[switchBranch]
    AuthService --> Company[GetCompany]
    AuthService --> Permissions[HasPermission / HasPermission2]
    AuthService --> Logout[logOut]
    Guard --> Routes[Protected Routes]

Usage

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

@Component({
  selector: "app-account-menu",
  template: `
    <button *ngIf="isLoggedIn()" (click)="changeBranch()">
      Switch branch
    </button>

    <button (click)="signOut()">Log out</button>
  `
})
export class AccountMenuComponent {
  constructor(private readonly authService: AuthService) {}

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

  canAccessProtectedRoute(): boolean {
    return this.authService.canActivate();
  }

  changeBranch(): string {
    return this.authService.switchBranch();
  }

  signOut(): void {
    this.authService.logOut();
  }
}

AI Coding Instructions

  • Keep authentication and authorization checks routed through AuthService rather than duplicating session logic in components.
  • Preserve the existing method names and casing, including HasPermission, HasPermission2, and GetCompany.
  • Call verifyLogin() or canActivate() before rendering or navigating to authenticated areas.
  • Keep JWT-related changes aligned with useJwtHelper(), login(), and logOut() so session state is cleared consistently.

Used by

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

Imported by (2)

  • MaritalStatusServicePams/Web/Pams.WebApp/Client/app/services/common/marital-status.service.ts:1
  • SharedServicesModulePams/Web/Pams.WebApp/Client/app/services/shared-service.module.ts:1

Was this page helpful?

Download as PDF