Skip to content

Commit

Permalink
style: format
Browse files Browse the repository at this point in the history
  • Loading branch information
github-actions[bot] committed Oct 23, 2024
1 parent 61f2fcf commit 70eb170
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 22 deletions.
6 changes: 5 additions & 1 deletion libs/eo/auth/data-access/auth.interceptor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,11 @@ export class EoAuthorizationInterceptor implements HttpInterceptor {
private transloco: TranslocoService = inject(TranslocoService);

private tokenRefreshCalls = ['PUT', 'POST', 'DELETE'];
private ignoreTokenRefreshUrls = ['/api/auth/token', '/api/authorization/consent/grant', '/api/authorization/terms/accept'];
private ignoreTokenRefreshUrls = [
'/api/auth/token',
'/api/authorization/consent/grant',
'/api/authorization/terms/accept',
];
private apiBaseUrls = [this.apiBase, this.apiBase.replace('/api', '/wallet-api')];

intercept(req: HttpRequest<unknown>, handler: HttpHandler) {
Expand Down
16 changes: 9 additions & 7 deletions libs/eo/auth/data-access/auth.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ export class EoAuthService {

async acceptTos(): Promise<void> {
const user = this.user();
if(!user) {
if (!user) {
this.login();
}

Expand All @@ -125,7 +125,9 @@ export class EoAuthService {

try {
// Accept TOS
await lastValueFrom(this.http.post(`${this.apiEnvironment.apiBase}/authorization/terms/accept`, {}));
await lastValueFrom(
this.http.post(`${this.apiEnvironment.apiBase}/authorization/terms/accept`, {})
);

// Poll for TOS acceptance confirmation
const maxAttempts = 10;
Expand All @@ -137,7 +139,7 @@ export class EoAuthService {
return;
}

await new Promise(resolve => setTimeout(resolve, delayMs));
await new Promise((resolve) => setTimeout(resolve, delayMs));
}

return Promise.reject('Max attempts reached waiting for TOS acceptance!');
Expand All @@ -151,7 +153,7 @@ export class EoAuthService {
return this.userManager
? this.userManager?.signinCallback().then((user) => {
if (user) {
this.user.set(user as EoUser ?? null);
this.user.set((user as EoUser) ?? null);
}
return Promise.resolve(user ?? null);
})
Expand All @@ -169,8 +171,8 @@ export class EoAuthService {

async refreshToken(): Promise<User | null> {
const user = await this.userManager?.signinSilent();
if(user) {
this.user.set(user as EoUser ?? null);
if (user) {
this.user.set((user as EoUser) ?? null);
return Promise.resolve(user);
} else {
this.user.set(null);
Expand All @@ -195,7 +197,7 @@ export class EoAuthService {
checkForExistingToken() {
return this.userManager?.getUser().then((user) => {
if (!user) return;
this.user.set(user as EoUser ?? null);
this.user.set((user as EoUser) ?? null);
});
}
}
31 changes: 17 additions & 14 deletions libs/eo/auth/feature-terms/terms.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -265,20 +265,23 @@ export class EoTermsComponent {
if (this.startedAcceptFlow() || !this.hasAcceptedTerms) return;
this.startedAcceptFlow.set(true);

this.authService.acceptTos().then(() => {
const redirectUrl = this.activatedRoute.snapshot.queryParamMap.get('redirectUrl');

if (redirectUrl) {
this.router.navigateByUrl(redirectUrl);
} else {
this.router.navigate([this.transloco.getActiveLang(), 'dashboard']);
}
}).catch(() => {
this.startedAcceptFlow.set(false);
this.toastService.open({
message: this.transloco.translate(this.translations.shared.error.message),
type: 'danger',
this.authService
.acceptTos()
.then(() => {
const redirectUrl = this.activatedRoute.snapshot.queryParamMap.get('redirectUrl');

if (redirectUrl) {
this.router.navigateByUrl(redirectUrl);
} else {
this.router.navigate([this.transloco.getActiveLang(), 'dashboard']);
}
})
.catch(() => {
this.startedAcceptFlow.set(false);
this.toastService.open({
message: this.transloco.translate(this.translations.shared.error.message),
type: 'danger',
});
});
});
}
}

0 comments on commit 70eb170

Please sign in to comment.