Skip to content

Commit 1179bc7

Browse files
committed
Validate PowerSync endpoint as soon as the credentials are constructed.
1 parent df9d5f7 commit 1179bc7

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

packages/powersync/lib/src/connector.dart

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,11 +87,13 @@ class PowerSyncCredentials {
8787
/// When the token expires. Only use for debugging purposes.
8888
final DateTime? expiresAt;
8989

90-
const PowerSyncCredentials(
90+
PowerSyncCredentials(
9191
{required this.endpoint,
9292
required this.token,
9393
this.userId,
94-
this.expiresAt});
94+
this.expiresAt}) {
95+
_validateEndpoint();
96+
}
9597

9698
factory PowerSyncCredentials.fromJson(Map<String, dynamic> parsed) {
9799
String token = parsed['token'];
@@ -133,6 +135,15 @@ class PowerSyncCredentials {
133135
Uri endpointUri(String path) {
134136
return Uri.parse(endpoint).resolve(path);
135137
}
138+
139+
_validateEndpoint() {
140+
final parsed = Uri.parse(endpoint);
141+
if ((!parsed.isScheme('http') && !parsed.isScheme('https')) ||
142+
parsed.host.isEmpty) {
143+
throw ArgumentError.value(
144+
endpoint, 'PowerSync endpoint must be a valid URL');
145+
}
146+
}
136147
}
137148

138149
/// Credentials used to connect to the PowerSync dev API.

0 commit comments

Comments
 (0)