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 { first, filter, map } from 'rxjs/operators';
|
||||
import { interval, concat } from 'rxjs';
|
||||
import { Router, ActivationEnd } from '@angular/router';
|
||||
import { Router, ActivationEnd, ActivatedRoute } from '@angular/router';
|
||||
import { Actionable, isActionable } from './shared/actionable';
|
||||
|
||||
@Component({
|
||||
|
@ -26,13 +26,20 @@ export class AppComponent {
|
|||
@Inject(TWIGS_SERVICE) private twigsService: TwigsService,
|
||||
private location: Location,
|
||||
private cookieService: CookieService,
|
||||
private router: Router,
|
||||
private activatedRoute: ActivatedRoute,
|
||||
private appRef: ApplicationRef,
|
||||
private updates: SwUpdate,
|
||||
) {
|
||||
if (this.cookieService.check('Authorization')) {
|
||||
this.twigsService.getProfile().subscribe(user => {
|
||||
this.user = user;
|
||||
if (this.activatedRoute.pathFromRoot.length == 0) {
|
||||
this.router.navigateByUrl("/budgets")
|
||||
}
|
||||
});
|
||||
} else {
|
||||
this.router.navigateByUrl("/login")
|
||||
}
|
||||
|
||||
updates.available.subscribe(event => {
|
||||
|
|
|
@ -22,6 +22,10 @@ export class BudgetsComponent implements OnInit {
|
|||
ngOnInit() {
|
||||
this.app.backEnabled = this.isLoggedIn();
|
||||
this.app.title = 'Budgets';
|
||||
if (!this.isLoggedIn()) {
|
||||
this.loading = false;
|
||||
return;
|
||||
}
|
||||
this.twigsService.getBudgets().subscribe(
|
||||
budgets => {
|
||||
this.budgets = budgets;
|
||||
|
|
|
@ -16,7 +16,7 @@ export class AuthInterceptor implements HttpInterceptor {
|
|||
}
|
||||
let headers = req.headers;
|
||||
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}));
|
||||
}
|
||||
}
|
|
@ -34,7 +34,7 @@ export class TwigsHttpService implements TwigsService {
|
|||
// };
|
||||
// return this.http.post<User>(this.apiUrl + '/users/login', params, this.options);
|
||||
const credentials = btoa(`${email}:${password}`)
|
||||
this.cookieService.set('Authorization', credentials, 14);
|
||||
this.cookieService.set('Authorization', credentials, 14, null, null, true);
|
||||
return this.getProfile();
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue