Skip to content

Instantly share code, notes, and snippets.

@coderkan
Created April 19, 2020 13:33
Show Gist options
  • Save coderkan/002a1f26304720e8db74a516c63dba83 to your computer and use it in GitHub Desktop.
Save coderkan/002a1f26304720e8db74a516c63dba83 to your computer and use it in GitHub Desktop.
@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