File

src/app/user/auth.service.ts

Index

Properties
Methods

Constructor

constructor()

Methods

isLoggedIn
isLoggedIn()
Returns : boolean
login
login(userName: string, password: string)
Parameters :
Name Type Optional
userName string No
password string No
Returns : void
logout
logout()
Returns : void

Properties

currentUser
currentUser: User | null
Type : User | null
redirectUrl
redirectUrl: string
Type : string
import { Injectable } from '@angular/core';
import { User } from './user';

@Injectable({
  providedIn: 'root'
})
export class AuthService {
currentUser: User | null;
// Retain the attempted URL for redirectUrl forredirection
redirectUrl: string;

  constructor() { }

  isLoggedIn(): boolean{
    return !!this.currentUser;
  }

  login(userName: string, password: string): void {
    // Code here would log into a back end service
    // and return user information
    // This is just hard-coded here.
    this.currentUser = {
        id: 2,
        userName: userName,
        isAdmin: false
    };
}

  logout(): void {
    this.currentUser = null;
 }
}

result-matching ""

    No results matching ""