Skip to content

Instantly share code, notes, and snippets.

@a-patel
Created November 16, 2018 19:07
Show Gist options
  • Select an option

  • Save a-patel/1fd47fab4213b040f712b2ba53f9d075 to your computer and use it in GitHub Desktop.

Select an option

Save a-patel/1fd47fab4213b040f712b2ba53f9d075 to your computer and use it in GitHub Desktop.
Token Service in Angular
import { Injectable } from "@angular/core";
@Injectable({ providedIn: "root" })
export class TokenService {
private token = "token";
clear(): void {
sessionStorage.removeItem(this.token);
}
any(): boolean {
return this.get() !== null;
}
get(): string {
return sessionStorage.getItem(this.token);
}
set(token: string): void {
sessionStorage.setItem(this.token, token);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment