Skip to content

Commit c1cda9b

Browse files
authored
fix: metadata decoding and encoding zitadel#9816 (zitadel#10024)
# Which Problems Are Solved Metadata encoding and decoding on the organization detail page was broken due to use of the old, generated gRPC client. # How the Problems Are Solved The metadata values are now correctly base64 decoded and encoded on the organization detail page. # Additional Changes Refactored parts of the code to remove the dependency on the buffer npm package, replacing it with the browser-native TextEncoder and TextDecoder APIs. # Additional Context - Closes [zitadel#9816](zitadel#9816)
1 parent 4df1382 commit c1cda9b

File tree

4 files changed

+13
-14
lines changed

4 files changed

+13
-14
lines changed

console/src/app/modules/metadata/metadata-dialog/metadata-dialog.component.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import { Timestamp } from 'google-protobuf/google/protobuf/timestamp_pb';
44
import { ToastService } from 'src/app/services/toast.service';
55
import { Metadata as MetadataV2 } from '@zitadel/proto/zitadel/metadata_pb';
66
import { Metadata } from 'src/app/proto/generated/zitadel/metadata_pb';
7-
import { Buffer } from 'buffer';
87

98
export type MetadataDialogData = {
109
metadata: (Metadata.AsObject | MetadataV2)[];
@@ -26,9 +25,10 @@ export class MetadataDialogComponent {
2625
public dialogRef: MatDialogRef<MetadataDialogComponent>,
2726
@Inject(MAT_DIALOG_DATA) public data: MetadataDialogData,
2827
) {
28+
const decoder = new TextDecoder();
2929
this.metadata = data.metadata.map(({ key, value }) => ({
3030
key,
31-
value: typeof value === 'string' ? value : Buffer.from(value as unknown as string, 'base64').toString('utf8'),
31+
value: typeof value === 'string' ? value : decoder.decode(value),
3232
}));
3333
}
3434

console/src/app/modules/metadata/metadata/metadata.component.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import { Observable, ReplaySubject } from 'rxjs';
55
import { Metadata as MetadataV2 } from '@zitadel/proto/zitadel/metadata_pb';
66
import { map, startWith } from 'rxjs/operators';
77
import { Metadata } from 'src/app/proto/generated/zitadel/metadata_pb';
8-
import { Buffer } from 'buffer';
98

109
type StringMetadata = {
1110
key: string;
@@ -37,12 +36,13 @@ export class MetadataComponent implements OnInit {
3736

3837
ngOnInit() {
3938
this.dataSource$ = this.metadata$.pipe(
40-
map((metadata) =>
41-
metadata.map(({ key, value }) => ({
39+
map((metadata) => {
40+
const decoder = new TextDecoder();
41+
return metadata.map(({ key, value }) => ({
4242
key,
43-
value: Buffer.from(value as any as string, 'base64').toString('utf-8'),
44-
})),
45-
),
43+
value: typeof value === 'string' ? value : decoder.decode(value),
44+
}));
45+
}),
4646
startWith([] as StringMetadata[]),
4747
map((metadata) => new MatTableDataSource(metadata)),
4848
);

console/src/app/pages/orgs/org-detail/org-detail.component.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import { Component, OnDestroy, OnInit } from '@angular/core';
22
import { MatDialog } from '@angular/material/dialog';
33
import { Router } from '@angular/router';
4-
import { Buffer } from 'buffer';
54
import { BehaviorSubject, from, Observable, of, Subject, takeUntil } from 'rxjs';
65
import { catchError, finalize, map } from 'rxjs/operators';
76
import { CreationType, MemberCreateDialogComponent } from 'src/app/modules/add-member-dialog/member-create-dialog.component';
@@ -266,10 +265,11 @@ export class OrgDetailComponent implements OnInit, OnDestroy {
266265
.listOrgMetadata()
267266
.then((resp) => {
268267
this.loadingMetadata = false;
269-
this.metadata = resp.resultList.map((md) => {
268+
const decoder = new TextDecoder();
269+
this.metadata = resp.resultList.map(({ key, value }) => {
270270
return {
271-
key: md.key,
272-
value: Buffer.from(md.value as string, 'base64').toString('utf-8'),
271+
key,
272+
value: atob(typeof value === 'string' ? value : decoder.decode(value)),
273273
};
274274
});
275275
})

console/src/app/pages/users/user-detail/user-detail/user-detail.component.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import { Validators } from '@angular/forms';
44
import { MatDialog } from '@angular/material/dialog';
55
import { ActivatedRoute, Params, Router } from '@angular/router';
66
import { TranslateService } from '@ngx-translate/core';
7-
import { Buffer } from 'buffer';
87
import { catchError, filter, map, startWith, take } from 'rxjs/operators';
98
import { ChangeType } from 'src/app/modules/changes/changes.component';
109
import { phoneValidator, requiredValidator } from 'src/app/modules/form-field/validators/validators';
@@ -582,7 +581,7 @@ export class UserDetailComponent implements OnInit {
582581
const setFcn = (key: string, value: string) =>
583582
this.newMgmtService.setUserMetadata({
584583
key,
585-
value: Buffer.from(value),
584+
value: new TextEncoder().encode(value),
586585
id: user.userId,
587586
});
588587
const removeFcn = (key: string): Promise<any> => this.newMgmtService.removeUserMetadata({ key, id: user.userId });

0 commit comments

Comments
 (0)