Created
April 19, 2020 13:33
-
-
Save coderkan/002a1f26304720e8db74a516c63dba83 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Injectable({ | |
providedIn: 'root' | |
}) | |
export class AuthService { | |
isLogin = false; | |
roleAs: string; | |
constructor() { } | |
login(value: string) { | |
this.isLogin = true; | |
this.roleAs = value; | |
localStorage.setItem('STATE', 'true'); | |
localStorage.setItem('ROLE', this.roleAs); | |
return of({ success: this.isLogin, role: this.roleAs }); | |
} | |
logout() { | |
this.isLogin = false; | |
this.roleAs = ''; | |
localStorage.setItem('STATE', 'false'); | |
localStorage.setItem('ROLE', ''); | |
return of({ success: this.isLogin, role: '' }); | |
} | |
isLoggedIn() { | |
const loggedIn = localStorage.getItem('STATE'); | |
if (loggedIn == 'true') | |
this.isLogin = true; | |
else | |
this.isLogin = false; | |
return this.isLogin; | |
} | |
getRole() { | |
this.roleAs = localStorage.getItem('ROLE'); | |
return this.roleAs; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment