Skip to content

Commit 54e8a6a

Browse files
committed
Allow multiple audiences and localhost audiences for auto endpoint
computation.
1 parent 7668495 commit 54e8a6a

File tree

1 file changed

+16
-3
lines changed

1 file changed

+16
-3
lines changed

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)