Skip to content

Commit d8647a4

Browse files
authored
Merge pull request #264 from powersync-ja/diagnostics-app-multiple-audiences
[diagnostics-app] support multiple audiences
2 parents 7668495 + d3379c5 commit d8647a4

File tree

2 files changed

+21
-3
lines changed

2 files changed

+21
-3
lines changed

.changeset/red-suits-explode.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@powersync/diagnostics-app': patch
3+
---
4+
5+
Improve extracting endpoint from token audience.

tools/diagnostics-app/src/components/widgets/LoginDetailsWidget.tsx

+16-3
Original file line numberDiff line numberDiff line change
@@ -155,10 +155,23 @@ function getTokenEndpoint(token: string) {
155155
try {
156156
const [head, body, signature] = token.split('.');
157157
const payload = JSON.parse(atob(body));
158-
const aud = payload.aud as string | undefined;
159-
if (aud?.endsWith('.journeyapps.com')) {
160-
return aud;
158+
const aud = payload.aud as string | string[] | undefined;
159+
const audiences = Array.isArray(aud) ? aud : [aud];
160+
161+
// Prioritize public powersync URL
162+
for (let aud of audiences) {
163+
if (aud?.match(/^https?:.*.journeyapps.com/)) {
164+
return aud;
165+
}
166+
}
167+
168+
// Fallback to any URL
169+
for (let aud of audiences) {
170+
if (aud?.match(/^https?:/)) {
171+
return aud;
172+
}
161173
}
174+
162175
return null;
163176
} catch (e) {
164177
return null;

0 commit comments

Comments
 (0)