Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Editor]: Allow logging out #1039

Merged
merged 11 commits into from
Nov 25, 2024
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,14 @@
<gn-ui-button
type="default"
class="w-10 h-10 flex justify-center items-center hover:cursor-pointer"
(click)="logOut()"
>
<img src="assets/system-shut.svg" alt="Log out" class="w-4 h-4" />
<img
src="assets/system-shut.svg"
alt="Log out"
cmoinier marked this conversation as resolved.
Show resolved Hide resolved
[title]="'editor.sidebar.logout' | translate"
class="w-4 h-4 hover:invert-[.5]"
/>
</gn-ui-button>
</div>
</ng-container>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@ import { ChangeDetectionStrategy, Component, OnInit } from '@angular/core'
import { TranslateModule } from '@ngx-translate/core'
import { DashboardMenuComponent } from '../dashboard-menu/dashboard-menu.component'
import { PlatformServiceInterface } from '@geonetwork-ui/common/domain/platform.service.interface'
import { AvatarServiceInterface } from '@geonetwork-ui/api/repository'
import {
AuthService,
AvatarServiceInterface,
} from '@geonetwork-ui/api/repository'
import { LetDirective } from '@ngrx/component'
import { UiElementsModule } from '@geonetwork-ui/ui/elements'
import { OrganizationsServiceInterface } from '@geonetwork-ui/common/domain/organizations.service.interface'
Expand Down Expand Up @@ -31,7 +34,8 @@ export class SidebarComponent implements OnInit {
constructor(
public platformService: PlatformServiceInterface,
private avatarService: AvatarServiceInterface,
public organisationsService: OrganizationsServiceInterface
public organisationsService: OrganizationsServiceInterface,
private authService: AuthService
) {}

ngOnInit(): void {
Expand All @@ -41,4 +45,20 @@ export class SidebarComponent implements OnInit {
(orgs, me) => orgs.filter((org) => org.name === me?.organisation)
)
}

logOut() {
fetch(this.authService.logoutUrl, {
method: 'GET',
})
.then((response) => {
if (response.ok) {
window.location.href = 'http://localhost:4200'
cmoinier marked this conversation as resolved.
Show resolved Hide resolved
} else {
console.error('Logout failed')
}
})
.catch((error) => {
console.error('Error during logout request:', error)
})
}
}