Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
constructor(
private http: HttpClient,
private configService: ConfigService,
private jwtHelperService: JwtHelperService
) {
super();
this.loggedIn = !!localStorage.getItem('auth_token');
// ?? not sure if this the best way to broadcast the status but seems to resolve issue on page refresh where auth status is lost in
// header component resulting in authed user nav links disappearing despite the fact user is still logged in
this._authNavStatusSource.next(this.loggedIn);
this.baseUrl = configService.getApiURI();
this.jwtHelperService = new JwtHelperService({
tokenGetter: () => localStorage.getItem('')
});
}
constructor(private http: HttpClient) {
this.baseUrl = environment.api.host;
this.jwtHelper = new JwtHelperService();
}
constructor(private api: ApiService) {
this.user = null;
this.subject = new BehaviorSubject(this.user);
this.jwtHelper = new JwtHelperService();
}
currentUser(){
let token=sessionStorage.getItem('token')
let jwthelper=new JwtHelperService();
return jwthelper.decodeToken(token)
}
intercept(request: HttpRequest, next: HttpHandler): Observable> {
let token = null;
const sessionUser = JSON.parse(localStorage.getItem('current_user'));
if (sessionUser) {
token = sessionUser.token;
const helper = new JwtHelperService();
const expirationDate = helper.getTokenExpirationDate(token);
const now = new Date();
if (expirationDate.getTime() - now.getTime() <= 1000 * 10 * 60) {
this.session.refreshToken(token).subscribe((data) => {
this.session.cacheToken(data);
});
}
}
if (token) {
request = request.clone({
setHeaders: {
Authorization: `JWT ${token}`
}
});
}
return next.handle(request).pipe(
constructor(
private router: Router
) {
this.jwtHelper = new JwtHelperService();
}
currentUser(){
let token=sessionStorage.getItem('token')
let jwthelper=new JwtHelperService();
return jwthelper.decodeToken(token)
}
* $$ / $$ |$$ / $$ |$$ | $$ |$$ / $$ |$$ | $$ | $$ / $$ |$$ | \__|
* $$ | $$ |$$ | $$ |$$ | $$ |$$ | $$ |$$ | $$ |$$\ $$ | $$ |$$ |
* \$$$$$$\ $$ |\$$$$$ |\$$$$$ |\$$$$$$ |$$ | \$$$ |\$$$$$ |$$ |
* \_______|\__| \______/ \______/ \_______|\__| \____/ \______/ \__|
*
* This file is part of Clouditor Community Edition.
*/
import { Injectable } from '@angular/core';
import { JwtHelperService } from '@auth0/angular-jwt';
import { Router, ActivatedRoute } from '@angular/router';
import { HttpParams } from '@angular/common/http';
export const TOKEN_NAME = 'token';
const helper = new JwtHelperService();
@Injectable()
export class AuthService {
constructor(private router: Router, private route: ActivatedRoute) {
const params = new HttpParams({ fromString: window.location.hash.replace('#?', '') });
const token = params.get('token');
if (token) {
this.login(token);
this.router.navigate(['/']);
}
}
isLoggedIn() {
constructor(
private localStorageService: LocalStorageService,
) {
this.jwtHelper = new JwtHelperService();
}