File tree Expand file tree Collapse file tree 1 file changed +17
-0
lines changed
tools/diagnostics-app/src/library/powersync Expand file tree Collapse file tree 1 file changed +17
-0
lines changed Original file line number Diff line number Diff line change @@ -22,6 +22,7 @@ export class TokenConnector implements PowerSyncBackendConnector {
2222 }
2323
2424 async signIn ( credentials : Credentials ) {
25+ validateSecureContext ( credentials . endpoint ) ;
2526 try {
2627 localStorage . setItem ( 'powersync_credentials' , JSON . stringify ( credentials ) ) ;
2728 await connect ( ) ;
@@ -39,3 +40,19 @@ export class TokenConnector implements PowerSyncBackendConnector {
3940 localStorage . removeItem ( 'powersync_credentials' ) ;
4041 }
4142}
43+
44+ function validateSecureContext ( url : string ) {
45+ if ( ! location . href . startsWith ( 'https:' ) ) {
46+ return ;
47+ }
48+ const parsedUrl = new URL ( url ) ;
49+ const secure =
50+ parsedUrl . protocol === 'https:' ||
51+ parsedUrl . hostname === 'localhost' ||
52+ parsedUrl . hostname === '127.0.0.1' ||
53+ parsedUrl . hostname === '::1' ;
54+ if ( ! secure ) {
55+ throw new Error ( `Cannot connect to http endpoints from the hosted diagnostics app.
56+ Run either the PowerSync endpoint on http://localhost, or the diagnostics app on http://localhost.` ) ;
57+ }
58+ }
You can’t perform that action at this time.
0 commit comments