Last active
July 26, 2020 00:54
-
-
Save changhuixu/9696a16ba0f00ec93ddc8da9e92b20c0 to your computer and use it in GitHub Desktop.
This file contains 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 implements OnDestroy { | |
private readonly apiUrl = `${environment.apiUrl}api/account`; | |
private timer: Subscription; | |
private _user = new BehaviorSubject<ApplicationUser>(null); | |
user$: Observable<ApplicationUser> = this._user.asObservable(); | |
private storageEventListener(event: StorageEvent) { // ... } | |
constructor(private router: Router, private http: HttpClient) { | |
window.addEventListener('storage', this.storageEventListener.bind(this)); | |
} | |
ngOnDestroy(): void { | |
window.removeEventListener('storage', this.storageEventListener.bind(this)); | |
} | |
login(username: string, password: string) { // ... } | |
logout() { // ... } | |
refreshToken() { // ... } | |
setLocalStorage(x: LoginResult) { // ... } | |
clearLocalStorage() { // ... } | |
private getTokenRemainingTime() { // ... } | |
private startTokenTimer() { // ... } | |
private stopTokenTimer() { | |
this.timer?.unsubscribe(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment