fix: bypassing cors

This commit is contained in:
Polianin Nikita 2024-12-18 08:41:29 +03:00
parent 16e25905dc
commit 9017e87175
3 changed files with 26 additions and 17 deletions

View File

@ -1,4 +1,4 @@
import {Component, Inject, Input, OnInit} from '@angular/core'; import {Component, EventEmitter, Inject, Input, Output} from '@angular/core';
import AuthApiService, {OAuthProviderData} from "@api/v1/authApiService"; import AuthApiService, {OAuthProviderData} from "@api/v1/authApiService";
import {OAuthProvider} from "@model/oAuthProvider"; import {OAuthProvider} from "@model/oAuthProvider";
import {ToastrService} from "ngx-toastr"; import {ToastrService} from "ngx-toastr";
@ -62,7 +62,7 @@ export class DeleteConfirmDialog {
styleUrl: './OAuthProviders.css', styleUrl: './OAuthProviders.css',
providers: [AuthApiService] providers: [AuthApiService]
}) })
export class OAuthProviders implements OnInit { export class OAuthProviders {
protected providers: AvailableOAuthProviders[] = []; protected providers: AvailableOAuthProviders[] = [];
protected _activeProvidersId: OAuthProvider[] = []; protected _activeProvidersId: OAuthProvider[] = [];
protected _activeProviders: string[] = []; protected _activeProviders: string[] = [];
@ -81,6 +81,8 @@ export class OAuthProviders implements OnInit {
@Input() canUnlink: boolean = false; @Input() canUnlink: boolean = false;
@Output() public oAuthUpdateProviders = new EventEmitter();
constructor(authApi: AuthApiService, private notify: ToastrService, private dialog: MatDialog) { constructor(authApi: AuthApiService, private notify: ToastrService, private dialog: MatDialog) {
authApi.availableProviders().subscribe(providers => this.updateDisabledProviders(providers)); authApi.availableProviders().subscribe(providers => this.updateDisabledProviders(providers));
} }
@ -95,18 +97,6 @@ export class OAuthProviders implements OnInit {
}); });
} }
ngOnInit(): void {
window.addEventListener('message', (event) => {
if (event.data && event.data.success === false) {
console.error(event.data.message);
this.notify.error(event.data.message, 'OAuth ошибка');
} else {
this.activeProvidersId.push(event.data.provider);
this.updateDisabledProviders();
}
});
}
protected openOAuth(provider: AvailableOAuthProviders) { protected openOAuth(provider: AvailableOAuthProviders) {
console.log(provider.redirect); console.log(provider.redirect);
const oauthWindow = window.open( const oauthWindow = window.open(
@ -120,6 +110,14 @@ export class OAuthProviders implements OnInit {
} }
provider.active = true; provider.active = true;
const checkInterval = setInterval(() => {
if (oauthWindow.closed) {
clearInterval(checkInterval);
this.oAuthUpdateProviders.emit();
provider.active = false;
}
}, 1500);
} }
protected confirmDelete(provider: AvailableOAuthProviders) { protected confirmDelete(provider: AvailableOAuthProviders) {

View File

@ -116,7 +116,7 @@
} }
</mat-form-field> </mat-form-field>
<OAuthProviders [canUnlink]="true" [activeProvidersId]="activatedProviders" <OAuthProviders [canUnlink]="true" [activeProvidersId]="activatedProviders" (oAuthUpdateProviders)="updateProviders()"
[message]="'Или можете получить часть данных от сторонних сервисов'"/> [message]="'Или можете получить часть данных от сторонних сервисов'"/>
</div> </div>
</form> </form>

View File

@ -70,9 +70,16 @@ export class CreateAdminComponent {
this.createAdminForm.get('password')?.updateValueAndValidity(); this.createAdminForm.get('password')?.updateValueAndValidity();
}); });
this.updateAdminData();
}
private updateAdminData() {
this.api.adminConfiguration().subscribe(configuration => { this.api.adminConfiguration().subscribe(configuration => {
if (configuration) { if (configuration) {
if (this.createAdminForm.get('email')?.value == 0)
this.createAdminForm.get('email')?.setValue(configuration.email); this.createAdminForm.get('email')?.setValue(configuration.email);
if (this.createAdminForm.get('user')?.value == 0)
this.createAdminForm.get('user')?.setValue(configuration.username); this.createAdminForm.get('user')?.setValue(configuration.username);
this.activatedProviders = configuration.usedOAuthProviders; this.activatedProviders = configuration.usedOAuthProviders;
@ -111,4 +118,8 @@ export class CreateAdminComponent {
this.hideRetypePass = !this.hideRetypePass; this.hideRetypePass = !this.hideRetypePass;
event.stopPropagation(); event.stopPropagation();
} }
protected updateProviders() {
this.updateAdminData();
}
} }