Fix excessive authentication prompts
Signed-off-by: William Brawner <me@wbrawner.com>
This commit is contained in:
parent
c1f333426b
commit
d82461834f
4 changed files with 14 additions and 3 deletions
|
@ -6,7 +6,7 @@ import { CookieService } from 'ngx-cookie-service';
|
||||||
import { SwUpdate } from '@angular/service-worker';
|
import { SwUpdate } from '@angular/service-worker';
|
||||||
import { first, filter, map } from 'rxjs/operators';
|
import { first, filter, map } from 'rxjs/operators';
|
||||||
import { interval, concat } from 'rxjs';
|
import { interval, concat } from 'rxjs';
|
||||||
import { Router, ActivationEnd } from '@angular/router';
|
import { Router, ActivationEnd, ActivatedRoute } from '@angular/router';
|
||||||
import { Actionable, isActionable } from './shared/actionable';
|
import { Actionable, isActionable } from './shared/actionable';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
|
@ -26,13 +26,20 @@ export class AppComponent {
|
||||||
@Inject(TWIGS_SERVICE) private twigsService: TwigsService,
|
@Inject(TWIGS_SERVICE) private twigsService: TwigsService,
|
||||||
private location: Location,
|
private location: Location,
|
||||||
private cookieService: CookieService,
|
private cookieService: CookieService,
|
||||||
|
private router: Router,
|
||||||
|
private activatedRoute: ActivatedRoute,
|
||||||
private appRef: ApplicationRef,
|
private appRef: ApplicationRef,
|
||||||
private updates: SwUpdate,
|
private updates: SwUpdate,
|
||||||
) {
|
) {
|
||||||
if (this.cookieService.check('Authorization')) {
|
if (this.cookieService.check('Authorization')) {
|
||||||
this.twigsService.getProfile().subscribe(user => {
|
this.twigsService.getProfile().subscribe(user => {
|
||||||
this.user = user;
|
this.user = user;
|
||||||
|
if (this.activatedRoute.pathFromRoot.length == 0) {
|
||||||
|
this.router.navigateByUrl("/budgets")
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
} else {
|
||||||
|
this.router.navigateByUrl("/login")
|
||||||
}
|
}
|
||||||
|
|
||||||
updates.available.subscribe(event => {
|
updates.available.subscribe(event => {
|
||||||
|
|
|
@ -22,6 +22,10 @@ export class BudgetsComponent implements OnInit {
|
||||||
ngOnInit() {
|
ngOnInit() {
|
||||||
this.app.backEnabled = this.isLoggedIn();
|
this.app.backEnabled = this.isLoggedIn();
|
||||||
this.app.title = 'Budgets';
|
this.app.title = 'Budgets';
|
||||||
|
if (!this.isLoggedIn()) {
|
||||||
|
this.loading = false;
|
||||||
|
return;
|
||||||
|
}
|
||||||
this.twigsService.getBudgets().subscribe(
|
this.twigsService.getBudgets().subscribe(
|
||||||
budgets => {
|
budgets => {
|
||||||
this.budgets = budgets;
|
this.budgets = budgets;
|
||||||
|
|
|
@ -16,7 +16,7 @@ export class AuthInterceptor implements HttpInterceptor {
|
||||||
}
|
}
|
||||||
let headers = req.headers;
|
let headers = req.headers;
|
||||||
headers = headers.append('Authorization', `Basic ${this.cookieService.get('Authorization')}`);
|
headers = headers.append('Authorization', `Basic ${this.cookieService.get('Authorization')}`);
|
||||||
this.cookieService.set('Authorization', this.cookieService.get('Authorization'), 14);
|
this.cookieService.set('Authorization', this.cookieService.get('Authorization'), 14, null, null, true);
|
||||||
return next.handle(req.clone({headers: headers}));
|
return next.handle(req.clone({headers: headers}));
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -34,7 +34,7 @@ export class TwigsHttpService implements TwigsService {
|
||||||
// };
|
// };
|
||||||
// return this.http.post<User>(this.apiUrl + '/users/login', params, this.options);
|
// return this.http.post<User>(this.apiUrl + '/users/login', params, this.options);
|
||||||
const credentials = btoa(`${email}:${password}`)
|
const credentials = btoa(`${email}:${password}`)
|
||||||
this.cookieService.set('Authorization', credentials, 14);
|
this.cookieService.set('Authorization', credentials, 14, null, null, true);
|
||||||
return this.getProfile();
|
return this.getProfile();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue