src/app/user/auth.service.ts
Properties |
Methods |
constructor()
|
Defined in src/app/user/auth.service.ts:10
|
isLoggedIn |
isLoggedIn()
|
Defined in src/app/user/auth.service.ts:14
|
Returns :
boolean
|
login |
login(userName: string, password: string)
|
Defined in src/app/user/auth.service.ts:18
|
Returns :
void
|
logout |
logout()
|
Defined in src/app/user/auth.service.ts:29
|
Returns :
void
|
currentUser |
currentUser:
|
Type : User | null
|
Defined in src/app/user/auth.service.ts:8
|
redirectUrl |
redirectUrl:
|
Type : string
|
Defined in src/app/user/auth.service.ts:10
|
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;
}
}